您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 其它行业文档 > 扬大电气单片机实验程序
3.1Keil集成开发环境熟悉及汇实验编程序1.MOV20H,#98HMOVA,20HMOVB,#100DIVABMOV30h,AXCHA,BMOVB,#10DIVABMOV31H,AMOV32H,BRETEND2.MOV20H,#78HMOVA,20HANLA,#0FHADDA,#30HMOV30H,AMOVA,20HANLA,#0F0HSWAPAADDA,#30HMOV31H,A3.MAIN:MOV30H,#2MOV31H,#3MOV3AH,#4MOV43H,#3MOVR0,#30HMOVR7,#10MOVA,#00HLOOP:MOV@R0,AINCR0DJNZR7,LOOPRETEND4.MAIN:MOV30H,#3MOV31H,#5MOV3FH,#6MOVR0,#30HMOVR1,#40HMOVR7,#16LOOP:MOVA,@R0MOV@R1,AINCR0INCR1DJNZR7,LOOPRETEND并行I/O接口实验1.ORG0000HAJMPMAINORG0100HMAIN:MOVA,#0FEHLIGHT:MOVP1,ARRAMOVP1,AACALLDELAYAJMPLIGHTDELAY:MOVR7,#250DELAY1:MOVR6,#250NOPDELAY2:DJNZR6,DELAY2DJNZR7,DELAY1RETEND2.ORG0000HAJMPMAINORG0100HMAIN:SETBP1.0SETBP1.1LOOP:MOVC,P1.0MOVP1.2,CMOVC,P1.1MOVP1.3,CAJMPLOOPSJMP$END3.ORG0000HAJMPMAINORG0100HMAIN:SETBP1.7LOOP:MOVC,P1.7MOVP1.1,CMOVP1.0,CAJMPLOOPSJMP$END3.3点阵式LED显示实验1.ORG0000HLJMPMAINORG0030HMAIN:MOVA,#0FEHMOVR4,#8LCALLT164SJMPMAINT164:RLCAMOVP3.3,CMOVP3.4,CSETBP3.2CLRP3.2LCALLDELDJNZR4,T164DEL:MOVR5,#04HDEL1:MOVR6,#0FFHDEL2:MOVR7,#0FFHDEL3:DJNZR7,DEL3DJNZR6,DEL2DJNZR5,DEL1END2.ORG0SJMPMAINORG30HMAIN:MOVR1,#10X:MOVDPTR,#TABXMOVB,#0FEH;B寄存器作列值变换CLRCMOVR2,#8;R2作列循环计数LCALLLOOPDJNZR2,LOOPDJNZR1,XSJMPMAINLOOP:MOVA,#0MOVP1,#0FFHMOVR4,#8;R4作行串并转换计数;行值设置MOVCA,@A+DPTRINCDPTRLCALLT164;列值设置MOVP1,BMOVA,BRLAMOVB,A;延时LCALLDELRETSJMPMAIN;串并转换程序T164:RLCAMOVP3.3,CMOVP3.4,CSETBP3.2CLRP3.2DJNZR4,T164RET;延时子程序DEL:MOVR5,#20DEL1:MOVR6,#125DEL2:DJNZR6,DEL2DJNZR5,DEL1RETTABX:DB7EH,0BDH,0DBH,0E7H,0E7H,0DBH,0BDH,7EHTABT:DB0FCH,0FCH,0FCH,00H,00H,0FCH,0FCH,0FCHTABL:DB00H,00H,3FH,3FH,3FH,3FH,3FH,3FHTABE:DB00H,00H,24H,24H,24H,24H,24H,24H3.4I2C总线和8段LED显示实验1.内容1,显示12345678;************************************************************************;定义器件地址及存放单元ZLG7290EQU70H;ZLG7290的器件地址SLADATA63H;器件的从地址SUBADATA64H;器件的子地址;定义变量单元ACKBIT10H;应答标志位NUMBYTEDATA62H;读/写的字节数变量MTDEQU6EH;发送数据缓冲器DISBUFEQU66H;66H~6DH为显示缓冲区,66H对应最右一位;以上定义一般不要改动;I2C引脚定义SDABITP3.0SCLBITP3.1RSTBITP3.6;************************************************************************ORG0000HLJMPMAINORG0030HMAIN:MOVSP,#70H;设堆栈,建议堆栈设在此处LCALLRE7290;复位RE7290MOVR0,#DISBUF;显缓区首地址(66H)MOVA,#1FH;将熄灭码依次填入显缓区MOVR2,#8MLOOP:MOV@R0,AINCR0DJNZR2,MLOOPCC:MOVR0,#DISBUFMOVR3,#08HMOVA,#08HAA:MOV@R0,AINCR0DECADJNZR3,AALCALLLEDDISP;调用显示程序LCALLDELAY;延时SJMPCC$INCLUDE(LEDDISP_ASM.INC);包含LED显示模块程序END2.ZLG7290EQU70HSLADATA63HSUBADATA64HACKBIT10HNUMBYTEDATA62HMTDEQU6EHDISBUFEQU66HSDABITP3.0SCLBITP3.1RSTBITP3.6ORG0000HLJMPMAINORG0030HMAIN:MOVSP,#70HLCALLRE7290MOVR0,#DISBUFMOVA,#1FHMOVR2,#8MLOOP:MOV@R0,AINCR0DJNZR2,MLOOPAA:MOVR0,#DISBUFMOVA,P1MOVB,#64HDIVABMOV@R0,AINCR0MOVA,BMOVB,#10DIVABMOV@R0,AINCR0MOVA,BMOV@R0,ALCALLLEDDISPLCALLDELAYSJMPAA$INCLUDE(LEDDISP_ASM.INC)END3.5中断实验1.ORG0LJMPMAINORG0003HLJMPINT00ORG30HMAIN:SETBEASETBEX0SETBIT0SETBP1.0HERE:JMPHEREINT00:CPLP1.0RETIEND2.ORG0000HLJMPMAINORG0003HLJMPINTT0ORG0100HMAIN:SETBEX0SETBIT0SETBEAMOVR1,#0MOVA,#0FCH//点亮最低位应送值CL:MOVR4,#8//移位7次DL:MOVR5,#10//50MS*10MOVP1,ACHULI:CJNER1,#0,CHULI1//R1为0,左移一位循环点亮RLACHULI1:CJNER1,#1,CHULI2//R1为1,右移一位循环点亮RRACHULI2:CJNER1,#2,CHULI3//R1为2,左移两位循环点亮RLARLACHULI3:CJNER1,#3,DELAY//R1为3,右移两位循环点亮RRARRADELAY:LCALLDELDJNZR5,DELAY//每一次调用DEL延时50ms,调用R5次DJNZR4,DL//每轮位移R4次LJMPCL//一轮结束,从头再来,主要从新赋值R4DEL:MOVR6,#200//较精确50ms延时DEL1:MOVR7,#123NOPDEL2:DJNZR7,DEL2DJNZR6,DEL1RETINTT0:INCR1CJNER1,#4,FANHUIMOVR1,#0FANHUI:RETIEND3.ORG0LJMPMAINORG0003HLJMPINTOOORG30HMAIN:SETBEASETBEX0SETBIT0SETBP1.0MOV30H,#0ORG50HHERE:JMPHEREINTOO:MOVA,30HADDA,#1MOV30H,AMOVA,31HADDCA,#0MOV31H,AMOVA,30HCPLAMOVP1,ARETIEND3.6定时/计数器实验1.;调用LED显示的示例程序:将按键连到T0引脚,程序对按键次数计数并显示。;************************************************************************;定义器件地址及存放单元ZLG7290EQU70H;ZLG7290的器件地址SLADATA63H;器件的从地址SUBADATA64H;器件的子地址;定义变量单元ACKBIT10H;应答标志位NUMBYTEDATA62H;读/写的字节数变量MTDEQU6EH;发送数据缓冲器DISBUFEQU66H;66H~6DH为显示缓冲区,66H对应最右一位;以上定义一般不要改动;I2C引脚定义SDABITP3.0SCLBITP3.1RSTBITP3.6;************************************************************************ORG0000HLJMPMAINORG0100HMAIN:MOVSP,#70H;设堆栈,建议堆栈设在此处LCALLRE7290;复位RE7290MOVR0,#DISBUF;显缓区首地址(66H)MOVA,#1FH;将熄灭码依次填入显缓区MOVR2,#8MLOOP:MOV@R0,AINCR0DJNZR2,MLOOPMOVTMOD,#05HMOVTH0,#0MOVTL0,#0SETBET0SETBEASETBTR0PLAY:MOVR1,TL0MOVA,R1CPLAMOVR1,AMOVP1,R1MOVB,#100MOVA,TL0DIVABMOV68H,AMOVA,BMOVB,#10DIVABMOV67H,AMOV66H,BMOVB,#100MOVA,TH0DIVABMOV6BH,AMOVA,BMOVB,#10DIVABMOV6AH,AMOV69H,BLCALLLEDDISPLCALLDELAYLJMPPLAY$INCLUDE(LEDDISP_ASM.INC)END2.ORG0000HLJMPMAINORG000BHLJMPIT0PORG0100HMAIN:MOVSP,#60H;设堆栈指针MOVB,#20;设循环次数20次MOVTMOD,#01HMOVTL0,#0B0HMOVTH0,#3CHSETBTR0SETBET0SETBEAHERE:SJMPHERE;原地循环,等待中断IT0P:MOVTL0,#0B0H;重装初值MOVTH0,#3CHDJNZB,LOOPMOVB,#20CPLP1.0LOOP:RETI;返回“SJMPHERE”处END3.ORG0000HLJMPMAINORG000BHLJMPIT0PORG001BHLJMPIT1PORG0100HMAIN:MOVSP,#60HMOVTMOD,#16H;IT0计数,IT1定时MOVTL0,#0FFHMOVTH0,#0FFHSETBTR0SETBET0MOVTL1,#0B0HMOVTH1,#3CHSETBET1SETBEASETBPT1CLRPT0MOVR0,#3;0~3,选择显示的效果4种MOVR1,#8;走马灯MOVB,#10;显示延迟所需的循环次数10词HERE:AJMPHEREIT0P:CJNER0,#0FFH,TMOVR0,#3T:CJNER0,#3,T2MOVDPTR,#TAB1T2:CJNER0,#2,T3MOVDPTR,#TAB2T3:CJNER0,#1,T4MOVDPTR,#TAB3T4:CJNER0,#0,T5MOVDPTR,#TAB4T5:MOVR2,DPLMOVR3,DPHLOOP:MOVDPL,R2MOVDPH,R3MOVR1,#8LOOP1:CLRAMOVCA,@A+DPTRMOVP1,AMOVC,TF0;IT0溢出
本文标题:扬大电气单片机实验程序
链接地址:https://www.777doc.com/doc-2416005 .html