两个单片机之间连接,控制灯模块。
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- void main()
- {
- uchar temp=0;
- TMOD=0x20;
- TH1=0xfd;
- TL1=0Xfd;
- SCON=0x50;
- PCON=0x00;
- TR1=1;
- while(1)
- {
- while(RI==0);
- RI=0;
- temp=SBUF;
- if(temp==0xfe)
- P0=0xfe;
- else if(temp==0xfd)
- P0=0xfd;
- else if(temp==0xfb)
- P0=0xfc;
- else
- P0=0xff;
- }
- }
复制代码- /*************** writer:shopping.w ******************/
- #include <reg52.h>
- #define uint unsigned int
- #define uchar unsigned char
- void main()
- {
- uchar temp=0;
- TMOD=0x20;
- TH1=0xfd;
- TL1=0xfd;
- SCON=0x40;
- PCON=0x00;
- TR1=1;
- P1=0xff;
- while(1)
- {
- temp=P1;
- SBUF=temp;
- while(TI==0);
- TI=0;
- }
- }
复制代码
所有资料51hei提供下载:
甲机通过串口控制乙机LED闪烁.zip
(72.08 KB, 下载次数: 17)
|