|
- #include "reg52.h"
- #define uchar unsigned char
- #define uint unsigned int
- uchar code askconfig[]= {0xcc,0x99,0x01,0x02,0x03,0xdd};
- uchar code Ackconfig[]= {0xaa,0x66,0x99,0x16,0x91,0x12,0xd8,0x56,0xbb};
- uchar chuli[29];
- void System_Init()
- {
- TMOD = 0x20;
- SCON = 0x50;
- TH1 = 0xfc;
- TL1 = 0xfc;
- PCON = 0x00;
- TR1 = 1;
- }
- void Delay (uint Milliseconds)//延時(shí)
- {
- uchar a,b;
- for(a=3;a>0;a--)
- {
- for(b=245;b>0;b--)
- for (; Milliseconds > 0; Milliseconds--);
- }
- }
- void SendChar (uchar chr)//發(fā)送一個(gè)字符
- {
- SBUF = chr;
- while(!TI);
- TI=0;
- }
- char Handshake (void)
- {
- uchar i,j,k;
- Delay(50000);
- Delay(50000);
- for(i=0;i<6;i++)
- {
- SendChar(askconfig[ i]);[ i]
- }
- while(RI)
- {
- chuli[j]=SBUF;
- RI=0;
- j++;
-
- if(j==9)
- {
- for(k=0;k<10;k++)
- {
- if(chuli[k]!=Ackconfig[k])
- break;
- }
- if(k!=10)
- return 0;
- else
- return -1;
- }
- }
- }
- void main()
- {
-
- System_Init();
- Delay(200);
- while(1)
- {
- if(Handshake ())
- {
- Delay(2000);
- Delay(2000);
- SendChar(0xff);
- }
- }
- }
復(fù)制代碼
|
評(píng)分
-
查看全部評(píng)分
|