湖南城市学院实验报告2018-2019学年上学期姓名:***班级学号:******实验课程:单片机原理及应用实验室名称:电子工程实验室湖南城市学院信息与电子工程学院实验中心印制实验项目名称:实验一指示灯和开关控制器实验实验时间:第周星期第五六节,年月日学生姓名:****班级学号:*****指导老师:*****实验成绩:一、实验目的及要求1、学习51单片机I/O基本输入/输出功能,掌握汇编语言的编程与调试方法;2、熟悉proteus软件,了解软件的结构组成与功能;3、学会在ISIS模块中进行汇编程序录入、编译和调试;4、理解单片机程序控制原理,实现指示灯/开关控制器的预期功能。二、实验原理实验电路原理图如图1所示,图中输入电路由外接在P3口的8只拨动开关组成;输出电路由外接在P2口的8只低电平驱动的发光二极管组成。此外,还包括时钟电路、复位电路和片选电路。图1实验原理图Y1Y3Y7Y2Y4Y1Y5Y6Y8Y2Y3Y4Y5Y6Y7Y8XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115U180C51D1LED-YELLOWD2LED-YELLOWD3LED-YELLOWD4LED-YELLOWD5LED-YELLOWD6LED-YELLOWD7LED-YELLOWD8LED-YELLOWR2200R3200R4200R5200R6200R7200R8200R9200X1CRYSTALC122uFR11k+5VC230pFC330pF+5V+5V在编程软件的配合下,要求实现如下指示灯/开关控制功能:程序启动后,8只发光二极管先整体闪烁3次(即亮→暗→亮→暗→亮→暗,间隔时间以肉眼可观察到为准),然后根据开关状态控制对应发光二极管的灯亮状态,即开关闭合相应灯亮,开关断开相应灯灭,直至停止程序运行。软件编程原理为:(1)8只发光二极管整体闪烁3次亮灯:向P2口送入数值0;灭灯:向P2口送入数值0FFH;闪烁3次:循环3次;闪烁快慢:由软件延时时间决定。(2)根据开关状态控制灯亮或灯灭开关控制灯:将P3口(即开关状态)内容送入P2口;无限持续:无条件循环。程序流程图如图2所示。主程序计数器R5←#3P2←#0延时子程序P2←#0FFH延时子程序R5-1=0?P2←P3YN延时子程序计数器R0←#100计数器R1←#50计数器R2←#25R2-1=0?R5-1=0?R5-1=0?子程序返回NNNYYY图2实验程序流程图三、实验仪器设备及装置(1)硬件:电脑一台;(2)仿真软件:Proteus;(3)编程软件KeiluVision4。其中,仿真软件ISIS元件清单如表1所示。表1仿真软件ISIS元件清单元件类别电路符号元件名称MicroprocessorICsU180C51MiscellaneousX1/12MHzCRYSTALCapacitorsC2~C3/30pFCAPCapacitorsC1/22uFCAP-ELECResistorsR1/10kRESResistorsR2~R9/200RESOptoelectronicesD1~D8LED-REDSwitches&RelaySSW1~SW8SWITCH四、实验内容和步骤(一)实验内容:(1)熟悉ISIS模块的汇编程序编辑、编译与调试过程;(2)完成实验的汇编语言的设计与编译;(3)练习ISIS汇编程序调试方法,并最终实现实验的预期功能。(二)实验步骤:(1)提前阅读与实验相关的阅读材料;(2)参考指示灯/开关控制器的原理图和实验的元件清单,在ISIS中完成电路原理的绘制;(3)参考程序流程图在KeiluVision4中编写和编译汇编语言程序;(4)利用ISIS的汇编调试功能检查程序的语法和逻辑错误;(5)观察仿真结果,检验与电路的正确性。五、实验数据记录与处理或实验现象与分析1、实验程序#includereg51.h#defineucharunsignedchar#defineuintunsignedintvoiddelay(uchark){uintj;while(k--)for(j=0;j1000;j++);}voidmain(void){uchartemp;uinti;for(i=0;i3;i++){P2=0;delay(100);P2=0xff;delay(100);}while(1){temp=P1;P2=temp;}}2、实验现象①程序开始运行后,8只发光二极管先整体闪烁3次(亮→暗→亮→暗→亮→暗)实验结果如图3图4所示。图3二极管灯亮图图4二极管灯灭图Y1Y3Y7Y2Y4Y1Y5Y6Y8Y2Y3Y4Y5Y6Y7Y8XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115U180C51D1LED-YELLOWD2LED-YELLOWD3LED-YELLOWD4LED-YELLOWD5LED-YELLOWD6LED-YELLOWD7LED-YELLOWD8LED-YELLOWR2200R3200R4200R5200R6200R7200R8200R9200X1CRYSTALC122uFR11k+5VC230pFC330pF+5V+5VY1Y3Y7Y2Y4Y1Y5Y6Y8Y2Y3Y4Y5Y6Y7Y8XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115U180C51D1LED-YELLOWD2LED-YELLOWD3LED-YELLOWD4LED-YELLOWD5LED-YELLOWD6LED-YELLOWD7LED-YELLOWD8LED-YELLOWR2200R3200R4200R5200R6200R7200R8200R9200X1CRYSTALC122uFR11k+5VC230pFC330pF+5V+5V②开关可以控制二极管的最终状态(即开关闭合则对应二极管最后的状态为亮,开关断开则对应二极管最后的状态为暗)。(1)当按下开关1278时结果如图5.1所示。图5.1二极管状态图(2)当按下开关1346时结果如图5.2所示。图5.2二极管状态图Y1Y3Y7Y2Y4Y1Y5Y6Y8Y2Y3Y4Y5Y6Y7Y8XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115U180C51D1LED-YELLOWD2LED-YELLOWD3LED-YELLOWD4LED-YELLOWD5LED-YELLOWD6LED-YELLOWD7LED-YELLOWD8LED-YELLOWR2200R3200R4200R5200R6200R7200R8200R9200X1CRYSTALC122uFR11k+5VC230pFC330pF+5V+5VY1Y3Y7Y2Y4Y1Y5Y6Y8Y2Y3Y4Y5Y6Y7Y8XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115U180C51D1LED-YELLOWD2LED-YELLOWD3LED-YELLOWD4LED-YELLOWD5LED-YELLOWD6LED-YELLOWD7LED-YELLOWD8LED-YELLOWR2200R3200R4200R5200R6200R7200R8200R9200X1CRYSTALC122uFR11k+5VC230pFC330pF+5V+5V实验结果分析:当程序启动时,可以看到8只发光二极管整体循环闪烁三次,闪烁快慢由延时时间决定,然后根据所设开关的状态对应二极管的亮灯状态。六、问题讨论下图6中单片机80C51中31号引脚为什么接+5V?图6问题分析图答:31号引脚为使能端(EA非),通过+5V电压是使单片机访问内部程序存储器,但当PC(程序计数器)值超过某值时,将自动转向执行外部程序存储器内的程序。Y1Y3Y7Y2Y4Y5Y6Y8XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115U180C51X1CRYSTALC230pFC330pF+5V实验项目名称:实验二LED灯和数码显示器的中断控制实验时间:第周星期第节,年月日学生姓名:班级学号:指导老师:实验成绩:一、实验目的及要求1