微机实验余成驹光电1202班U201214134实验名称LED数码管显示实验指导教师专业班级姓名学号联系方式一实验要求:实验四LED数码管显示实验实验目的:理解LED七段数码管的显示控制原理,掌握数码管与MCU的接口技术,能够编写数码管显示驱动程序;熟悉接口程序调试方法。实验内容:利用C8051F310单片机控制数码管显示器基本要求:利用末位数码管循环显示数字0-F,显示切换频率为1Hz。提高要求:在数码管上显示0→199计数,计数间隔为0.5秒。二、设计思路1基本要求:对F310信号频率进行8分频,再对定时器进行48分频,以使在一次定时时间范围内实现1s定时。采用查询方式进行定时。P0.6,P0.7作为位选信号来一直选择末位数码管输出信号。再利用R0作为相对寻址来储存数据并赋值给A。通过MOVCA,@A+DPTR指令,利用顺序查表法取出显示段码数据。寄存器R0自增1,并赋给A以取出下一个显示段码数据。2提高要求:微机实验余成驹光电1202班U201214134依然对信号频率八分频,对定时器进行48分频,通过P0,6,P0.7进行位控选择数码管输出,定时器定时0.5s,当溢出时进入中断,并通过中断程序将段位控制按序加一,R3,R6,R7分别储存第一第二第三位数码管段位码,利用A为中间变量,通过P1输出储存的值,查表输出数码管值,达到119时结束。三、资源分配1基本要求:P0.6:位选信号端口P0.7:位选信号端口P1:输出段码数据R0:存放显示数据DPTR:指向段码数据表首2提高要求:P0.6:位选信号端口P0.7:位选信号端口P1:输出段码数据DPTR:指向段码数据表首R3,R6,R7:分别储存第三第二第一位数码管数据四、流程图1基本要求2提高要求:主程序微机实验余成驹光电1202班U201214134延时程序微机实验余成驹光电1202班U201214134接--2提高要求:动态扫描程序中断程序微机实验余成驹光电1202班U201214134五、源代码(含文件头说明、语句行注释)1基本要求:ORG0000HLJMPMAINORG0100HMAIN:LCALLInit_DeviceMOVSP,#40HMOVDPTR,#TAB;将DPTR地址指向表头MOVTMOD,#01H;定时器采用T0定时方式一MOVTH0,#06H;定时器赋予初值MOVTL0,#0C6HCLRP0.6;选择末位数码管CLRP0.7START:MOVR0,#00H;赋初值0CLRAMOVCA,@A+DPTR;查表输出MOVP1,ASETBTR0;定时器开始工作HERE:JNBTF0,HERE;等待溢出CLRTR0CLRTF0MOVTH0,#06H;重新赋予初值MOVTL0,#0C6HCJNER0,#0FH,NEXT;等待末位数码管到FSJMPSTARTNEXT:INCR0;R0加一MOVA,R0MOVCA,@A+DPTRMOVP1,A;P1输出SETBTR0SJMPHERE;踏步微机实验余成驹光电1202班U201214134org1000hTAB:DB0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0HDB0FEH,0E6H,0EEH,3EH,1AH,7AH,9EH,8EH;------------------------------------;-GeneratedInitializationFile--;------------------------------------$include(C8051F310.inc)publicInit_DeviceINITSEGMENTCODErsegINIT;Peripheralspecificinitializationfunctions,;CalledfromtheInit_DevicelabelPCA_Init:anlPCA0MD,#0BFhmovPCA0MD,#000hretTimer_Init:movCKCON,#002hretPort_IO_Init:;P0.0-Unassigned,Open-Drain,Digital;P0.1-Unassigned,Open-Drain,Digital;P0.2-Unassigned,Open-Drain,Digital;P0.3-Unassigned,Open-Drain,Digital;P0.4-Unassigned,Open-Drain,Digital;P0.5-Unassigned,Open-Drain,Digital;P0.6-Unassigned,Open-Drain,Digital;P0.7-Unassigned,Open-Drain,Digital;P1.0-Unassigned,Push-Pull,Digital;P1.1-Unassigned,Push-Pull,Digital;P1.2-Unassigned,Push-Pull,Digital;P1.3-Unassigned,Push-Pull,Digital;P1.4-Unassigned,Push-Pull,Digital;P1.5-Unassigned,Push-Pull,Digital;P1.6-Unassigned,Push-Pull,Digital;P1.7-Unassigned,Push-Pull,Digital;P2.0-Unassigned,Open-Drain,Digital微机实验余成驹光电1202班U201214134;P2.1-Unassigned,Open-Drain,Digital;P2.2-Unassigned,Open-Drain,Digital;P2.3-Unassigned,Open-Drain,DigitalmovP1MDOUT,#0FFhmovP2MDOUT,#0C0hmovXBR1,#040hret;Initializationfunctionfordevice,;CallInit_DevicefromyourmainprogramInit_Device:lcallPCA_InitlcallTimer_InitlcallPort_IO_InitretEND2提高部分:ORG0000HLJMPSTARTORG000BHLJMPTI00ORG0300HSTART:LCALLInit_DeviceMOVR3,#00H;百位数码管赋予初值MOVR6,#00H;十位数码管赋予初值MOVR7,#01H;个位数码管赋予初值MOV60H,#00H;设置位控码MOV61H,#40HMOV62H,#80HMOVTMOD,#01H;选择定时器T0方式一SETBET0;开外中断T0SETBEA微机实验余成驹光电1202班U201214134MOVTH0,#131;定时器赋予初值MOVTL0,#99MAIN:LJMPDISP;跳入动态输出子程序MAIN1:LCALLCOUNTERAJMPMAIN;重新扫描;=================动态输出子程序==================DISP:MOVSP,#30H;设置堆栈指针MOVR1,#60H;位选指针赋初值MOVP1,#00H;灯全灭;=================LD0:MOVA,@R1;取出位选码ANLP0,#3FH;将P0端口高两位置零(这样做的目的是为了避免用MOV指令影响到P0端口的低6位)ORLP0,A;输出位选信号MOVA,R7;取出段选码MOVDPTR,#TAB;DPTR指向段选码表第一个数据MOVCA,@A+DPTR;查表,取出段选码MOVP1,A;输出段选码LCALLDL1MS;延时1ms,灯亮1msMOVP1,#00H;灯全灭INCR1;位选指针加一MOVA,@R1;取出位选码ANLP0,#3FH;将P0端口高两位置零(这样做的目的是为了避免用MOV指令影响到P0端口的低6位)ORLP0,A;输出位选信号MOVA,R6;取出段选码MOVDPTR,#TAB;DPTR指向段选码表第一个数据MOVCA,@A+DPTR;查表,取出段选码MOVP1,A;输出段选码LCALLDL1MS;延时1ms,灯亮1ms微机实验余成驹光电1202班U201214134MOVP1,#00H;灯全灭INCR1MOVA,@R1;取出位选码ANLP0,#3FH;将P0端口高两位置零(这样做的目的是为了避免用MOV指令影响到P0端口的低6位)ORLP0,A;输出位选信号MOVA,R3;取出段选码MOVDPTR,#TAB;DPTR指向段选码表第一个数据MOVCA,@A+DPTR;查表,取出段选码MOVP1,A;输出段选码LCALLDL1MS;延时1ms,灯亮1msMOVP1,#00H;灯全灭LJMPMAIN1;返回主程序;===============延时1ms子程序=============ORG0050HDL1MS:MOVR4,#4;延时程序通过R4,R5实现D1:MOVR5,#253NOPDJNZR5,$DJNZR4,D1RETORG0100HCOUNTER:SETBTR0;定时器开启RET;中断程序TI00:MOVTH0,#133;中断程序重新赋予初值MOVTL0,#99INCR7;个位加一CJNER7,#0BH,S1;判断个位是否进位MOVR7,#01H;重新将个位归零CJNER6,#00H,S2;判断此时十位是否显示微机实验余成驹光电1202班U201214134MOVR6,#01H;若不显示则开启显示S2:INCR6;十位加一CJNER6,#0BH,S1;判断十位是否进位CJNER3,#00H,S3;判断百位是否显示MOVR3,#01HS3:INCR3;百位加一MOVR6,#01H;十位重新归零CJNER3,#03H,S1;判断百位是否到2MOVP1,#00H;如果到200则数码管全熄灭SJMP$;踏步停止S1:RETI;中断返回ORG0200H;===============段选码表==============;TAB:DB00H,0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H,0FEH,0F6H;$include(C8051F310.inc)publicInit_DeviceINITSEGMENTCODErsegINIT;Peripheralspecificinitializationfunctions,;CalledfromtheInit_DevicelabelPCA_Init:anlPCA0MD,#0BFhmovPCA0MD,#000hretTimer_Init:movCKCON,#002hret微机实验余成驹光电1202班U201214134Port_IO_Init:;P0.0-Unassigned,Open-Drain,Digital;P0.1-Unassigned,Open-Drain,Digital;P0.2-Unassigned,Open-Drain,Digital;P0.3-Unassigned,Open-Drain,Digital;P0.4-Unassigned,Open-Drain,Digital;P0.5-Unassigned,Open-Drain,Digital;P0.6-Unassigned,Push-Pull,Digital;P0.7-Unassigned,Push-Pull,Digital;P1.0-Unassigned,Push-Pull,Digital;P1.1-Unassigned,Push-Pull,Digital;P1.2-Unassigned,Push-Pull,Digital;P1.3-Unassigned,Push-Pull,Digital;P1.4-Unassigned,Push-Pull,Digital;P1.5-Unassigned,Push-Pull,Digital;P1.6-Unassigned,Push-Pull,Digital;P1.7-Unassigned,Push-Pull,