|
/***************************************************************
通信协议:
通信控制码:起始码(10101010,0xAA),结束码(01010101,0x55)
病房编码 :特护病房(10111011,0xBB)
一般病房1(11001100,0xCC)
一般病房2(00110011,0x33)
服务项目编码:病人要输液(01100110,0x66)
病人要上卫生间(10011001,0x99)
***************************************************************/
#include<reg52.h>
#include"5110.c"
sbit KEY=P3^3;
sbit LED=P3^6;
unsigned char temp[20][2];//数据缓冲区
unsigned char count=0x00; //标志当前记录条数
unsigned char flag=0x00,DATA[4],i=0x00,flag1=0xff,flag2=0x00;
unsigned char code tempp[]="**************";
void delay_Ms(unsigned int x)
{
unsigned char i;
while(x--)
{
for(i=0;i<245;i++);
}
}
unsigned char add_temp(unsigned char x,unsigned char y)
{
unsigned char a,b,i;
if(count>=20)
{
return 0x00;
}
if(x==0xBB)
{
for(i=0;i<count+1;i++)
{
if(temp[i][0]==0xBB)
{
continue;
}
else
{
a=temp[i][0];
b=temp[i][1];
temp[i][0]=x;
temp[i][1]=y;
x=a;
y=b;
}
}
}
else
{
temp[count][0]=x;
temp[count][1]=y;
}
count++;
flag1=0xff;
return 0xff;
}
unsigned char del_temp()
{
unsigned char i;
if(count==0)
{
return 0xff;
}
else
{
for(i=0;i<count;i++)
{
temp[i][0]=temp[i+1][0];
temp[i][1]=temp[i+1][1];
}
count--;
}
return 0x00;
}
void init_uart()
{
SCON=0x50;
PCON=0x00;
TMOD=0x20;
TH1=0xF3;
TL1=0xF3;
TR1=1;
ES=1;
EA=1;
}
void serical_service() interrupt 4
{
unsigned char com;
if(RI==1)
{
EA=0;
com=SBUF;
RI=0;
if(com==0xAA)
{
i=0;
}
DATA[i++]=com;
if(i==0x04)
{
if(DATA[3]==0x55)
{
flag=1;
}
i=0;
}
EA=1;
}
}
void main()
{
unsigned int num=0x00;
init_LCD();
LCD_clear();
init_uart();
LCD_clear();
display_English_String(0,0,tempp);
display_English_String(0,5,tempp);
display_chinese_word1(10,2,16,4,0,0);
delay_Ms(2000);
while(1)
{
num++;
if(KEY==0)
{
delay_Ms(10);
if(KEY==0)
{
while(KEY==0);//等待按键释放
if(count>0)
{
del_temp();
}
flag1=0xff;
}
}
if(flag==1)
{
add_temp(DATA[1],DATA[2]);
flag=0;
}
if(flag1==0xff)
{
if(count==0)
{
LCD_clear();
flag2=0x00;
LED=1;
display_English_String(0,0,tempp);
display_English_String(0,5,tempp);
display_chinese_word(12,2,12,5,0,0);
}
else
{
LCD_clear();
flag2=0xff;
display_English_String(0,0,tempp);
display_English_String(0,5,tempp);
if(temp[0][0]==0xBB)
{
display_chinese_word(6,1,12,6,5,0);
}
if(temp[0][0]==0xCC)
{
display_chinese_word(0,1,12,7,14,0);
}
if(temp[0][0]==0x33)
{
display_chinese_word(0,1,12,7,24,0);
}
if(temp[0][1]==0x66)
{
display_chinese_word(24,3,12,3,11,0);
}
if(temp[0][1]==0x99)
{
display_chinese_word(12,3,12,5,40,0);
}
}
flag1=0x00;
}
if(flag2==0xff&&num<30000)
{
LED=1;
}
if(flag2==0xff&&num>=30000&&num<60000)
{
LED=0;
}
if(num>=60000)
{
num=0;
}
}
}
小弟是新手,看不太懂,哪位大哥知道的话和我说说好么,最好逐条 解释 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|