您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 电子设计/PCB > proteus单片机pcbarm实验报告
目录实验一、单片机间的多机通信...............................................................................................0实验二、I2C总线应用技术.....................................................................................................8实验三、层次原理图设计.....................................................................................................16实验四、元件封装的创建.....................................................................................................18实验五、自动布局.................................................................................................................20实验六、开关控制LED..........................................................................................................24实验七、中断计数器.............................................................................................................27实验八、UART........................................................................................................................32实验一、单片机间的多机通信(1)实验题目采用C语言实现单片机间的多机通信。实现内容:三个51单片机进行多机通信。一个单片机用于温度的采集(可采用可变电阻模拟温度值),一个单片机用于控制8个LED灯循环显示,显示的时间间隔从主机中获得,主机用于发送温度的大小值及循环显示的时间给从机。(2)实验目的掌握proteus和软件环境——keilC的联机调试过程掌握基于ARMc编程基础(3)实验设备1.Proteus8Professional仿真开发环境;2.KeiluVision4(4)实验步骤1.1打开Proteus8,选择isis绘制电路图,点击p添加元件AT89C51,BUTTON,CAP,CAP-ELEC,CRYSTAL,RES.1.2绘制电路图如图所示:1RXDTXDTXDRXDTXDRXDp1.7p1.7p1.6p1.6p1.5p1.4p1.3p1.5p1.2p1.1p1.0p1.4p1.0p1.1p1.2p1.3XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C51B1B2XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U2AT89C51XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U3AT89C51发送显示时间发送温度加1CS1CH02CH13GND4VCC8CLK7DI5DO6U5ADC083275%OUTGANVCCRV11k主机从机1从机2TIME_RESETCCT002XTAL1XTAL2RSTEATIME_RESET2CCT002XTAL1XTAL2RSTEATIME_RESET1CCT002XTAL1XTAL2RSTEA2.1打开KeiluVision5,newproject和newfile2.2编写代码:(c语言)/************************************实验一*主机*发送循环显示时间和温度值给从机*************************************/#includereg51.h#includestring.h#define_SUCC_0x0f//数据传送成功#define_ERR_0xf0//数据传送失败#defineucharunsignedchar#defineuintunsignedintuintTime[]={0,1,2,3,4,5,6,7};//循环显示时间间隔(s)uintT[]={22,33,66,77,88,99};sbitKEY1=P3^3;sbitKEY2=P3^5;ucharcount=0;//延时1ms函数voiddelay_1ms(uintt){uinty;while(t--)2for(y=110;y0;y--);}//串口初始化函数voidserial_init(){TMOD=0x20;//定时器1工作于方式2TH1=0xfd;TL1=0xfd;//波特率为9600PCON=0;SCON=0xd0;//串口工作于方式3TR1=1;//开启定时器TI=0;RI=0;}//发送数据函数voidSEND_data(uint*Buff){TI=0;//发送数据长度TB8=0;//发送数据帧P2=Buff[count];SBUF=Buff[count];while(!TI);TI=0;count++;count=count%5;}//向指定从机地址发送数据voidADDR_data(ucharaddr,uint*Buff){uchartemp=0xff;while(temp!=addr)//主机等待从机返回其地址作为应答信号{TI=0;//发送从机地址TB8=1;//发送地址帧SBUF=addr;while(!TI);TI=0;RI=0;while(!RI);temp=SBUF;RI=0;}3SEND_data(Buff);}//main函数voidmain(){serial_init();while(1){if(KEY1==0){delay_1ms(5);if(KEY1==0){while(!KEY1);ADDR_data(0x01,Time);}}if(KEY2==0){delay_1ms(5);if(KEY2==0){while(!KEY2);ADDR_data(0x02,T);}}}}/************************************实验一*从机1*接收主机发送的温度值*************************************/#includereg51.h#includestring.h#includeintrins.h#defineaddr0x02//从机2的地址#define_SUCC_0x0f//数据传送成功#define_ERR_0xf0//数据传送失败#defineuintunsignedint#defineucharunsignedcharunsignedcharBuff[20];//数据缓冲区ucharflag=0;//请求标志4sbitcs=P1^0;sbitclk=P1^1;sbitdio=P1^2;//串口初始化函数voidserial_init(){TMOD=0x20;//定时器1工作于方式2TH1=0xfd;TL1=0xfd;//波特率为9600PCON=0;SCON=0xd0;//串口工作于方式3TR1=1;//开启定时器TI=0;RI=0;}//----------------------------------//延时//-----------------------------------voiddelay(uintx){uinti;while(x--)for(i=0;i120;i++);}//--------------------------------------//得到ad转结果//-------------------------------------ucharget_ad_result(){uchari,dat1=0,dat2=0;cs=0;clk=0;dio=1;_nop_();_nop_();clk=1;_nop_();_nop_();clk=0;dio=1;_nop_();_nop_();clk=1;_nop_();_nop_();clk=0;dio=0;_nop_();_nop_();clk=1;dio=1;_nop_();_nop_();clk=0;dio=1;_nop_();_nop_();for(i=0;i8;i++){clk=1;_nop_();_nop_();5clk=0;_nop_();_nop_();dat1=dat11|dio;}for(i=0;i8;i++){dat2=dat2|((uchar)(dio)i);clk=1;_nop_();_nop_();clk=0;_nop_();_nop_();}cs=1;return(dat1==dat2)?dat1:0;}//------------------------------------//主函数//-------------------------------------voidmain(){uinti=0,j=0;uchartemp=0,temp2=0;ucharaa=0xff;serial_init();while(1){SM2=1;//接收地址帧aa=0xff;while(aa!=addr)//从机等待主机请求自己的地址{RI=0;while(!RI){temp=get_ad_result();//温度采集结果if(temp!=temp2)P2=temp
本文标题:proteus单片机pcbarm实验报告
链接地址:https://www.777doc.com/doc-50143 .html