資源描述:
《51單片機(jī)的串口通信程序》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、·51單片機(jī)的串口通信程序(C語(yǔ)言)·發(fā)布時(shí)間:2009-6-2??閱讀次數(shù):2551??字體大小:【小】【中】【大】作者:佚名??來(lái)源:不詳#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--)?{??/*對(duì)于11.0592M時(shí)鐘,約延時(shí)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