📄 mylib.c
字号:
#include "mylib.h"
uchar code IC1_TB[10]= {0x0EB,0x60,0x0C7,0x0E5,0x6C,0x0AD,0x0AF,0x0E0,0x0EF,0x0ED}; //0-9 display code
uchar code IC2_TB[10]= {0x7D,0x60,0x3E,0x7A,0x63,0x5B,0x5F,0x70,0x7F,0x7B}; //0-9 display code
extern uchar Curtime[7];
extern uchar disnum[9];
bit SetTimeFlag; //used for set time
extern uchar idata FaultTime[6];
extern uint UaStartEeprom;
extern uint UbStartEeprom;
extern uint UcStartEeprom ;
extern uint IaStartEeprom;
extern uint IcStartEeprom;
extern uint IpStartEeprom;
extern bit send_flag;//发送标志
extern bit times_flag;//故障显示次数增加标志
extern bit swith_phase;//故障形式转换标志
extern bit error_flag;//校验故障标志,为1则表明手持机接到的数据不正确
extern uchar n;
uchar modified=0;
//新增变量
extern uchar IdNum;
extern bit ResetNum;
extern uchar m1;//地址加k1值提取下一个故障时间
extern uchar m2;//
extern uint Fault_adress;
extern uchar CountTimer;
//*********************1302******************/
/*******************************************/
/* clock 1302 */
/* write 1Byte data to DS1302;ucDa is the */
/* data to be writen */
/*******************************************/
//时钟-------------------------------------------------------------------------
void RTInputByte(uchar ucDa) //往DS1302写入1Byte数据;ucDa 写入的数据
{
uchar i;
ACC = ucDa;
for(i=8;i>0;i--)
{
T_IO = ACC_0;
T_CLK = 1;
T_CLK = 0;
ACC = ACC >> 1;
}
}
uchar RTOutputByte(void) //从DS1302读取1Byte数据
{
uchar i;
for(i=8;i>0;i--)
{
ACC = ACC >>1; //相当于汇编中的 RRC
ACC_7 = T_IO;
T_CLK = 1;
T_CLK = 0;
}
return(ACC);
}
void W1302(uchar ucAddr, uchar ucDa)/*往DS1302写入数据;ucAddr: DS1302地址, ucDa: 要写的数据*/
{
T_RST = 0;
T_CLK = 0;
T_RST = 1;
RTInputByte(ucAddr); /* 地址,命令 */
RTInputByte(ucDa); /* 写1Byte数据*/
//T_CLK = 1;
T_RST =0;
KickDog();
}
uchar R1302(uchar ucAddr)//读取DS1302某地址的数据
{
uchar ucDa;
T_RST = 0;
T_CLK = 0;
T_RST = 1;
RTInputByte(ucAddr); // 地址,命令
ucDa = RTOutputByte(); // 读1Byte数据
//T_CLK = 1;
T_RST =0;
return(ucDa);
KickDog();
}
//*********************LCD************************/
/*************************************************/
/* */
/* The function write a bit to LCD */
/* Designed by xr.li */
/* Date 2007-3-21 */
/* */
/*************************************************/
void LCD_WriteBit(bit C_D)
{
DIPIN = C_D;
delay(1); //waiting for change
CLKPIN = 1;
delay(1);
CLKPIN = 0;
delay(1);
CLKPIN = 1;
}
/*********************************************************/
/* */
/* The function write control word to LCD ,for IC1 region*/
/* Designed by xr.li */
/* Date 2007-3-21 */
/* */
/*********************************************************/
void LCD_WC1(uchar Ctrl_Byte)
{
bit C_C; //name?
uchar i,Ctrl_ByteA;
Ctrl_ByteA = Ctrl_Byte;
CS1PIN = 1;
CS1PIN = 0;
C_C = 1;
LCD_WriteBit(C_C);
C_C = 0;
LCD_WriteBit(C_C);
LCD_WriteBit(C_C);
for(i=8; i>0;i--)
{
if(Ctrl_ByteA & 0x80)
C_C = 1;
else
C_C = 0;
LCD_WriteBit(C_C);
Ctrl_ByteA <<= 1;
}
C_C = 0;
LCD_WriteBit(C_C);
DIPIN = 1;
CS1PIN = 1;
KickDog();
}
/*************************************************/
/* */
/* The function reset LCD,for IC1 and IC2 region */
/* Designed by xr.li */
/* Date 2007-3-21 */
/* */
/*************************************************/
void LCD_Reset(uchar region)
{
switch(region)
{
case 0x01: //for IC1 region
LCD_WC1(CMDOFF);
LCD_WC1(CMDLCDOFF);
LCD_WC1(CMDON);
LCD_WC1(CMDLCDON);
LCD_WC1(CMDB3C4);
break;
case 0x02: //for IC2 region
LCD_WC2(CMDOFF);
LCD_WC2(CMDLCDOFF);
LCD_WC2(CMDON);
LCD_WC2(CMDLCDON);
LCD_WC2(CMDB3C4);
break;
default:
break;
}
}
/*************************************************/
/* */
/* The function write data to LCD */
/* Designed by xr.li */
/* Date 2007-3-21 */
/* */
/*************************************************/
void LCD_WD1(uchar data_byteB,uchar data_byteA)
{
bit C_A;
uchar i;
CS1PIN = 1;
CS1PIN = 0;
C_A = 1;
LCD_WriteBit(C_A);
C_A = 0;
LCD_WriteBit(C_A);
C_A = 1;
LCD_WriteBit(C_A);
data_byteB = (data_byteB << 2) & 0x0FC;
for(i = 6; i > 0; i--)
{
if(data_byteB & 0x80) C_A = 1;
else C_A = 0;
LCD_WriteBit(C_A);
data_byteB = data_byteB <<1;
}
for(i = 8; i > 0; i--)
{
if(data_byteA & 0x01) C_A = 1;
else C_A = 0;
LCD_WriteBit(C_A);
data_byteA = data_byteA >>1;
}
DIPIN = 1;
CS1PIN = 0;
CS1PIN = 1; // enable write
KickDog();
}
/*************************************************/
/* */
/* The function write control to LCD,for IC2 region */
/* Designed by xr.li */
/* Date 2007-3-22 */
/* */
/*************************************************/
void LCD_WC2(uchar Ctrl_Byte)
{
bit C_C; //name?
uchar i,Ctrl_ByteA;
Ctrl_ByteA = Ctrl_Byte;
CS2PIN = 1;
CS2PIN = 0;
C_C = 1;
LCD_WriteBit(C_C);
C_C = 0;
LCD_WriteBit(C_C);
LCD_WriteBit(C_C);
for(i=8; i>0;i--)
{
if(Ctrl_ByteA & 0x80) C_C = 1;
else C_C = 0;
LCD_WriteBit(C_C);
Ctrl_ByteA <<= 1;
}
C_C = 0;
LCD_WriteBit(C_C);
DIPIN = 1;
CS2PIN = 1;
KickDog();
}
/*************************************************/
/* */
/* The function write data to LCD */
/*where,data_byteB is the LCD RAM address, */
/* data_byteA is data to send */
/* Designed by xr.li */
/* Date 2007-3-22 */
/*************************************************/
void LCD_WD2(uchar data_byteB,uchar data_byteA)
{
bit C_A;
uchar i;
CS2PIN = 1;
CS2PIN = 0;
C_A = 1; //101:write data to ram
LCD_WriteBit(C_A);
C_A = 0;
LCD_WriteBit(C_A);
C_A = 1;
LCD_WriteBit(C_A);
data_byteB = (data_byteB << 2) & 0x0FC;
for(i = 6; i > 0; i--)
{
if(data_byteB & 0x80)C_A = 1;
else C_A = 0;
LCD_WriteBit(C_A);
data_byteB = data_byteB <<1;
}
for(i = 8; i > 0; i--)
{
if(data_byteA & 0x01)C_A = 1;
else C_A = 0;
LCD_WriteBit(C_A);
data_byteA = data_byteA >>1;
}
DIPIN = 1;
CS2PIN = 0;
CS2PIN = 1; // enable write
KickDog();
}
/**************************************************/
/* */
/* The function send display number to IC1 region,*/
/* where Sx is the trouble type to display */
/* f_time is the trouble time to display */
/* hour and minute <=255(FFH) */
/* designed by xl.zhang */
/* Date 2007-3-28 */
/**************************************************/
void DispIC1(uchar Sx,struct fault_time f_time) //
{
uchar B_D;
int j;
B_D = 0x0;
j = f_time.hour / 1000;
if(Sx == 0) //trouble in S1
LCD_WD1(B_D,*(IC1_TB+j)|0x10);
else
LCD_WD1(B_D,*(IC1_TB+j));
B_D += 2;
j = (f_time.hour % 1000)/100;
if(Sx == 1) //trouble in S2
LCD_WD1(B_D,*(IC1_TB+j)|0x10);
else
LCD_WD1(B_D,*(IC1_TB+j));
B_D += 2;
j = (f_time.hour % 100)/10;
if(Sx == 2) //trouble in S3
LCD_WD1(B_D,*(IC1_TB+j)|0x10);
else
LCD_WD1(B_D,*(IC1_TB+j));
B_D += 2;
j = f_time.hour % 10;
if(Sx == 3) //trouble in S4
LCD_WD1(B_D,*(IC1_TB+j)|0x10);
else
LCD_WD1(B_D,*(IC1_TB+j));
B_D += 2;
j = f_time.min / 10;
if(Sx == 4) //trouble in S5
LCD_WD1(B_D,*(IC1_TB+j)|0x10);
else
LCD_WD1(B_D,*(IC1_TB+j));
B_D += 2;
j = f_time.min % 10;
if(Sx == 5) //trouble in S6
LCD_WD1(B_D,*(IC1_TB+j)|0x10);
else
LCD_WD1(B_D,*(IC1_TB+j));
KickDog();
}
/*************************************************/
/* */
/* The function select the phrase A,B,C for the */
/* system,where Sx is the phrase to select */
/* Designed by xr.li */
/* Date 2007-3-22 */
/*************************************************/
void Phase_select(uchar Phase)
{
switch(Phase)
{
case Phase_A:
LCD_WD2(26,0x09);
break;
case Phase_B:
LCD_WD2(26,0x0A);
break;
case Phase_C:
LCD_WD2(26,0x0C);
break;
default:
break;
}
}
/*************************************************/
/* */
/* The function initial the unchangable item in */
/* IC2 region */
/* Designed by xr.li ,modified by xl.zhang */
/* Date 2007-3-22 */
/*************************************************/
void Init_IC2(void)
{
LCD_WD2(0,0xFD); //display s15 and d8 = 0
LCD_WD2(2,0x80); //display s14
LCD_WD2(4,0x80); //display s13
LCD_WD2(6,0x80); //display s12
LCD_WD2(22,0x80); //display s17
LCD_WD2(24,0x80); //display s16
LCD_WD2(26,0x0F); //display s8,s9,s10 and s11
}
/*************************************************/
/* */
/* The function initial the unchangable item in */
/* IC1 region */
/* Designed by xl.zhang */
/* Date 2007-3-28 */
/*************************************************/
void Init_IC1(void)
{
LCD_WD1(0,0xEB); //display d1 = 0
LCD_WD1(2,0xEB); //display d2 = 0
LCD_WD1(4,0xEB); //display d3 = 0
LCD_WD1(6,0xEB); //display d4 = 0
LCD_WD1(8,0xEB); //display d5 = 0
LCD_WD1(10,0xEB); //display d6 = 0
LCD_WD1(12,0x01); //display s7
}
/*************************************************/
/* */
/* The function display the total number of */
/* trouble in D8 */
/* Designed by xl.zhang */
/* Date 2007-3-26 */
/*************************************************/
void TotalNumOfTrb(uchar Total_Num)
{
LCD_WD2(0,*(IC2_TB+Total_Num)|0x80); //同时显示S15
}
/*************************************************/
/* */
/* The function lighting the different bits */
/* in D8 */
/* Designed by Dr. Kat */
/* Date 2007-4-15 */
/* */
/*************************************************/
void LightingBits(uchar *time, uchar mask)
{
uchar i, j, val, k=2, msk;
msk = 0x40;
i = 20;
while(i>6)
{
j = *(time+k)/10;
if(mask&msk) val = *(IC2_TB+j)|0x80;
else val = *(IC2_TB+j);
LCD_WD2(i, val);
j = *(time+k)%10;
msk>>=1;
i -= 2;
if(mask&msk) val = *(IC2_TB+j)|0x80;
else val = *(IC2_TB+j);
LCD_WD2(i, val);
k++;
i -= 2;
msk>>=1;
}
KickDog();
}
/*************************************************/
/* */
/* The function display each fault number */
/* in D8 */
/* Designed by xl.zhang */
/* Date 2007-4-12 */
/* */
/*************************************************/
/*void Disp_fault_num(uchar num,uchar *time)
{
// uint j;
switch(num)
{
case 0:
LightingBits(time, 0x7B); //0111 1011
break;
case 1:
LightingBits(time, 0x0A); //0000 1010
break;
case 2:
LightingBits(time, 0x37); //0011 0111
break;
case 3:
LightingBits(time, 0x1F); //0001 1111
break;
case 4:
LightingBits(time, 0x4E); //0100 1110
break;
case 5:
LightingBits(time, 0x5D); //0101 1101
break;
case 6:
LightingBits(time, 0x7D); //0111 1101
break;
case 7:
LightingBits(time, 0x0F); //0000 1111
break;
case 8:
LightingBits(time, 0x7F); //0111 1111
break;
case 9:
LightingBits(time, 0x5F); //0101 1111
break;
default:
break;
}
}*/
/************************************************/
/* The function display year ,month ,date ,hour,*/
/* minute,second ,Sx represents start(S12) */
/* current(S13) ,stop(S14) */
/* Designed by xl.zhang */
/* Date 2007-3-28 */
/************************************************/
void DispIC2_time(uchar Sx,uchar *time)
{
uint j;
//display year
j = *time/10;
LCD_WD2(24,*(IC2_TB+j)|0x80); //display S16
j = *time%10;
LCD_WD2(22,*(IC2_TB+j)|0x80); //display S17
if(!ResetNum)
{
switch(IdNum)
{
case 0:
LightingBits(time, 0x7B); //0111 1011
break;
case 1:
LightingBits(time, 0x0A); //0000 1010
break;
case 2:
LightingBits(time, 0x37); //0011 0111
break;
case 3:
LightingBits(time, 0x1F); //0001 1111
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -