Protues 7.8+ Keil 4.0以上版本可用。
自己搭建的电路,亲测代码可用。主要功能是实现了三机网络中两两单片机之间的通信功能,并通过数码管实时显示。
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include <reg52.h>
- #include <intrins.h>
- #define read 0
- #define wite 1
- unsigned char cort = 3;
- sbit BusAccess = P3 ^ 5;
- key_serial() interrupt 0 using 1
- {
- cort++;
- cort = cort%3;
- }
- void main()
- {
- P2 = 0xC0;
- TMOD = 0x20; //20H = 0010 0000
- TH1 = 0xFD;
- TL1 = 0xFD;
- PCON = 0x00;
- TR1 = 1;
- SCON = 0xF8; //F8 = 1111 1000,SM0SM1=11B=3,SM2=1,REN=1,TB8=1,RB8=0
- EA = 1;
- EX0 = 1;
- IT0 = 1;
- while(1)
- {
- if (cort == 1)
- {
- BusAccess = wite; //写总线
- SBUF = 0x01;
- while(TI != 1) {;}
- TI = 0;
- BusAccess = read; //读总线
- while(RI != 1) {;}
- RI = 0;
- P2 = SBUF;
- BusAccess = wite; //写总线
- }
- if(cort == 2)
- {
- BusAccess = wite; //写总线
- SBUF = 0x02;
- while(TI != 1) {;}
- TI = 0;
- BusAccess = read;
- while(RI != 1) {;}
- RI = 0;
- P2 = SBUF;
- BusAccess = wite;
- }
- if(cort == 0)
- {
- BusAccess = wite; //写总线
- SBUF = 0x00;
- while(TI != 1) {;}
- TI = 0;
- P2 = 0xC0;
- BusAccess = wite; //写总线
- cort = 3;
- }
-
- }
- }
复制代码
所有资料51hei提供下载:
所有源文件.rar
(32.27 KB, 下载次数: 44)
|