资源描述:
《单片机课程设计参考程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、设计思路:1、255计数:255可用8位二进制数表示,故本设计可直接采用可以重装载的计数器T1模式二进行计数。然后对TL1的内容进行相应的二进制---十进制转换:首先TL1的内容除以64H,所的商就是十进制的百位,然后用余数除以0AH,所得的商就是十进制数的十位,余数即相应的十进制的个位。接着将相应的十进制数进行译码,并在LED数码管上显示出来。每来一个脉冲其显示的结果加一,直加至255然后T1重新开始计数。开始初始化堆栈,定时器初始化清零相关RAM地址单元TF1=1?调用显示子程序脉冲数加1即20H
2、加120H=100?21H加120清零计算出脉冲数的个,十,百位分别存放于30H,31H,32H(20H=54)&(21H=2?)脉冲数计到255后重新计数即20H,21H清零说明:1.20H存放脉冲的个位和十位数值,21H存放脉冲的百位和千位数值。2.计算脉冲数的个位和十位数值:(20H)/10的商即十位数值存放于31H,余数即个位数值存放于30H。3.计算脉冲数的百位数值:(20H)/10的余数即百位数值存放于32H。例如:脉冲数212(十进制),(20H)=12,(21H)=2。脉冲的个位数值(
3、30H)=2,脉冲的十位数值(31H)=1,脉冲的百位数值(32H)=2.图3255计数程序流程图课程设计参考程序,希望大家好好研读,尽量完全融会贯通。一、255计数ORG0000HLJMPSTARTORG0030HSTART:MOVTMOD,#50HSETBTR1SETBTR0MOVA,TL1LCALLBCDLCALLDISPLAYLJMPSTARTBCD:MOVB,#64HDIVABMOV72H,AXCHA,BMOVB,#0AHDIVABMOV71H,AMOV70H,BRETDISPLAY:MOV
4、R1,#70h;指向显示缓冲区的首地址MOVR5,#00h;数码管显示从最低位开始play:MOVA,R5MOVp2,AMOVA,@R1MOVDPTR,#TABMOVCA,@A+DPTRMOVp0,ALCALLdl5msMOVp0,#0ffh;消隐INCR1INCR5CJNER5,#03h,playRET;1ms延时程序,LED显示用dl5ms:push06hpush07hmovr6,#32hdl1:movr7,#10hdl2:djnzr7,dl2djnzr6,dl1nopnopnoppop07hpo
5、p06hRETENDTAB:DB0C0h,0F9h,0A4h,0B0h,099h,092h,082h,0F8h,080h,90h;0123456789不亮二、0-999999循环计数ORG0000HLJMPSTARTORG0030HSTART:MOV70H,#00HMOV71H,#00HMOV72H,#00HMOV73H,#00HMOV74H,#00HMOV75H,#00HMOVTL1,#0FFHSTART1:MOVTMOD,#50HSETBTR1LCALLDISPLAYMOVR4,TL1CJNER4
6、,#00H,START1LCALLBCDLJMPSTART1BCD:MOVTL1,#0FFHINC70HMOVA,70HCJNEA,#0AH,RETURNMOV70H,#00HINC71HMOVA,71HCJNEA,#0AH,RETURNMOV71H,#00HINC72HMOVA,72HCJNEA,#0AH,RETURNMOV72H,#00HINC73HMOVA,73HCJNEA,#0AH,RETURNMOV73H,#00HINC74HMOVA,74HCJNEA,#0AH,RETURNMOV74H,#
7、00HINC75HMOVA,75HCJNEA,#0AH,RETURNMOV75H,#00HRETURN:RETDISPLAY:MOVR1,#70h;指向显示缓冲区的首地址MOVR5,#00h;数码管显示从最低位开始play:MOVA,R5MOVp2,AMOVA,@R1MOVDPTR,#TABMOVCA,@A+DPTRMOVp0,ALCALLdl5msINCR1INCR5CJNER5,#06h,playRET;1ms延时程序,LED显示用dl5ms:PUSH06hPUSH07hMOVR6,#32hdl1
8、:MOVR7,#10hdl2:DJNZR7,dl2DJNZR6,dl1NOPNOPNOPPOP07hPOP06hRETTAB:DB0C0h,0F9h,0A4h,0B0h,099h,092h,082h,0F8h,080h,90h;0123456789不亮三、出租车计费汇编程序:ORG0000HLJMPSTARTORG0030HSTART:MOV70H,#05HMOV71H,#00HMOV72H,#00HMOV73H,#00HMOV74H,#05HMOV75