📄 ledrgb.txt
字号:
}
void Wrt_IDT7134_Buf1(void) //declaretion sentence
{
//rewrite the flag of the IDT7134 when 77e58 write the dual-port RAM IDT7134
wrt_DRAM_begin=0xaa; //when the 77e58 write the d-ram the at89c51 cannot read the d-ram
wrt_DRAM_finish=0x55; //read disable
//begin to write the dispbuf on the IDT7134 LINGFENG 2005-5 UPDATED
// put_time_dispbuf(time,num_model);
// put_temp_dispbuf(time,num_model);
put_char_dispbuf(COMBUF.charbuf, 8);
NOP;
NOP;
wrt_DRAM_begin=0x55; //when the 77e58 finished write the d-ram the at89c51 can read the d-ram
wrt_DRAM_finish=0xaa; //read enable
//only 77e58 can change the value of the two flag byte
}
void Wrt_IDT7134_Buf2(void)
{
//rewrite the flag of the IDT7134 when 77e58 write the dual-port RAM IDT7134
wrt_DRAM_begin=0xaa; //when the 77e58 write the d-ram the at89c51 cannot read the d-ram
wrt_DRAM_finish=0x55; //read disable
//begin to write the dispbuf on the IDT7134 LINGFENG 2005-5 UPDATED
put_time_dispbuf(time,num_model);
put_temp_dispbuf(time,num_model);
NOP;
NOP;
wrt_DRAM_begin=0x55; //when the 77e58 finished write the d-ram the at89c51 can read the d-ram
wrt_DRAM_finish=0xaa; //read enable
//only 77e58 can change the value of the two flag byte
}
void watchdog(void)
{
if(fd_dog==3)
{
FDDOG=1;
FDDOG=0;
fd_dog=0;
}
}
void serial0_process(void) interrupt 5 using 1
{
if (RI){ //receive the data
RI = 0; //clear the flag of receive interrupt of serial
RECBUF.databuf[RECBUF.len++] = SBUF;
if (RECBUF.len == UDATALEN
||RECBUF.len == DATALEN)
{
RECBUF.flag = True;
}
}
else //send the data
{
TI = 0; //clear the flag of send interrupt of serial
SEDBUF.loc++;
if (--SEDBUF.len>0)
{
SBUF = SEDBUF.databuf[SEDBUF.loc++];
}
else
{
SEDBUF.flag = True; //all data is sended
}
}
}
void commu(void)
{
while(RECBUF.flag)
{
if (com_judge_ud())
{
if (com_crc_verify())
{
command(RECBUF.databuf[1]);
watchdog();
}
else
{
while(~com_packet_ud(RES_ERR_D));
}
}
}
}
void command(uchar cmd)
{
switch (cmd)
{
uchar i;
case ORD_BCOM : //begin the communcation
ET0 = 0 ; //turn off the interrupt of PCF8563
COMBUF.flag_time = (uchar)0;
COMBUF.flag_char = (uchar)0;
com_packet_ud(RES_OK_W);
break;
case ORD_ECOM : //finish the communcation
if (COMBUF.flag_time == (uchar)1)
{
set_time(COMBUF.time);
}
if (COMBUF.flag_char == (uchar)1)
{
store_c_code(COMBUF.charbuf,CHARLEN);
}
com_packet_ud(RES_OK_W);
break;
case ORD_SETT: //setting time and data
for(i=0; i<TIMELEN; i++)
{
COMBUF.time[i] = RECBUF.databuf[i+2];
}
com_packet_ud(RES_OK_W);
break;
case ORD_DISC : //display char
for (i=0; i<CHARLEN; i++)
{
COMBUF.charbuf[i] = RECBUF.databuf[i+2];
}
put_char_dispbuf(COMBUF.charbuf, CHARLEN);
com_packet_ud(RES_OK_W);
break;
case ORD_GETC:
get_time(COMBUF.time);
com_packet_d(RES_OK_W, COMBUF.charbuf,8);
break;
default :
com_packet_ud(RES_ERR_D);
break;
}
}
bit com_judge_ud(void) //judge the frame is the 4-length frame or 36-length frame
{
if (RECBUF.len == LENGTH_ND)
{
delay60(); //delay 120us
delay60();
if (RECBUF.len == LENGTH_ND)
{
return(True); //is no data frame
}
else
{
RECBUF.flag = (uchar)0;
return(False);
}
}
return(True); //is data frame
}
bit com_crc_verify (void)
{
uint crc;
crc = com_cal_crc(RECBUF.databuf, RECBUF.len-2);
if (crc == Makeword(RECBUF.databuf[3], RECBUF.databuf[4]))
{
return(True);
}
else
{
return(False);
}
}
bit com_packet_ud(uchar cmd)
{
uint crc;
if (SEDBUF.flag )
{
SEDBUF.databuf[0] = FRM_BE;
SEDBUF.databuf[1] = cmd;
crc = com_cal_crc(SEDBUF.databuf, 2);
SEDBUF.databuf[2] = Hbyte(crc);
SEDBUF.databuf[3] = Lbyte(crc);
SEDBUF.len = 4;
SBUF = FRM_BE;
return(True);
}
return(False);
}
// len is length of data wanted to send
bit com_packet_d(uchar cmd, uchar *ptr, uchar len)
{
uchar i;
uint crc;
if (SEDBUF.flag)
{
SEDBUF.databuf[0] = FRM_BE;
SEDBUF.databuf[1] = cmd;
for (i=0; i<len; i++)
{
SEDBUF.databuf[i+2] = *(ptr+i);
}
crc = com_cal_crc(SEDBUF.databuf, len+2);
SEDBUF.databuf[len+2] = Hbyte(crc);
SEDBUF.databuf[len+3] = Lbyte(crc);
SEDBUF.len = 36;
SEDBUF.loc = 0;
SEDBUF.flag = False;
SBUF= FRM_BE;
return(True);
}
return(False);
}
uint com_cal_crc(uchar *ptr, uchar len)
{
uint crc;
uchar da;
static uint crc_ta[16]={
0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,
0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,
};
crc=0;
while(len--!=0)
{
da=((uchar)(crc/256))/16;
crc<<=4;
crc^=crc_ta[da^(*ptr/16)];
da=((uchar)(crc/256))/16;
crc<<=4;
crc^=crc_ta[da^(*ptr&0x0f)];
ptr++;
}
return(crc);
}
void timer0_process(void ) interrupt 1 using 1 // time for 500ms
{
ET0=0;
TL0=0x00;
TH0=0x4c;
fd_dog++;
if(flag_begin)
{
if(++count_sec == 10) //Is one second?
{
count_sec = 0;
if(++count_min == 30) //Is 30second?
{
count_min = 0;
flag_30sec = True;
}
}
}
ET0=1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -