扬大电气单片机实验程序.docx
- 文档编号:27146527
- 上传时间:2023-06-27
- 格式:DOCX
- 页数:26
- 大小:20.70KB
扬大电气单片机实验程序.docx
《扬大电气单片机实验程序.docx》由会员分享,可在线阅读,更多相关《扬大电气单片机实验程序.docx(26页珍藏版)》请在冰豆网上搜索。
扬大电气单片机实验程序
3.1Keil集成开发环境熟悉及汇实验编程序
MOV31H,A
1.
3.
MOV20H,#98H
MAIN:
MOVA,20H
MOV30H,#2
MOVB,#100
MOV31H,#3
DIVAB
MOV3AH,#4
MOV30h,A
MOV43H,#3
XCHA,B
MOVR0,#30H
MOVB,#10
MOVR7,#10
DIVAB
MOVA,#00H
MOV31H,A
LOOP:
MOV@R0,A
MOV32H,B
INCR0
RET
DJNZR7,LOOP
END
RET
2.
END
MOV20H,#78H4.
MOVA,20H
MAIN:
ANLA,#0FH
MOV30H,#3
ADDA,#30H
MOV31H,#5
MOV30H,A
MOV3FH,#6
MOVA,20H
MOVR0,#30H
ANLA,#0F0H
MOVR1,#40H
SWAPA
MOVR7,#16
ADDA,#30H
NOP
LOOP:
MOVA,@R0
MOV@R1,A
INCR0
INCR1
DJNZR7,LOOP
RET
END
并行I/O接口实验
1.ORG0000H
AJMPMAIN
ORG0100H
MAIN:
MOVA,#0FEH
LIGHT:
MOVP1,A
RRA
MOVP1,A
ACALLDELAY
AJMPLIGHT
DELAY:
MOVR7,#250
DELAY1:
MOVR6,#250
DELAY2:
DJNZR6,DELAY2
DJNZR7,DELAY1
RET
END
2.ORG0000H
AJMPMAIN
ORG0100H
MAIN:
SETBP1.0
SETBP1.1
LOOP:
MOVC,P1.0
MOVP1.2,C
MOVC,P1.1
MOVP1.3,C
AJMPLOOP
SJMP$
END
3.ORG0000H
AJMPMAIN
ORG0100H
MAIN:
SETBP1.7
DJNZR4,T164
DEL:
MOV
R5,#04H
DEL1:
MOV
R6,#0FFH
DEL2:
MOV
R7,#0FFH
DEL3:
DJNZ
R7,DEL3
DJNZ
R6,DEL2
DJNZ
R5,DEL1
END
LCALLT164
SJMPMAIN
T164:
RLCA
MOVP3.3,C
MOVP3.4,C
SETBP3.2
CLRP3.2
LCALLDEL
LOOP:
MOVC,P1.7
MOVP1.1,C
MOVP1.0,C
AJMPLOOP
SJMP$
END
3.3点阵式LED显示实验2.
1.
ORG
0
ORG
0000H
SJMP
MAIN
LJMP
MAIN
ORG
30H
ORG
0030H
MAIN:
MAIN:
MOVA,#0FEHMOVR1,#10
MOVR4,#8
X:
MOVDPTR,#TABX
MOVB,#0FEH;B寄存器作列值变换
CLRC
MOVR2,#8;R2作列循环计数
LCALLLOOP
DJNZR2,LOOP
DJNZR1,X
SJMPMAIN
DJNZR4,T164
LOOP:
MOVA,#0
MOVP1,#0FFH
MOVR4,#8;R4作行串并转换计数;行值设置
MOVCA,@A+DPTR
INCDPTR
LCALLT164
;列值设置
MOVP1,B
MOVA,B
RLA
MOVB,A
;延时
LCALLDEL
RET
SJMPMAIN
;串并转换程序
T164:
RLCA
MOVP3.3,C
MOVP3.4,C
SETBP3.2
RET
;延时子程序
DEL:
MOVR5,#20
DEL1:
MOVR6,#125
DEL2:
DJNZR6,DEL2
DJNZR5,DEL1
RET
TABX:
DB
7EH,0BDH,0DBH,0E7H,0E7H,0DBH,0BDH,7EH
TABT:
DB
0FCH,0FCH,0FCH,00H,00H,0FCH,0FCH,0FCH
TABL:
DB00H,00H,3FH,3FH,3FH,3FH,3FH,3FH
TABE:
DB00H,00H,24H,24H,24H,24H,24H,24H
3.4I2C总线和8段LED显示实验
1.
内容1,显示12345678
・***************************************************
J
*********************
;定义器件地址及存放单元
ZLG7290EQU70H;ZLG7290的器件地址
SLADATA63H;器件的从地址
CLRP3.2
SUBADATA64H;器件的子地址
MOVA,#1FH;将熄灭码依次填入显缓区
MOVR2,#8
;定义变量单元
ACKBIT10H;应答标志位
NUMBYTEDATA62H;读/写的字节数变量
MTDEQU6EH;发送数据缓冲器
DISBUFEQU66H;66H~6DH为显示缓冲区,
66H对应最右一位
;以上定义一般不要改动
;I2C引脚定义
SDABITP3.0
SCLBITP3.1
RSTBITP3.6
・***************************************************
J
*********************
MLOOP:
MOV@R0,A
INCR0
DJNZR2,MLOOP
CC:
MOVR0,#DISBUF
MOVR3,#08H
MOVA,#08H
AA:
MOV@R0,A
INCR0
DECA
DJNZR3,AA
LCALLLEDDISP;调用显示程序
LCALLDELAY;延时
SJMPCC
ORG
0000H
$INCLUDE(LEDDISP_ASM.INC)
;包含LED显示模
LJMP
MAIN
块程序
ORG
0030H
END
MAIN:
2.
MOV
SP,#70H;设堆栈,建议堆栈设在此处
ZLG7290EQU
70H
SLADATA63H
LCALL
RE7290;复位RE7290
SUBADATA64H
MOV
R0,#DISBUF;显缓区首地址(66H)
ACK
BIT
10H
NUMBYTEDATA62H
MTD
EQU
6EH
DISBUF
EQU
66H
SDA
BIT
P3.0
SCL
BIT
P3.1
RST
BIT
P3.6
ORG
0000H
LJMP
MAIN
ORG
0030H
MAIN:
MOV
SP,#70H
LCALL
RE7290
MOV
R0,#DISBUF
MOV
A,#1FH
MOV
R2,#8
MLOOP:
MOV
@R0,A
INC
R0
DJNZ
R2,MLOOP
AA:
MOV
R0,#DISBUF
MOVA,P1
MOVB,#64H
DIVAB
MOV@R0,A
INCR0
MOVA,B
MOVB,#10
DIVAB
MOV@R0,A
INCR0
MOVA,B
MOV@R0,A
LCALLLEDDISP
LCALLDELAY
SJMPAA
$INCLUDE(LEDDISP_ASM.INC)
END
3.5中断实验
1.
ORG0
LJMPMAIN
ORG0003H
LJMPINT00
ORG30H
MAIN:
SETBEA
SETBEX0
SETBIT0
SETBP1.0
HERE:
JMPHERE
INT00:
CPLP1.0
RETI
END
2.
ORG
0000H
LJMP
MAIN
ORG
0003H
LJMP
INTT0
ORG
0100H
MAIN:
SETB
EX0
SETB
IT0
SETB
EA
MOV
R1,#0
MOV
A,#0FCH
//点亮最低位
应送值
CL:
MOV
R4,#8
//移位7次
DL:
MOV
R5,#10
//50MS*10
MOV
P1,A
CHULI:
CJNE
R1,#0,CHULI1
//R1为0,左移一
RL
A
CHULI1:
CJNE
R1,#1,CHULI2
//R1为1,右移一
位循环点亮
RR
A
CHULI2:
CJNE
R1,#2,CHULI3
//R1为2,左移两
位循环点亮
RL
A
RL
A
CHULI3:
CJNE
R1,#3,DELAY
//R1为3,右
移两位循环点亮
RR
A
RR
A
DELAY:
LCALL
DEL
DJNZ
R5,DELAY
//每一次调用DEL延
时50ms,调用R5次
DJNZ
R4,DL//每轮位移R4次
LJMP
CL//一轮结束,从头再来,主
要从新赋值R4
DEL:
MOV
R6,#200//较精确50ms延
时
DEL1:
MOV
R7,#123
NOP
位循环点亮
DEL2:
DJNZR7,DEL2
ADDA,#1
DJNZR6,DEL1
RET
INTT0:
INCR1
CJNER1,#4,FANHUI
MOVR1,#0
FANHUI:
RETI
END
3.
ORG0
LJMPMAIN
ORG0003H
LJMPINTOO
ORG30H
MAIN:
SETBEA
SETBEX0
SETBIT0
SETBP1.0
MOV30H,#0
ORG50H
HERE:
JMPHERE
MOV30H,A
MOVA,31H
ADDCA,#0
MOV31H,A
MOVA,30H
CPLA
MOVP1,A
RETI
END
3.6定时/计数器实验
1.
;调用LED显示的示例程序:
将按键连到T0引脚,程序对按键次数计数并显示。
・***************************************************
J
*********************
;定义器件地址及存放单元
ZLG7290EQU70H;ZLG7290的器件地址
SLADATA63H;器件的从地址
SUBADATA64H;器件的子地址
;定义变量单元
ACKBIT10H;应答标志位
INTOO:
MOVA,30H
NUMBYTEDATA62H
;读/写的字节数变量
LJMP
MAIN
ORG0100H
MAIN:
MOV
SP,#70H
;设堆栈,建议堆栈设在此处
LCALL
RE7290
;复位RE7290
MOV
R0,#DISBUF;
显缓区首地址(66H)
MOV
A,#1FH
;将熄灭码依次填入显缓区
MOV
R2,#8
MOV
66H,B
MOVB,#100
MTDEQU6EH;发送数据缓冲器
DISBUFEQU66H;66H~6DH为显示缓冲区,
66H对应最右一位
;以上定义一般不要改动
;I2C引脚定义
SDABITP3.0
SCLBITP3.1
RSTBITP3.6
・***************************************************
J
*********************
ORG0000H
MLOOP:
MOV@R0,A
INCR0
MOVA,TH0
DIVAB
MOV6BH,A
MOVA,B
MOVB,#10
DIVAB
MOV6AH,A
MOV69H,B
LCALLLEDDISP
LCALLDELAY
LJMPPLAY
$INCLUDE(LEDDISP_ASM.INC)
END
2.
ORG0000H
LJMPMAIN
ORG000BH
LJMPIT0P
ORG0100H
MAIN:
MOVSP,#60H;设堆栈指针
MOVB,#20
;设循环次数20次
MOVTMOD,#01H
MOVTL0,#0B0H
MOVTH0,#3CH
SETBTR0
SETBET0
SETBEA
HERE:
SJMPHERE
;原地循环,等待中
断
IT0P:
MOVTL0,#0B0H
;重装初值
MOVTH0,#3CH
DJNZB,LOOP
MOVB,#20
CPLP1.0
LOOP:
RETI
;返回“SJMPHERE”
处
END
3.
ORG0000H
LJMPMAIN
ORG000BH
LJMPIT0P
ORG001BH
MOVCA,@A+DPTR
MOVP1,A
MOVC,TF0;IT0溢出置1
JCDE
LCALLDEL
INCDPTR
DJNZR1,LOOP1
AJMPLOOP
DE:
DECR0
RETI
SETBPT1
CLRPT0
MOVR0,#3;0~3,选择显示的效果4种
MOVR1,#8;走马灯
MOVB,#10;显示延迟所需的循环次数
10词
HERE:
AJMPHERE
IT0P:
CJNER0,#0FFH,T
MOVR0,#3
T:
CJNER0,#3,T2
MOVDPTR,#TAB1
IT1P:
MOVTL1,#0B0H
;延时
ORG0100H
MOVTH1,#3CH
DJNZB,LOP
MAIN:
MOVSP,#60H
MOVB,#10
MOV
R0,#30H
CLRTR1
MOV
30H,#30H
LOP:
RETI;返回“IT1P”处
MOV
31H,#31H
DEL:
SETBTR1
MOV
32H,#32H
ZIJI:
JBTR1,ZIJI
MOV
33H,#33H
RET
MOV
34H,#34H
TAB1:
DB
MOV
35H,#35H
0FEH,0FDH,0FBH,0F7H,0EFH,0DFH,0BFH,7FH
MOV
36H,#36H
TAB2:
DB
MOV
37H,#37H
7FH,0BFH,0DFH,0EFH,0F7H,0FBH,0FDH,0FEH
MOV
TMOD,#20H
TAB3:
DB
MOV
TL1,#0FAH
7FH,0FEH,0BFH,0FDH,0DFH,0FBH,0EFH,0F7H
MOV
TH1,#0FAH
TAB4:
DB
MOV
SCON,#50H
7EH,0BDH,0DBH,0E7H,0DBH,0BDH,7EH,0FFH
SETBTR1
END
SETBES
3.7串行通信实验
SETBEA
1.发送
MOV
R1,#8
ORG0000H
MOV
SBUF,@R0
AJMPMAIN
SJMP$
ORG0023H
SINT:
CLRTI
AJMPSINT
DJNZR1,LP
SINTR:
sjmpti_end
lp:
INCR0
CLRRI
MOVSBUF,@R0
MOVA,SBUF
ti_end:
RETI
MOV@R0,A
END
INCR0
接受
RETI
ORG0000H
END
AJMPMAIN
2.发送
ORG0023H
ORG
0000H
AJMPSINTR
LJMP
MAIN
ORG0100H
ORG
0100H
MAIN:
MAIN:
MOVSCON,#40H
MOVSP,#60H
MOV
TMOD,#20H
MOVR0,#40H
MOV
TH1,#0FDH
MOVTMOD,#20H
MOV
TL1,#0FDH
MOVTH1,#0FAH
SETB
TR1
MOVTL1,#0FAHTRANSLATE:
MOVA,P1
MOVSCON,#50H
MOVSBUF,A
SETBTR1
WAIT:
JBCTI,NEXT
SETBEA
SJMPWAIT
SETBES
NEXT:
SJMPTRANSLATE
SJMP$
ORG0150HEND
接受
ORG
0100H
ORG
0000H
LJMP
MAIN
ORG
0100H
MAIN:
MOVSCON,#50H
MOV
TMOD,#20H
MOV
TH1,#0FDH
MOV
TL1,#0FDH
SETB
TR1
MAIN:
SETBIT0
SETB
EA
SETB
EX0
MOV
DPTR,#7FFCH
MOV
A,#00H
MOVX
@DPTR,A
SJMP
$
RECEIVE:
JBCRI,NEXT
SJMPRECEIVE
NEXT:
MOVA,SBUF
MOVP1,A
SJMPRECEIVE
END
3.8A/D转换实验
1.
ORG0000H
LJMPMAIN
ORG0003H
LJMPQAZ
QAZ:
MOVDPTR,#7FFCH
MOVXA,@DPTR
MOVP1,#0FFH
MOVP1,A
MOVA,#00H
MOVX@DPTR,A
RETI
END
2.
ZLG7290EQU70H;ZLG7290的器件
地址
SLADATA63H;器件的从地址
SUBADATA64H;器件的子地址
;定义变量单元
ACKBIT10H
;应答标志位
NUMBYTEDATA62H
;读/写的字节数变
MOVTL0,#00H
量
SETBIT0MTDEQU6EH;发送数据缓冲器
SETBEX0DISBUFEQU66H;66H~6DH为显示缓
SETBET0冲区,66H对应最右一位
SETBEA
;以上定义一般不要改动SETBTR0
;I2C引脚定义
SDABITP1.7
SCLBITP1.6
RSTBITP1.0
・***********************************************
J
*************************
ORG0000H
LJMPMAIN
ORG0003H
LJMPQAZ
ORG000BH
LJMPTIMER00
ORG0100H
MAIN:
MOVTMOD,#01H//T1,方
式1
MOVTH0,#4CH//50ms
MOVDPTR,#7FFCH
MOVA,#00H
MOVX@DPTR,A
AA:
MOV6DH,R2
MOV6CH,R3//最左边显示两位十六进制数
MOV68H,R4
MOV67H,R5
MOV66H,R6//最右边显示三位十进制数
LCALLLEDDISP
LCALLDELAY
SJMPAA
TIMER00:
MOVTH0,#4CH
MOVTL0,#00H
INCR0
//2*50=100MSMOVR5,A//十进制十位放在R5中
CJNE
R0,#1,EXITMOVR6,B//十进制个位放在R6中
MOV
R0,#0RETI
MOV
DPTR,#7FFCH$INCLUDE(LEDDISP_ASM.INC);包含LED显
MOV
A,#00H示模块程序
MOVX
@DPTR,AEND
EXIT:
RETI
QAZ:
MOVDPTR,#7FFCH
MOVX
A,@DPTR
MOV
P1,A
MOV
R1,A//暂存A
MOV
B,#16
DIVAB
MOV
R2,A//十六进制高位放在R2中
MOV
R3,B//十六进制低位放在R3中
MOV
A,R1
MOV
B,#100
DIVAB
MOV
R4,A//十进制百位放在R4中
MOV
A,B
MOV
B,#10
DIVAB
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 电气 单片机 实验 程序
![提示](https://static.bdocx.com/images/bang_tan.gif)