您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 其它行业文档 > 51单片机实验及代码
单片机实验实验一:开发环境的应用(1)将数据存储器的40H-4FH的内容复制成00H-0FH,并将40H-4FH的内容整体复制到外部数据存储器的1050H-105FH.(2)P1口接八只二极管,使二极管逐个循环点亮ORG0000HAJMPSTARTORG0100HSTART:MOVA,#00HMOVR0,#40HLOOP:MOV@R0,AINCAINCR0CJNEA,#10H,LOOPSECOND:MOVDPTR,#1050HMOVR1,#40HCOPY:MOVA,@R1MOVX@DPTR,AINCDPTRINCR1CJNER1,#50H,COPYSJMP$END实验二:外部中断(1)用单脉冲信号申请中断,在中断服务程序中对输出信号进行翻转(可通过P1.0接一二极管观察)ORG0000HLJMPSTARTORG0003HLJMPINTORG0100HSTART:SETBEX0SETBPX0SETBIT0SETBEASJMP$INT:CPLP1.0RETIEND(2)用单脉冲信号申请中断,要求对中断进行累加计数,并将计数结果显示在二极管上ORG0000HLJMPSTARTORG0003HLJMPINTORG0100HSTART:MOVA,#00HMOVP1,ASETBEX0SETBPX0SETBIT0SETBEASJMP$INT:MOVP1,AINCARETIEND实验三:定时器实验(1)用定时器1的方式1定时,P1.0节发光二极管,使二极管每秒闪烁五次ORG0000HLJMPMAINORG001BHLJMPINTORG0100HMAIN:MOVTMOD,#10HMOVTH1,#3CHMOVTL1,#0B0H;50ms×2=100msMOVR2,#2SETBEASETBET1SETBTR1SJMP$INT:DJNZR2,NEXTCPLP1.0MOVR2,#2NEXT:MOVTH1,#3CHMOVTL1,#0B0HSETBTR1RETIEND(2)用定时器1的方式2计数,T1引脚接单脉冲,用P1口接二极管显示计数。ORG0000HLJMPMAINORG001BHLJMPLOOPORG0100HMAIN:MOVTMOD,#60HMOVTH1,#00HMOVTL1,#00HSETBEASETBET1SETBTF1SETBTR1SJMP$LOOP:MOVP1,TL1LJMPLOOPRETIEND实验四:串行通信波特率2400bit/s。PC发送8个字节的数据给单片机,单片机接受完数据后发送两个字节55H和AAH给PC机(使用查询方式)。ORG0000HAJMPMAINORG0030HMAIN:MOVSCON,#50HMOVPCON,#00HMOVTMOD,#20HSETBTR1MOVTL1,#0F3HMOVTH1,#0F3HLOOP:MOVR0,#30HMOVR1,#08HWAIT1:JBCRI,RECEIVESJMPWAIT1RECEIVE:MOVA,SBUFMOV@R0,AINCR0DJNZR1,WAIT1MOVA,#55HMOVSBUF,AWAIT21:JBCTI,SENDSJMPWAIT21SEND:MOVA,#0AAHMOVSBUF,AWAIT22:JNBTI,WAIT22CLRTISJMPLOOPEND实验五:数码管显示及键盘扫描(1)将30H-32H中存储的6位十进制数在6个数码管上显示出来(要求编写一个将内存单元中的压缩BCD码转换为两个七段显示码的子程序和延时子程序)ORG0000HLJMPMAINORG0030HMAIN:MOV30H,#12HMOV31H,#34HMOV32H,#56HMOVR0,#30HMOVR1,#20HBCD:MOVA,@R0SWAPAANLA,#0FHACALLCTABMOVR2,AMOVA,@R0ANLA,#0FHACALLCTABMOVR3,AMOVDPTR,#8002HMOVA,R1MOVX@DPTR,AMOVDPTR,#8004HMOVA,R2MOVX@DPTR,AMOVA,R1RRAMOVR1,ALCALLDLEYMOVDPTR,#8002HMOVA,R1MOVX@DPTR,AMOVDPTR,#8004HMOVA,R3MOVX@DPTR,AMOVA,R1RRAMOVR1,ALCALLDLEYINCR0CJNER0,#33H,BCDLJMPMAINCTAB:PUSHDPHPUSHDPLMOVDPTR,#TABMOVCA,@A+DPTRPOPDPLPOPDPHRETTAB:DB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,77H,7CH,39H,5EH,79H,71HDLEY:MOVR7,#02HDL:MOVR6,#0FFHDL1:DJNZR6,DL1DJNZR7,DLRETEND(2)扫描矩阵键盘,将对应键盘值送LED显示ORG0000HLJMPSTARTORG1000HSTART:ACALLKEY1AJMPSTARTKEY1:ACALLKEY14JNZKEY3KEY2:ACALLKEY16AJMPKEY1KEY3:ACALLKEY16ACALLDELAYACALLKEY14JNZKEY4ACALLKEY16AJMPKEY1KEY4:MOVR2,#0FEHMOVR4,#00HKEY5:MOVDPTR,#8002HMOVA,R2MOVX@DPTR,AMOVDPTR,#8001HMOVXA,@DPTRJBACC.0,KEY6MOVA,#00HAJMPKEY9KEY6:JBACC.1,KEY7MOVA,#06HAJMPKEY9KEY7:JBACC.2,KEY8MOVA,#0CHAJMPKEY9KEY8:JBACC.3,KEY12MOVA,#12HKEY9:ADDA,R4KEY10:MOVR5,AKEY11:ACALLKEY14JNZKEY11MOVA,R5ACALLKEY15RETKEY12:INCR4MOVA,R2JNBACC.5,KEY13RLAMOVR2,AAJMPKEY5KEY13:AJMPKEY1KEY14:MOVDPTR,#8002HMOVA,#00HMOVX@DPTR,AMOVDPTR,#8001HMOVXA,@DPTRCPLAANLA,#0FHRETKEY15:MOVDPTR,#TABLEMOVCA,@A+DPTRMOVR3,AKEY16:MOVDPTR,#8002HMOVA,#01HMOVX@DPTR,AMOVDPTR,#8004HMOVA,R3MOVX@DPTR,AACALLDELAYRETDELAY:MOVR7,#12LOOP:MOVR6,#250DJNZR6,$DJNZR7,LOOPRETTABLE:DB7EH,7EH,5EH,79H,71H,3FH,7EH,7EH,39H,4FH,5BH,06H,7EH,7EH,7CH,7DH,6DH,66H,7EH,7EH,77H,6FH,7FH,07HEND实验六:D/A和A/D(1)利用实验箱上的电位器提供模拟量输入,将模拟量转换成二进制数字量,将转换的结果用P1口输出到二极管显示;ORG0000HLJMPMAINORG0100HMAIN:MOVDPTR,#8000HMOVA,#00HMOVX@DPTR,AMOVR2,#100DJNZR2,$MOVXA,@DPTRMOVP1,ALJMPMAINEND(2)用DAC0832将一个数值转换为模拟电压,该模拟电压接ADC0809的一个模拟输入进行模/数转换,转换结果通过P1口送到二极管显示。ORG0000HLJMPMAINORG0100HMAIN:MOVA,#90HMOVDPTR,#9000HMOVX@DPTR,AMOVDPTR,#8000HMOVX@DPTR,AMOVR2,#64HDJNZR2,$MOVXA,@DPTRMOVP1,ASJMP$END实验七:电子钟实现一个24小时制的电子钟程序,在6个数码管上显示时分秒(用定时器0中断更新计时,以压缩BCD码形式保存在内部RAM的30H、31H和32H单元);可以通过串行口调时!ORG0000HAJMPMAINORG000BHLJMPCLOCKORG0023HLJMPINPUTORG0100HMAIN:MOVTMOD,#21HCLRAMOV30H,AMOV31H,AMOV32H,AMOVTH0,#3CHMOVTL0,#0B0HMOV50H,#14H;50*20MOVTH1,#0F3HMOVTL1,#0F3H;波特率MOVSCON,#50HSETBPSMOVIE,#92HSETBTR1SETBTR0SLED:MOVR0,#30HMOVR1,#20HLJMPLEDCLOCK:MOVTH0,#3CHMOVTL0,#0B0HDJNZ50H,RETURNMOV50H,#14HMOVA,#01HADDA,32HDAAMOV32H,ACJNEA,#60H,RETURNMOV32H,#00HMOVA,#01HADDA,31HDAAMOV31H,ACJNEA,#60H,RETURNMOV31H,#00HMOVA,#01HADDA,30HDAAMOV30H,ACJNEA,#24H,RETURNMOV30H,#00HRETURN:RETILED:MOVA,@R0SWAPAANLA,#0FHACALLCTABMOVR2,AMOVA,@R0ANLA,#0FHLCALLCTABMOVR3,AMOVDPTR,#8002HMOVA,R1MOVX@DPTR,AMOVDPTR,#8004HMOVA,R2MOVX@DPTR,AMOVA,R1RRAMOVR1,ALCALLDLYMOVDPTR,#8002HMOVA,R1MOVX@DPTR,AMOVDPTR,#8004HMOVA,R3MOVX@DPTR,AMOVA,R1RRAMOVR1,ALCALLDLYINCR0CJNER0,#33H,LEDLJMPSLEDCTAB:PUSHDPHPUSHDPLMOVDPTR,#TABMOVCA,@A+DPTRPOPDPLPOPDPHRETINPUT:CLRRICLREAMOV30H,SBUFJNBRI,$CLRRIMOV31H,SBUFJNBRI,$CLRRIMOV32H,SBUFSETBEARETITAB:DB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FHDLY:MOVR7,#02HDL:MOVR6,#0FFHDL1:DJNZR6,DL1DJNZR7,DLRETEND
本文标题:51单片机实验及代码
链接地址:https://www.777doc.com/doc-5017333 .html