您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 南昌大学-单片机课程设计-设计图-源程序
(上图硬件原理图可以另存为图片放大了看,清晰度五颗星,放心好了)源程序清单1.汇编程序ORG0000H;主程序入口0000020030LJMPMAINORG0003H;外部中断0入口00030200D4LJMPA2DORG000BH;t0入口000B02007ALJMPSELECTORG0013H;外部中断1入口0013020062LJMPKEYORG0030HMAIN:;主程序003075A886MOVIE,#86H;外部中断0,t0,外部中断1使能00337590F6MOVP1,#0F6H;键盘初值0036758C3CMOVTH0,#3CH;t0赋初值0039758AB0MOVTL0,#0B0H003C758901MOVTMOD,#01H;设置t0工作方式为方式1003FD288SETBIT0;打开中断00041120048LCALLXUEHAO;调用显示学号子程序00447C1EMOVR4,#30;设置t0延时次数,即任务中延时1.5s的功能选择,因为定时器最多计时65536us,所以需要多次计时累计004680FESJMP$;踏步命令00489001A7XUEHAO:MOVDPTR,#XUEHAOTAB;学号显示子程程序004B7A03MOVR2,#3;3次刷新004D7B05XUEHAO2:MOVR3,#5;每次发送5个显示码进数码管004F7400XUEHAO1:MOVA,#0;a清零,dptr自加来选择需要显示的字型码005193MOVCA,@A+DPTR;查表,给a赋值0052F599MOVSBUF,A;a发送到串行口00543099FDJNBTI,$;查询串行口发送中断标志位0057C299CLRTI;清除中断标志位,准备进行下一次发送0059A3INCDPTR;dptr加1,指向下一个字型码地址005ADBF3DJNZR3,XUEHAO1;执行显示5个字型码005C12018DLCALLDELAY1S;延迟1s005FDAECDJNZR2,XUEHAO2;刷新3次006122RET006212019EKEY:LCALLDELAY10MS;键盘按键响应程序006520B311JBP3.3,KEY1;延迟10ms之后判断是否按键还是按下状态,为按下则返回00689001B6MOVDPTR,#SHUZITAB;dptr指向数字表首地址006B1200B4LCALLJUDGEKEY;调用判断键值子程序006E04INCA;键值加1调用字型码(因为硬件显示的数字比键值大1)006F93MOVCA,@A+DPTR;查表得字型码0070F599MOVSBUF,A;发送a到串行口进行显示00723099FDJNBTI,$;0075C299CLRTI0077D28CSETBTR0;打开定时器t0007932KEY1:RETI;中断返回SELECT:;长按1.5s功能选择程序007A20B319JBP3.3,SELECTOUT;判断按键是否按下,否则返回007DDC17DJNZR4,SELECTOUT;判断是否达到1.5s,否则r4减1返回(r4记录中断次数)007F1200B4LCALLJUDGEKEY;调用判断键值子程序0082B40003CJNEA,#0,SELECT1;得到a的键值,判断功能008512009DLCALLD2A0088B40103SELECT1:CJNEA,#1,SELECT2008B120048LCALLXUEHAO008EB40303SELECT2:CJNEA,#3,SELECT300911200CALCALLATOD00947C1ESELECT3:MOVR4,#30;r4重新赋初值0096758C3CSELECTOUT:MOVTH0,#3CH;定时计数器重新赋初值0099758A0BMOVTL0,#0BH009C32RETI;中断返回009D900FFFD2A:MOVDPTR,#0FFFH;数模转换程序00A074C8MOVA,#20000A27A64MOVR2,#10000A414D2A1:DECA00A5F0MOVX@DPTR,A00A6B400FBCJNEA,#0,D2A100A9120195LCALLDELAY3MS00AC04D2A2:INCA00ADF0MOVX@DPTR,A00AEB4C8FBCJNEA,#200,D2A200B1DAF1DJNZR2,D2A100B322RET00B47800JUDGEKEY:MOVR0,#0;键值判断程序00B67400MOVA,#000B8309402JNBP1.4,JP100BB7801MOVR0,#100BD7590A7JP1:MOVP1,#0A7H00C0309002JNBP1.0,JP200C37402MOVA,#200C528JP2:ADDA,R000C67590F6MOVP1,#0F6H00C922RET00CAE4ATOD:CLRA;模数转换程序00CBD2A8SETBEX0;打开中断000CD90FFFEMOVDPTR,#0FFFEH;dptr指向adc0808首地址00D0F0MOVX@DPTR,A;启动adc080800D17814MOVR0,#20;重新设定采样次数00D322RET;返回A2D:;模数转换中断响应程序00D490FFFEMOVDPTR,#0FFFEH00D7D2D4A2D1:SETBRS1;打开第三组00D9E0MOVXA,@DPTR;取得adc0808反馈值00DAF5F0MOVB,A;把a中的值倒置(因为采样的时候是从高位到低位倒置的)00DC7400MOVA,#000DE30F702JNBB.7,SS100E1D2E0SETBACC.000E330F602SS1:JNBB.6,SS200E6D2E1SETBACC.100E830F502SS2:JNBB.5,SS300EBD2E2SETBACC.200ED30F402SS3:JNBB.4,SS400F0D2E3SETBACC.300F230F302SS4:JNBB.3,SS500F5D2E4SETBACC.400F730F202SS5:JNBB.2,SS600FAD2E5SETBACC.500FC30F102SS6:JNBB.1,SS700FFD2E6SETBACC.6010130F002SS7:JNBB.0,SS80104D2E7SETBACC.7010675F033SS8:MOVB,#51;以下将得到数值转换成bcd码,因为a的范围是0~255,电压范围是0~5,所以将得到值除以51得到最高位整数值010984DIVAB;然后第二位再乘10,除以51,得到第二位,以此类推010AFBMOVR3,A010BE5F0MOVA,B010D75F00AMOVB,#100110A4MULAB0111FAMOVR2,A0112E5F0MOVA,B0114B4000ACJNEA,#00,LP10117EAMOVA,R2011875F033MOVB,#51011B84DIVAB011CFAMOVR2,A011DE5F0MOVA,B011F800BSJMPLP20121EALP1:MOVA,R2012204INCA012375F033MOVB,#51012684DIVAB01272405ADDA,#50129FAMOVR2,A012AE5F0MOVA,B012C75F00ALP2:MOVB,#10012FA4MULAB0130F9MOVR1,A0131E5F0MOVA,B0133B40008CJNEA,#0,LP30136E9MOVA,R1013775F033MOVB,#51013A84DIVAB013BF9MOVR1,A013C8009SJMPLP4013EE9LP3:MOVA,R1013F04INCA014075F033MOVB,#51014384DIVAB01442405ADDA,#50146F9MOVR1,A0147120157LP4:LCALLDIANYA014AC2D4CLRRS1014C90FFFEMOVDPTR,#0FFFEH014FF0MOVX@DPTR,A;转换完成,最高位,次高位,最低位分别放在r3,r2,r10150D882DJNZR0,A2D01527814MOVR0,#200154C2A8CLREX0015632RETI015774FFDIANYA:MOVA,#0ffH;显示电压程序0159F599MOVSBUF,A;显示黑015B3099FDJNBTI,$015EC299CLRTI016074FFMOVA,#0FFH0162F599MOVSBUF,A01643099FDJNBTI,$0167C299CLRTI01699001B6MOVDPTR,#SHUZITAB016CEBMOVA,R3016D93MOVCA,@A+DPTR016E547FANLA,#7FH0170F599MOVSBUF,A01723099FDJNBTI,$0175C299CLRTI0177EAMOVA,R2017893MOVCA,@A+DPTR0179F599MOVSBUF,A017B3099FDJNBTI,$017EC299CLRTI0180E9MOVA,R1018193MOVCA,@A+DPTR0182F599MOVSBUF,A01843099FDJNBTI,$0187C299CLRTI018912018DLCALLDELAY1S018C22RET018D7D64DELAY1S:MOVR5,#100;延时一秒子程序018F12019EDELAY1S1:LCALLDELAY10MS0192DDFBDJNZR5,DELAY1S1019422RET01957E06DELAY3MS:MOVR6,#6;延时一秒子程序01977FFADELAY3MS1:MOVR7,#2500199DFFEDJNZR7,$019BDEFADJNZR6,DELAY3MS1019D22RET019E7E14DELAY10MS:MOVR6,#20;延时一秒子程序01A07FFADELAY10MS1:MOVR7,#25001A2DFFEDJNZR7,$01A4DEFADJNZR6,DELAY10MS101A622RET01A7FFFFF701AAF7F7XUEHAOTAB:DB0FFH,0FFH,0F7H,0F7H,0F7H;学号显示表01ACFBFBAB01AFA7B3DB0FBH,0FBH,0ABH,0A7H,0B3H01B1F9F9C001B482B0DB0F9H,0F9H,0C0H,82H,0B0H01B6C0F9A401B9B0999201BC82F88001BF90SHUZITAB:DB0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H;数字表符号值类型A2D=00D4HCODE标号A2D1=00D7HCODE标号AC=00D6HCONST常量ACC=00E0HCONST常量ATOD=00CAHCODE标号B=00F0HCONST常量CY=00D7HCONST常量D2A=009DHCODE标号D2A1=00A4HCODE标号D2A2=00ACHCODE标号DELAY10MS=019EHCODE标号DELAY10MS1=01A0HCODE标号DELAY1S=018DHCODE标号DELAY1S1=018FHCODE标号DELAY3MS=0195HCODE标号DELAY3MS1=0197HCODE标号DIANYA=0157HCODE标号DPH=0083HCONST常量DPL=0082HCONST常量EA=00AFHCONST常量ES=00ACHCONST常量ET0=00A9HCONST常量ET1=00ABHCONST常量EX0=00A8HCONST常量EX1=00AAHCONST常量F0=00D5HCONST常量F1=00D1HCONST常量IE=00A8HCONST常量IE0=0089HCONST常量IE1=008BHCONST常量IP
本文标题:南昌大学-单片机课程设计-设计图-源程序
链接地址:https://www.777doc.com/doc-4266908 .html