单片机并口简单应用(流水灯、数码管)实验报告6-1
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
实验一单片机并口简单应用(流水灯、数码管)
实验目的
1、了解简单单片机应用系统的设计方法。
2、了解单片机汇编语言程序的基本结构
3、了解单片机汇编语言程序的设计和调试方法
4、掌握应用PROTEUS仿真软件的操作方法。
5、掌握应用KEIL软件编辑、编译源汇编程序的操作方法。
6、培养良好的实验习惯。
实验内容
1、AT89S51为主控芯片,用PROTEUS仿真设计简单单片机应用系统。
2、编程实现8个发光LED“流水”的现象,用一个按键控制灯的上、下、开
花三种状态,先用查询。
3、用四个数码管开始现实185,做二个按键,加5,减4,最多加到210,
最多减到150。
发辉部分:修改程序,用中断完成以上功能,用六位数码管显示学号后
六位。
实验原理
1、流水灯
(1)实验原理图(可打印)
(2)实验程序(必须手写)
流水灯中断
ORG 0000H
AJMP MAIN
ORG 0003H
AJMP KEY
MAIN:CALL INIT
LOOP:CALL MOVE
CALL DELAY
AJMP LOOP
INIT:MOV R3,#0FEH
MOV R4,#0
MOV P2,#0FFH
MOV R0,#00H
SETB IT0
SETB EX0
SETB EA
RET
MOVE:CJNE R0,#00H,MOV2 MOV A,R3
RL A
MOV R3,A
MOV P2,R3
MOV2:CJNE R0,#01H,MOV3 MOV A,R3
RR A
MOV R3,A
MOV P2,R3
MOV3:CJNE R0,#02H,LEND MOV DPTR,#TAB
MOV R7,#0
MOV R6,#4
LOP: MOV A,R7
MOVC A,@A+DPTR
MOV P2,A
LCALL DELAY
INC R7
DJNZ R6,LOP LEND: RET
KEY: PUSH PSW
PUSH ACC
MOV A,R0
INC A
CJNE A,#03H,HU1
MOV A,#00H
HU1: MOV R0,A
POP ACC
POP PSW
RETI
DELAY:MOV R2,#150
DE1: MOV R5,#200
DJNZ R5,$
DJNZ R2,DE1
RET
TAB: DB 0e7H,0dbH,0bdH,07eH END
;OK
查询
ORG 0000H
AJMP START
START:
MOV R3,#0FEH
MOV R4,#0
MOV P2,#0FFH
MOV R0,#00H
MAIN:
CALL DET
CALL MOVE
AJMP MAIN
DET:
JB P3.2,DEND
JNB P3.2,$
MOV A,R0
INC A
MOV R0,A
CJNE A,#03H,DEND
MOV R0,#00H
DEND:RET
MOVE:CJNE R0,#00H,MOV2
MOV A,R3
RL A
MOV R3,A
MOV P2,R3
MOV2:CJNE R0,#01H,MOV3
MOV A,R3
RR A
MOV R3,A
MOV P2,R3
MOV3:CJNE R0,#02H,LEND
MOV DPTR,#TAB
MOV R7,#0
MOV R6,#4
LOP: MOV A,R7
MOVC A,@A+DPTR
MOV P2,A
LCALL DELAY
INC R7
DJNZ R6,LOP
LEND: RET
DELAY: MOV R4,#250
DE1: MOV R5,#200
DJNZ R5,$
DJNZ R4,DE1
RET
TAB: DB 0e7H,0dbH,0bdH,07eH END
;OK
2、数码管显示
(1)实验原理图(可打印)
(2)实验程序(可打印)
(3)数码管查询
(4) ORG 0000H
(5) AJMP MAIN
(6)
(7) MAIN:
(8)MOV R2,#000
(9)MOV R3,#185
(10)
(11)MANAGE:
(12)LCALL COMPUTING
(13)LCALL BCD
(14)LCALL DISPLAY
(15)AJMP MANAGE
(16)
(17)
(18)COMPUTING:
(19)JB P3.1,SU
(20)JNB P3.1,$
(21)INC R3
(22)INC R3
(23)INC R3
(24)INC R3
(25)INC R3
(26)CJNE R3,#210,PD1
(27)PD1: JC LEND
(28)MOV R3,#210
(29)SU: JB P3.2,LEND
(30)JNB P3.2,$
(31)DEC R3
(32)DEC R3
(33)DEC R3
(34)DEC R3
(35)CJNE R3,#150,PD2 (36)PD2: JNC LEND (37)MOV R3,#150 (38)LEND:RET
(39)
(40)
(41)BCD:
(42)MOV A,R2
(43)MOV B,#100 (44)DIV AB
(45)MOV 30H,A
(46)MOV A,B
(47)MOV B,#10
(48)DIV AB
(49)MOV 31H,A
(50)MOV 32H,B
(51)
(52)MOV A,R3
(53)MOV B,#100 (54)DIV AB
(55)MOV 33H,A
(56)MOV A,B
(57)MOV B,#10
(58)DIV AB
(59)MOV 34H,A
(60)MOV 35H,B
(61)
(62)DISPLAY:
(63)MOV R7,#7
(64)MOV R0,#30H (65)MOV DPTR,#TAB (66)MOV R6,#0FEH (67)LOOP:
(68)MOV A,@R0
(69)MOVC A,@A+DPTR (70)MOV P1,R6
(71)MOV P2,A
(72)LCALL DELAY (73)MOV A,R6
(74)RR A
(75)MOV R6,A
(76)LCALL DELAY
(77)INC R0
(78)DJNZ R7,LOOP
(79)RET
(80)
(81)DELAY:
(82)MOV R5,#50
(83)DE1:MOV R4,#10
(84)DJNZ R4,$
(85)DJNZ R5,DE1
(86)RET
(87)
(88)
(89)TAB: DB 0C0H,0F9H,0A4H,0B0H,099H,092H,082H,0F8H,080H,090H (90)
(91)END
(92)
(93);OK
(94)
(95)中断
(96) ORG 0000H
(97) AJMP MAIN
(98) ORG 0003H
(99) AJMP KEY
(100) ORG 0013H
(101) AJMP KEY2
(102)
(103)MAIN:
(104)LCALL INIT
(105)MOV R2,#000
(106)MOV R3,#185
(107)
(108)MANAGE:
(109)LCALL BCD
(110)LCALL DISPLAY
(111)AJMP MANAGE
(112)
(113)INIT:
(114) SETB IT0
(115) SETB IT1
(116) SETB EX0
(117) SETB EX1
(118) SETB EA
(119) RET
(120)
(121)KEY: MOV A,R3 (122)ADD A,#5 (123)MOV R3,A (124)CJNE R3,#210,M1 (125)M1: JC KEND
(126)MOV R3,#210 (127)AJMP KEND (128)KEY2: MOV A,R3 (129)SUBB A,#4 (130)MOV R3,A (131)CJNE R3,#150,M2 (132)M2: JNC KEND (133)MOV R3,#150 (134)KEND: RETI
(135)
(136)
(137)BCD:
(138)MOV A,R2
(139)MOV B,#100
(140)DIV AB
(141)MOV 30H,A
(142)MOV A,B
(143)MOV B,#10
(144)DIV AB
(145)MOV 31H,A
(146)MOV 32H,B
(147)
(148)MOV A,R3
(149)MOV B,#100
(150)DIV AB
(151)MOV 33H,A
(152)MOV A,B
(153)MOV B,#10
(154)DIV AB
(155)MOV 34H,A
(156)MOV 35H,B
(157)
(158)DISPLAY:
(159)MOV R7,#7
(160)MOV R0,#30H (161)MOV DPTR,#TAB (162)MOV R6,#0FEH (163)LOOP:
(164)MOV A,@R0
(165)MOVC A,@A+DPTR
(166)MOV P1,R6
(167)MOV P2,A
(168)LCALL DELAY
(169)MOV A,R6
(170)RR A
(171)MOV R6,A
(172)LCALL DELAY
(173)INC R0
(174)DJNZ R7,LOOP
(175)RET
(176)
(177)DELAY:
(178)MOV R5,#50
(179)DE1:MOV R4,#10
(180)DJNZ R4,$
(181)DJNZ R5,DE1
(182)RET
(183)
(184)
(185)TAB: DB
0C0H,0F9H,0A4H,0B0H,099H,092H,082H,0F8H,080H,090H (186)
(187)END
(188)
(189);OK
3、显示学号后六位
(1)实验原理图(可打印)
(2)实验程序(可打印)
学号
ORG 0000H
AJMP MAIN
MAIN:
MOV R2,#071
MOV R3,#082
MANAGE:
LCALL BCD
LCALL DISPLAY
AJMP MANAGE
BCD:
MOV A,R2
MOV B,#100
DIV AB
MOV 30H,A
MOV A,B
MOV B,#10
DIV AB
MOV 31H,A
MOV 32H,B
MOV A,R3
MOV B,#100
DIV AB
MOV 33H,A
MOV A,B
MOV B,#10
DIV AB
MOV 34H,A
MOV 35H,B
DISPLAY:
MOV R7,#7
MOV R0,#30H
MOV DPTR,#TAB
MOV R6,#0FEH
LOOP:
MOV A,@R0
MOVC A,@A+DPTR
MOV P1,R6
MOV P2,A
LCALL DELAY
MOV A,R6
RR A
MOV R6,A
LCALL DELAY
INC R0
DJNZ R7,LOOP
RET
DELAY:
MOV R5,#50
DE1:MOV R4,#10
DJNZ R4,$
DJNZ R5,DE1
RET
TAB: DB 0C0H,0F9H,0A4H,0B0H,099H,092H,082H,0F8H,080H,090H END
实验总结
1、实验中出现的问题,如何解决
2、心得体会。