基于单片机双机通信设计仿真设计(资料1)
1495下载地址 https://docs.qq.com/doc/DWEpnR2pOWU91b3p4?pub=1&dver=2.1.0
1、单片机1发送0~9的一个数字至单片机2,通过按键(可用一个按键,上电默认为0,按键加1)选择数字;
2、单片机2收到单片机1发的数字,用一位数码管或4个发光二极管显示,同时回送应答信号(自定义);
3、单片机1收到应答信号后亮灯(1个发光二极管)1秒表示收到单片机2的应答,通信成功。
//#include<reg51.h> # include <STCC5A60S2.h> # define uchar unsigned char # define vtime 6000 //定时3ms,一帧8*3=24ms,频率=40Hz # define sub1 0x11 # define sub2 0x12 sbit key1=P3^2; sbit key2=P3^3; sbit led=P0^0; uchar over_t=0; uchar addr=sub1,sum=0; //uchar i,j,temp,m=0x01; uchar code distable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0x40,0x09}; //位选码表 uchar code numi[]={0xfe,0xfd,0xfb,0xf7}; //显示缓存 uchar V_ram[]={17,16,16,0}; uchar wi=0; //位选循环变量 uchar rn=0; //接收循环变量 uchar rxdv[3]; void main( ) { led=1;//led初始化 SCON = 0xd0; PCON = 0X80; TH1 = 0XFd; TL1 = 0XFd; IT0 = 1; // 中断0为边沿触发