资源描述:
《单片机实验程序.docx》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、试验一流水灯独立键盘org0000hajmpmainorg0100hmain:mova,#01hloop:movp1,acalldelyclrcrlaajmploopdely:movr6,#0hdel1:movr7,#0hdel:djnzr6,deldjnzr7,delretendORG0000HLJMPMAINORG0100HMAIN:MOVP1,#03HLOOP:MOVC,P1.0MOVP1.2,CMOVC,P1.1MOVP1.3,CLJMPLOOPEND试验二.定时器ORG0000HAJMPSTARTORG000BHAJMPTO
2、INTORG0100HSTART:MOVTMOD,#01HMOVTL0,#0B0HMOVTH0,#03CHMOVR7,#0AHMOVP1.0,ASETBET1SETBEASETBTR0WAIT:MOVA,R7CJNEA,#00H,WAITLJMPSTARTTOINT:DECR7MOVTL0,#0B0HMOVTH0,#3CHCPLP1.0RETIEND试验三数码管显示ORG0000hLJMPSTARTORG0100HSTART:MOV79H,#04HMOV8AH,#05HMOV8BH,#04HMOV8CH,#02HMOV8DH,#02H
3、MOV8EH,#00HacallDIRDIR:MOVR0,#79HMOVR2,#01MOVA,R2LD0:MOVDPTR,#8002HMOVX@DPTR,AMOVDPTR,#8004HMOVA,@R0MOVA,#13HMOVCA,@A+PCMOVX@DPTR,AACALLDL1INCR0MOVA,R2JBACC.5,LD1RLAMOVR2,AAJMPLD0LD1:RETDB3FH,06H,5BH,4FH,66H,6DHDB7DH,07H,7FH,67H,77H,7CHDB39H,5EH,79H,71HDL1:MOVR7,#02HDL2
4、:MOVR6,#0FFHDL3:DJNZR6,DL3DJNZR7,DL2RETEND试验四键盘OUTBITEQU08002H;位控制口OUTSEGEQU08004H;段控制口INEQU08001H;键盘读入口LEDBUFEQU60H;显示缓冲LJMPSTARTLEDMAP:DB3FH,06H,5BH,4FH,66H,6DH,7DH,07H;八段管显示码DB7FH,6fH,77H,7CH,39H,5EH,79H,71HDELAY:MOVR7,#01H;延时子程序MOVR6,#01HDELAYLOOP:DJNZR7,DELAYLOOPDJ
5、NZR6,DELAYLOOPRETDISPLAYLED:MOVR0,#LEDBUFMOVR1,#06H;共6个八段管MOVR2,#00100000B;从左边开始显示LOOP:MOVDPTR,#OUTBITMOVA,#0HMOVX@DPTR,A;关所有八段管MOVA,@R0MOVDPTR,#OUTSEGMOVX@DPTR,AMOVDPTR,#OUTBITMOVA,R2MOVX@DPTR,A;显示一位八段管MOVR6,#01HCALLDELAYMOVA,R2;显示下一位RRAMOVR2,AINCR0DJNZR1,LOOPRETTESTKE
6、Y:MOVDPTR,#OUTBITMOVA,#00HMOVX@DPTR,A;输出线置为0MOVDPTR,#INMOVXA,@DPTR;读入键状态CPLAANLA,#0FH;高四位不用RETKEYTABLE:DB16H,15H,14H,0FFH;键码定义DB13H,12H,11H,10HDB0DH,0CH,0BH,0AHDB0EH,03H,06H,09HDB0FH,02H,05H,08HDB00H,01H,04H,07HGETKEY:MOVDPTR,#OUTBITMOVP2,DPHMOVR0,#LOW(IN)MOVR1,#0010000
7、0BMOVR2,#06HKLOOP:MOVA,R1;找出键所在列CPLAMOVX@DPTR,ACPLARRAMOVR1,A;下一列MOVXA,@R0CPLAANLA,#0FHJNZLOOP1;该列有键入DJNZR2,KLOOPMOVR2,#0FFH;没有键按下,返回0ffhSJMPEXITLOOP1:MOVR1,A;键值=列X4+行MOVA,R2DECARLARLAMOVR2,A;r2=(r2-1)*4MOVA,R1;r1中为读入的行值MOVR1,#04HLOOP2:RRCA;移位找出所在行JCEXITINCR2;r2=r2+行值DJ
8、NZR1,LOOP2Exit:MOVA,R2;取出键码MOVDPTR,#KEYTABLEMOVCA,@A+DPTRMOVR2,AWAIT:MOVDPTR,#OUTBIT;等键释放CLRAMOVX@DPTR,AMOVR6,