




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、基于proteus的at89c52双机通目仿真在一个proteus工程屮,添加两个at89c52单片机,一个做主机,另一作从机。 现在要实现主机与从机之间的简单通信。具体功能是:主机不停扫描矩阵键盘, 如果有键被按下,则把相应按键的数字发送给从机,从机通过数码管显示它接 受到的数据。主机与从机之间的通信通过串行口实现。构建proteus仿真图时,如果感觉图纸不够大,放置元器件比较拥挤, 可以通过system选项>set sheet side.选择a3图纸就合适/。proteus中的rs-232c标准接头compim不耑要连接max232,可以直接 和单片机的rxd, txd连接,因为co
2、mpim已经把max232集成在内部。这里的串行通讯选择方式1,因为方式1的波特率与定时器t1的溢出率 有关,所以可以通过设置定时器t1的初值来确定串行通信的波特率。这里选 择了波特率为9600, t1选择具有自动重装功能的方式2,那么th1和tl1 的初值通过计算得到oxfd。具体的电路连接如下:士.4-rc1fx1b士.ss?ss_2inhb麝肩j><>«,»r«&&lr»r»r*r»9hs戀amj s 剩rsrmttutp2i0s3s主机电路:从机电路:c430pfu2c3叫 x219>x
3、tal130p18crystalxtal29'rst<tir>1c6vt;t“uv1si 2231 psenaleeap00/ad0 po 1/ao1 p0 2/ad2 p0 3zad3 p0 4/ad4 p0 6/ad5 p0 6/ad6 p0 7/ad7p2 0/a8 p2.1/a9 p2 2/a10 p2 3/a11 p2 4/a12 p2 5za13 p2 6/a14 p2 7/a15ci3?111 p p p! 1 19ppp0/121/t2ex23456 7p3 1/txd p3 2ntd" p3 3ntt p3.4zt0 p3s/t1 p3 6/涵
4、p3 7/rdatoc52)2dcddsrrxdrtstxdctsdtrrlerrorompim12l281 i-5jliq2"11,7-2113«iiiin上all要顺利实现双机通信重要的是要保持两机的波特率一致。所以,下面的一些参 数设置很重要。利用虚拟串口软件virtual serial port driver,建立一对相连的虚拟串口。如果 没有安装这个软件可以网上下载安装。这是实现仿真必须的。这里的虚拟串口 为com1和com4,下图可以看到两个端口是相连的。port pairs options fjelpserial ports explorervirtual s
5、erial port driver白塾 physical portso com33 儀 virtual ports® rs c0m1 9600-n-8-1 d) com4 9600-n-8-1other virtual portsmanage ports port access list custom pinoutvspdby qbma can create virtual senal ports wth any names you like, so you are not wed to comx rmes only however, please, make sure that p
6、rograms wortang wth these ports support custom port names.first port: second port:com2com5 add parfirst port: second port:c0m1com4delete parenable stnet baudrate emulation break bne/rcstorc connectional vituai send pars wil be removed from your system. ptease. make sure al ports are dosed.delete alf
7、or help press fi设賈主机 rs-232 接头 pl 的参数。physical port 选择端口 c0m11, physical baud rate选择9600, virtual baud rate也选择9600。其他参数默认,设置如下:component reference: component value:vsm model:physical port:physical baud rate: physical data bb: physical parky:virtual baud rate:virtual data biu:virtual parity: advanced
8、 properties:icompimicompim.dll|c0m119800|8i none19600i nonehidden:hidden:hide aohide ahhide aohide aovhide abhkjeaohide ahhide allqkhelpcanceli physical stop bits | i hide allother properdes:exclude hom sirnulalion exclude from pcb edit 11 properties as textattach hierarchy modulehide jorwnon pin$设置
9、从机 rs-232 接头 p2 的参数。physical port 选择端口 com4, physical baud rate选择9600, virtual baud rate也选择9600。其他参数默认,设置如下:晶振频率设置力11.0592mhz,它与上面设置波特率为9600是对应的。两个晶 振没置相同,如下图。component reference: |x1hidden:hidden:qkcomponent value:|crystalcancelfrequency:|l 1.0592mhz| hide all二j|xtal18z! 03 i hide allvpcb package:o
10、ther properhes:exclude from simulation exclude from pcb l卻outedi( all properties a$ textawach hierarchy module hide common pin$单片机的时钟频率也要设賈为11.0592mhz。两单片机参数设賈一致,如下图:edit componentcomponent reference:|u1hidden:component value:|at89c52hidden:pcb package:|dil40jdllllhideam _jprogram file:pwomcucom.hex
11、|3lhideaiclock frequency:|11.0592mhz|hideafl!advanced properties:enable trace logging| |no i | hide allother properties:fikhelpqatahidden pinscancelexclude from simulation exclude from pcb layout edit 11 properties as textauach hierarchy modulehide corrtfoon pins参数设置完成之后,proteus的任务就完成了。接着就是编写从机与主机之间
12、 的控制程序。程序编写完成后,分别把主机程序调入u1,从机程序调入u2。 主机与从机程序如下:主机程序#include<reg52.h>#define uchar unsigned char #define uint unsigned intvoid delay(uint x)/延时uint ij; for(i=0;i<x;i+)for(j=0;j<125;j+);void sent_data(uchar date) /发送数据 sbuf=date;while(iti);ti=0;void matrixkeyscan()/键盘扫描uchar temp,key;pl=ox
13、fe;temp=pl;temp=temp&oxfo;if(temp!=oxfo)delay(lo);temp=pl;temp=temp&oxfo;if(temp!=oxfo)temp=pl;switch(temp)case oxee: key=o;break;case oxde:key=l;break;case oxbe: key=2; break;case 0x7e: key=3; break;while(temp!=oxfo)temp=pl;temp=temp&oxfo;sent_data(key);pl=oxfd;temp=pl;temp=temp&oxf
14、o;if(temp!=oxfo)delay(lo);temp=pl;if(temp!=oxfo)temp=pl;switch(temp)case oxed:key=4;break;case oxdd: key=5; break;case oxbd:key=6;break;case 0x7d:key=7;break;while(temp!=oxfo)temp=pl;temp=temp&oxfo;sent_data(key);pl=oxfb;temp=pl;temp=temp&oxfo;if(temp!=oxfo)delay(lo);temp=pl;temp=temp&ox
15、fo;if(temp!=oxfo)temp=pl;switch(temp)case oxeb:key=8;break;case oxdb: key=9; break;case oxbb:key=10;break;case 0x7b:key=ll;break;while(temp!=oxfo)temp=pl;temp=temp&oxfo;sent_data(key);pl=0xf7;temp=pl;temp=temp&oxfo;if(temp!=oxfo)delay(lo);temp=pl;temp=temp&oxfo;if(temp!=oxfo)temp=pl;swit
16、ch(temp)case 0xe7:key=12;break;case 0xd7:key=13;break;case 0xb7: key=14; break;case 0x77:key=15;break;while(temp!=oxfo)temp=pl;temp=temp&oxfo;sent_data(key);void main()/主函数tmod=0x20;thl=oxfd;tll=oxfd;sm0=0;sm1=1;tr1=1;ea=1;es=1; while matrixkeyscan();从机程序#include<reg52.h>#define uchar unsigned char #define uint unsigned intuchar code disp=ox3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71;void delayfuint x)uint ij; for(i=0;i<x;i+)for(j=0;j<1
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 污水装置安装合同协议书
- 父母商铺过户协议书模板
- 物业与业主协议合同范本
- 消防维保终止合同协议书
- 股权回收合同协议书范本
- 闲置玻璃钢改造合同范本
- 申请廉租房劳务合同范本
- 浙江商会合作合同协议书
- 物流运输调车协议书范本
- 游乐场地板采购合同协议
- 建筑施工脚手架安全技术统一标准
- 鞍钢劳研考试题库及答案
- 2025年金融衍生品市场创新与风险防范策略在金融风险管理领域的应用与挑战报告
- 招考辅警 面试题及答案
- 工伤误工赔偿协议书
- 美术高考协议班合同
- 渔具回收寄售合同协议
- 《咖啡机操作培训资料》课件
- 小学数学教学策略与方法讲座
- 《幼儿户外自我保护能力提升研究的相关概念界定与国内外文献综述》3600字
- GB/T 2878.1-2025液压传动连接普通螺纹斜油口和螺柱端第1部分:斜油口
评论
0/150
提交评论