资源描述:
《51单片机的串口通信程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、·51单片机的串口通信程序(C语言)·发布时间:2009-6-2 阅读次数:2551 字体大小:【小】【中】【大】作者:佚名 来源:不详#include #include#include#include#defineucharunsignedchar#defineuintunsignedintsbitKey1=P2^3;sbitKey2=P2^2;sbitKey3=P2^1;sbitKey4=P2^0;sbitBELL=P3^6;sbitCONNE
2、CT=P3^7;unsignedint Key1_flag=0;unsignedint Key2_flag=0;unsignedint Key3_flag=0;unsignedint Key4_flag=0;unsignedcharb;unsignedcharcodeNum[21]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80, 0x90,0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,
3、 0x10,0x89};unsignedcharcodeDisdigit[4]={0x7F,0xBF,0xDF,0xEF};unsignedcharDisbuf[4];voiddelayms(uintt){ uinti; while(t--) { /*对于11.0592M时钟,约延时1ms*/ for(i=0;i<125;i++) {} }} //-----------------------------------------------------voidSendDa
4、ta(ucharDat){uchari=0;SBUF=Dat;while(1) { if(TI) { TI=0; break; } }}voidScanKey(){ if(Key1==0) { delayms(100); if(Key1==0) { Key1_flag=1; Key2_flag=0; Key3_flag=0; Key4_flag=0; Key1=1; } else; } if(Key2==0)
5、 { delayms(100); if(Key2==0) { Key2_flag=1; Key1_flag=0; Key3_flag=0; Key4_flag=0; Key2=1; } else; } if(Key3==0) { delayms(50); if(Key3==0) { Key3_flag=1; Key1_flag=0; Key2_flag=0; Key4_flag=0; Key3=1; } else
6、; } if(Key4==0) { delayms(50); if(Key4==0) { Key4_flag=1; Key1_flag=0; Key2_flag=0; Key3_flag=0; Key4=1; } else; } else; }voidKeyProc(){ if(Key1_flag) { TR1=1; SendData(0x55); Key1_flag=0; } elseif(Key2_flag) { T
7、R1=1; SendData(0x11); Key2_flag=0; } elseif(Key3_flag) { P1=0xff; BELL=0; CONNECT=1; Key3_flag=0; } elseif(Key4_flag) { CONNECT=0; BELL=1; Key4_flag=0; } else; }voidInitdisplay(void){Disbuf[0]=1;Disbuf[1]=2;Disbuf[2]=3;Disbuf[3]=4;}vo
8、idDisplay() //显示{unsignedint i=0;unsignedinttemp,count; temp=Disdigit[count]; P2=temp; temp=Disbuf[count]; temp=Num[temp