做的是两单片机串行通信控制八小灯循环点亮。编译成功,但就是没反应。
发送程序/**********************************/
/**********************************/
- #include<reg52.h>
- unsigned char code Tab[] = {0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};
- /*****************************************************
- ***************************************************/
- void Send(unsigned char dat)
- {
- SBUF=dat;
- while(TI==0)
- ;
- TI=0;
- }
- /**************************************************************
- **************************************************************/
- void delay(void)
- {
- unsigned char m,n;
- for(m=0;m<200;m++)
- for(n=0;n<250;n++)
- ;
- }
- void main_(void)
- {
- unsigned char i;
- TMOD=0x20;
- SCON=0x40;
- PCON=0x00;
- TH1=0xfd;
- TL1=0xfd;
- TR1=1;
- while(1)
- {
- for(i=0;i<8;i++)
- {
- Send(Tab[i][i]);
- delay();
- }
- }
- }
- 接收程序#include<reg52.h>
- unsigned char Receive(void)
- {
- unsigned char dat;
- while(RI==0)
- ;
- RI=0;
- dat=SBUF;
- return dat;
- }
- void main(void)
- {
- TMOD=0x20; //TMOD=0010 0000B,???T1?????2
- SCON=0x40; //SCON=0100 0000B,??????1
- PCON=0x00; //PCON=0000 0000B,???9600
- TH1=0xfd; //????????T1???
- TL1=0xfd; //????????T1???
- TR1=1; //?????T1
- REN=1;
- while(1)
- {
- P1=Receive();
- }
- }
复制代码
|