单片机实验三 双机通信实验程序_实验三双机通信实验
单片机实验三 双机通信实验程序由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“实验三双机通信实验”。
实验三 双机通信实验
一、实验目的UART 串行通信接口技术应用
二、实验实现的功能
用两片核心板之间实现串行通信,将按键信息互发到对方数码管显示。
三、系统硬件设计
实验所需硬件:电脑一台;
开发板一块;
串口通信线一根; USB线一根;
四、系统软件设计
实验所需软件:编译软件:keil uvision3;
程序下载软件:STC_ISP_V480; 试验程序:
#include sbit W1=P0^0;sbit W2=P0^1;sbit W3=P0^2;sbit W4=P0^3;sbit D9=P3^2;sbit D10=P3^3;sbit D11=P3^4;sbit D12=P3^5;sbit DP=P1^7;code unsigned char table[]={0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71};sfr P1M1=0x91;sfr P1M0=0x92;sbit H1=P3^6;sbit H2=P3^7;sbit L1=P0^5;sbit L2=P0^6;sbit L3=P0^7;unsigned char dat;unsigned char keynum;unsigned char keyscan();void display();void delay(void);
L1=1;L2=1;L3=1;
H1=0;if(L1==0)
return 1;else if(L2==0)
return 2;else if(L3==0)
return 3;
H1=1;H2=0;if(L1==0)
return 4;else if(L2==0)
return 5;else if(L3==0)
return 6;H2=1;return 0;
} unsigned char keyscan(){ static unsigned int ct=0;static unsigned char lastkey=0;unsigned char key;key=getkey();
if(key==lastkey){
ct++;
if(ct==900)
{
ct=0;
lastkey=0;
return key;
} } else {