首页 行业资讯 宠物日常 宠物养护 宠物健康 宠物故事

Tr9x5(P2.5)-7E

发布网友 发布时间:2022-04-26 21:50

我来回答

1个回答

热心网友 时间:2023-11-07 07:27

汇编可以么

LED_1 EQU 30H
LED_2 EQU 31H
LED_3 EQU 32H
LED_4 EQU 33H
LED_5 EQU 34H
LED_6 EQU 35H
LED_7 EQU 36H
LED_8 EQU 37H
TIMER EQU 38H
MODE EQU 39H;模式判断
FLASH EQU 40H;闪烁判断 1亮 0不亮
BUTTON1 EQU 41H;按钮开关
BUTTON2 EQU 42H;按钮开关
BUTTON3 EQU 43H;按钮开关
BUTTON4 EQU 44H;按钮灵敏
CS1 EQU P2.0
CS2 EQU P2.1
WR_ON EQU P2.2
;-------------------------------
; 按钮
;-------------------------------
IN_SET EQU P2.3
IN_GAL EQU P2.4
IN_SUB EQU P2.5
;-------------------------------
; 主程序
;接口:D0-D7 接 P1.0-P1.7
; CS1 P2.0 CS2 P2.1 WR P2.2
;-------------------------------
ORG 0000H
JMP MAIN
ORG 000BH
JMP T0INT
ORG 0030H
MAIN:
CALL SYSINIT
;-------------------------------
START:
JMP START
;-------------------------------
; 计时器子程序
;-------------------------------
T0INT:
MOV TH0,#03CH
MOV TL0,#0AFH
CALL SHOW
DJNZ BUTTON4,T0INT1
MOV BUTTON4,#10
CALL AJ1
CALL AJ3
CALL AJ5
T0INT1:
DJNZ TIMER,T0INTEND
CALL MODE_PD1
T0INTEND:
RETI
;-------------------------------
; 模式判断
;-------------------------------
MODE_PD1:
MOV A,MODE
CJNE A,#0,MODE_PD2
MOV TIMER,#200
CALL CADD
JMP MODE_PDEND
MODE_PD2:
MOV A,MODE
CJNE A,#1,MODE_PD3
MOV TIMER,#50
CALL FLASH1
JMP MODE_PDEND
MODE_PD3:
MOV A,MODE
CJNE A,#2,MODE_PD4
MOV TIMER,#50
CALL FLASH3
JMP MODE_PDEND
MODE_PD4:
MOV A,MODE
CJNE A,#3,MODE_PDEND
MOV TIMER,#50
CALL FLASH5
MODE_PDEND:
RET
;-------------------------------
; 按钮
;-------------------------------
AJ1:
MOV A,BUTTON1
CJNE A,#1,AJ2
JB IN_SET,AJEND
MOV BUTTON1,#0
CALL SAVE2
MOV TIMER,#1
INC MODE
MOV A,MODE
CJNE A,#4,AJEND
MOV MODE,#0
MOV TIMER,#100
JMP AJEND
AJ2:
MOV A,BUTTON1
CJNE A,#0,AJ1
JNB IN_SET,AJEND
MOV BUTTON1,#1
JMP AJEND
AJ3:
MOV A,BUTTON2
CJNE A,#1,AJ4
JB IN_GAL,AJEND
MOV BUTTON2,#0
CALL GAL1
JMP AJEND
AJ4:
MOV A,BUTTON2
CJNE A,#0,AJ3
JNB IN_GAL,AJEND
MOV BUTTON2,#1
JMP AJEND
AJ5:
MOV A,BUTTON3
CJNE A,#1,AJ6
JB IN_SUB,AJEND
MOV BUTTON3,#0
CALL SUB1
JMP AJEND
AJ6:
MOV A,BUTTON3
CJNE A,#0,AJ5
JNB IN_SUB,AJEND
MOV BUTTON3,#1
JMP AJEND
AJEND:
RET
;-------------------------------
; 加法
;-------------------------------
GAL1:
MOV A,MODE
CJNE A,#3,GAL2
INC 58H
MOV A,58H
CJNE A,#10,GALEND
MOV 58H,#0
INC 57H
MOV A,57H
CJNE A,#6,GALEND
MOV 57H,#0
GAL2:
MOV A,MODE
CJNE A,#2,GAL3
INC 55H
MOV A,55H
CJNE A,#10,GALEND
MOV 55H,#0
INC 54H
MOV A,54H
CJNE A,#6,GALEND
MOV 54H,#0
GAL3:
MOV A,MODE
CJNE A,#1,GALEND
INC 52H
MOV A,52H
CJNE A,#10,GAL32
MOV 52H,#0
INC 51H
GAL32:
CJNE A,#4,GALEND
MOV A,51H
CJNE A,#2,GALEND
MOV 52H,#0
MOV 51H,#0
GALEND:
CALL SAVE2
RET
;-------------------------------
; 减法
;-------------------------------
SUB1:
MOV A,MODE
CJNE A,#3,SUB2
DEC 58H
MOV A,58H
CJNE A,#-1,SUBEND
MOV 58H,#9
DEC 57H
MOV A,57H
CJNE A,#-1,SUBEND
MOV 57H,#5
SUB2:
MOV A,MODE
CJNE A,#2,SUB3
DEC 55H
MOV A,55H
CJNE A,#-1,SUBEND
MOV 55H,#9
DEC 54H
MOV A,54H
CJNE A,#-1,SUBEND
MOV 54H,#5
SUB3:
MOV A,MODE
CJNE A,#1,SUBEND
DEC 52H
MOV A,52H
CJNE A,#-1,SUBEND
MOV 52H,#9
DEC 51H
MOV A,51H
CJNE A,#-1,GALEND
MOV 52H,#3
MOV 51H,#2
SUBEND:
CALL SAVE2
RET
;-------------------------------
; 闪烁
;-------------------------------
FLASH1:
MOV A,FLASH
CJNE A,#0,FLASH2
MOV 51H,LED_1
MOV 52H,LED_2
MOV LED_1,#11
MOV LED_2,#11
MOV FLASH,#1
JMP FLASHEND
FLASH2:
MOV A,FLASH
CJNE A,#1,FLASHEND
MOV LED_1,51H
MOV LED_2,52H
MOV FLASH,#0
JMP FLASHEND;小时闪烁
FLASH3:
MOV A,FLASH
CJNE A,#0,FLASH4
MOV 54H,LED_4
MOV 55H,LED_5
MOV LED_4,#11
MOV LED_5,#11
MOV FLASH,#1
JMP FLASHEND
FLASH4:
MOV A,FLASH
CJNE A,#1,FLASHEND
MOV LED_4,54H
MOV LED_5,55H
MOV FLASH,#0
JMP FLASHEND;分钟闪烁
FLASH5:
MOV A,FLASH
CJNE A,#0,FLASH6
MOV 57H,LED_7
MOV 58H,LED_8
MOV LED_7,#11
MOV LED_8,#11
MOV FLASH,#1
JMP FLASHEND
FLASH6:
MOV A,FLASH
CJNE A,#1,FLASHEND
MOV LED_7,57H
MOV LED_8,58H
MOV FLASH,#0;秒钟闪烁
FLASHEND:
RET
;-------------------------------
; 数据加减
;-------------------------------
CADD:
INC LED_8
MOV A,LED_8
CJNE A,#10,CADDEND
MOV LED_8,#0
INC LED_7
MOV A,LED_7
CJNE A,#6,CADDEND
MOV LED_7,#0
INC LED_5
MOV A,LED_5
CJNE A,#10,CADDEND
MOV LED_5,#0
INC LED_4
MOV A,LED_4
CJNE A,#6,CADDEND
MOV LED_4,#0
INC LED_2
MOV A,LED_2
CJNE A,#10,CADD2
MOV LED_2,#0
INC LED_1
CADD2:
CJNE A,#4,CADDEND
MOV A,LED_1
CJNE A,#2,CADDEND
CALL SYSINIT
CADDEND:
CALL SAVE1
RET
;-------------------------------
; 数据显示
;-------------------------------
SHOW:
MOV R0,#30H
MOV R1,#8
MOV R2,#B
SHOW1:
MOV A,R2
MOV P0,A
CALL CS2_ON
RR A
MOV R2,A
MOV A,@R0
MOVC A,@A+DPTR
MOV P0,A
CALL CS1_ON
CALL DELAY
MOV P0,#0FFH
CALL CS1_ON
CALL CS2_ON
INC R0
DJNZ R1,SHOW1
RET
CS1_ON:
CLR WR_ON
CLR CS1
SETB WR_ON
SETB CS1
RET
CS2_ON:
CLR WR_ON
CLR CS2
SETB WR_ON
SETB CS2
RET
;-------------------------------
; 数据储存
;-------------------------------
SAVE1:
MOV 51H,LED_1
MOV 52H,LED_2
MOV 54H,LED_4
MOV 55H,LED_5
MOV 57H,LED_7
MOV 58H,LED_8
RET
SAVE2:
MOV LED_1,51H
MOV LED_2,52H
MOV LED_4,54H
MOV LED_5,55H
MOV LED_7,57H
MOV LED_8,58H
RET
;-------------------------------
; 数据初始化
;-------------------------------
SYSINIT:
MOV LED_1,#0
MOV LED_2,#0
MOV LED_3,#10
MOV LED_4,#0
MOV LED_5,#0
MOV LED_6,#10
MOV LED_7,#0
MOV LED_8,#0
CALL SAVE1
MOV TIMER,#200
MOV MODE,#0
MOV FLASH,#0
MOV BUTTON1,#1
MOV BUTTON2,#1
MOV BUTTON3,#1
MOV BUTTON4,#3
MOV TH0,#03CH
MOV TL0,#0AFH
SETB TR0
SETB ET0
SETB EA
MOV DPTR,#TAB
RET
;-------------------------------
; 延迟
;-------------------------------
DELAY:
MOV R6,#255
DJNZ R6,$
RET
;-------------------------------
; 段码
;-------------------------------
TAB:
DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0BFH,0FFH
;0- "0"
;1- "1"
;2- "2"
;
;9- "9"
;10-"-"
;11-" "
END

热心网友 时间:2023-11-07 07:27

汇编可以么

LED_1 EQU 30H
LED_2 EQU 31H
LED_3 EQU 32H
LED_4 EQU 33H
LED_5 EQU 34H
LED_6 EQU 35H
LED_7 EQU 36H
LED_8 EQU 37H
TIMER EQU 38H
MODE EQU 39H;模式判断
FLASH EQU 40H;闪烁判断 1亮 0不亮
BUTTON1 EQU 41H;按钮开关
BUTTON2 EQU 42H;按钮开关
BUTTON3 EQU 43H;按钮开关
BUTTON4 EQU 44H;按钮灵敏
CS1 EQU P2.0
CS2 EQU P2.1
WR_ON EQU P2.2
;-------------------------------
; 按钮
;-------------------------------
IN_SET EQU P2.3
IN_GAL EQU P2.4
IN_SUB EQU P2.5
;-------------------------------
; 主程序
;接口:D0-D7 接 P1.0-P1.7
; CS1 P2.0 CS2 P2.1 WR P2.2
;-------------------------------
ORG 0000H
JMP MAIN
ORG 000BH
JMP T0INT
ORG 0030H
MAIN:
CALL SYSINIT
;-------------------------------
START:
JMP START
;-------------------------------
; 计时器子程序
;-------------------------------
T0INT:
MOV TH0,#03CH
MOV TL0,#0AFH
CALL SHOW
DJNZ BUTTON4,T0INT1
MOV BUTTON4,#10
CALL AJ1
CALL AJ3
CALL AJ5
T0INT1:
DJNZ TIMER,T0INTEND
CALL MODE_PD1
T0INTEND:
RETI
;-------------------------------
; 模式判断
;-------------------------------
MODE_PD1:
MOV A,MODE
CJNE A,#0,MODE_PD2
MOV TIMER,#200
CALL CADD
JMP MODE_PDEND
MODE_PD2:
MOV A,MODE
CJNE A,#1,MODE_PD3
MOV TIMER,#50
CALL FLASH1
JMP MODE_PDEND
MODE_PD3:
MOV A,MODE
CJNE A,#2,MODE_PD4
MOV TIMER,#50
CALL FLASH3
JMP MODE_PDEND
MODE_PD4:
MOV A,MODE
CJNE A,#3,MODE_PDEND
MOV TIMER,#50
CALL FLASH5
MODE_PDEND:
RET
;-------------------------------
; 按钮
;-------------------------------
AJ1:
MOV A,BUTTON1
CJNE A,#1,AJ2
JB IN_SET,AJEND
MOV BUTTON1,#0
CALL SAVE2
MOV TIMER,#1
INC MODE
MOV A,MODE
CJNE A,#4,AJEND
MOV MODE,#0
MOV TIMER,#100
JMP AJEND
AJ2:
MOV A,BUTTON1
CJNE A,#0,AJ1
JNB IN_SET,AJEND
MOV BUTTON1,#1
JMP AJEND
AJ3:
MOV A,BUTTON2
CJNE A,#1,AJ4
JB IN_GAL,AJEND
MOV BUTTON2,#0
CALL GAL1
JMP AJEND
AJ4:
MOV A,BUTTON2
CJNE A,#0,AJ3
JNB IN_GAL,AJEND
MOV BUTTON2,#1
JMP AJEND
AJ5:
MOV A,BUTTON3
CJNE A,#1,AJ6
JB IN_SUB,AJEND
MOV BUTTON3,#0
CALL SUB1
JMP AJEND
AJ6:
MOV A,BUTTON3
CJNE A,#0,AJ5
JNB IN_SUB,AJEND
MOV BUTTON3,#1
JMP AJEND
AJEND:
RET
;-------------------------------
; 加法
;-------------------------------
GAL1:
MOV A,MODE
CJNE A,#3,GAL2
INC 58H
MOV A,58H
CJNE A,#10,GALEND
MOV 58H,#0
INC 57H
MOV A,57H
CJNE A,#6,GALEND
MOV 57H,#0
GAL2:
MOV A,MODE
CJNE A,#2,GAL3
INC 55H
MOV A,55H
CJNE A,#10,GALEND
MOV 55H,#0
INC 54H
MOV A,54H
CJNE A,#6,GALEND
MOV 54H,#0
GAL3:
MOV A,MODE
CJNE A,#1,GALEND
INC 52H
MOV A,52H
CJNE A,#10,GAL32
MOV 52H,#0
INC 51H
GAL32:
CJNE A,#4,GALEND
MOV A,51H
CJNE A,#2,GALEND
MOV 52H,#0
MOV 51H,#0
GALEND:
CALL SAVE2
RET
;-------------------------------
; 减法
;-------------------------------
SUB1:
MOV A,MODE
CJNE A,#3,SUB2
DEC 58H
MOV A,58H
CJNE A,#-1,SUBEND
MOV 58H,#9
DEC 57H
MOV A,57H
CJNE A,#-1,SUBEND
MOV 57H,#5
SUB2:
MOV A,MODE
CJNE A,#2,SUB3
DEC 55H
MOV A,55H
CJNE A,#-1,SUBEND
MOV 55H,#9
DEC 54H
MOV A,54H
CJNE A,#-1,SUBEND
MOV 54H,#5
SUB3:
MOV A,MODE
CJNE A,#1,SUBEND
DEC 52H
MOV A,52H
CJNE A,#-1,SUBEND
MOV 52H,#9
DEC 51H
MOV A,51H
CJNE A,#-1,GALEND
MOV 52H,#3
MOV 51H,#2
SUBEND:
CALL SAVE2
RET
;-------------------------------
; 闪烁
;-------------------------------
FLASH1:
MOV A,FLASH
CJNE A,#0,FLASH2
MOV 51H,LED_1
MOV 52H,LED_2
MOV LED_1,#11
MOV LED_2,#11
MOV FLASH,#1
JMP FLASHEND
FLASH2:
MOV A,FLASH
CJNE A,#1,FLASHEND
MOV LED_1,51H
MOV LED_2,52H
MOV FLASH,#0
JMP FLASHEND;小时闪烁
FLASH3:
MOV A,FLASH
CJNE A,#0,FLASH4
MOV 54H,LED_4
MOV 55H,LED_5
MOV LED_4,#11
MOV LED_5,#11
MOV FLASH,#1
JMP FLASHEND
FLASH4:
MOV A,FLASH
CJNE A,#1,FLASHEND
MOV LED_4,54H
MOV LED_5,55H
MOV FLASH,#0
JMP FLASHEND;分钟闪烁
FLASH5:
MOV A,FLASH
CJNE A,#0,FLASH6
MOV 57H,LED_7
MOV 58H,LED_8
MOV LED_7,#11
MOV LED_8,#11
MOV FLASH,#1
JMP FLASHEND
FLASH6:
MOV A,FLASH
CJNE A,#1,FLASHEND
MOV LED_7,57H
MOV LED_8,58H
MOV FLASH,#0;秒钟闪烁
FLASHEND:
RET
;-------------------------------
; 数据加减
;-------------------------------
CADD:
INC LED_8
MOV A,LED_8
CJNE A,#10,CADDEND
MOV LED_8,#0
INC LED_7
MOV A,LED_7
CJNE A,#6,CADDEND
MOV LED_7,#0
INC LED_5
MOV A,LED_5
CJNE A,#10,CADDEND
MOV LED_5,#0
INC LED_4
MOV A,LED_4
CJNE A,#6,CADDEND
MOV LED_4,#0
INC LED_2
MOV A,LED_2
CJNE A,#10,CADD2
MOV LED_2,#0
INC LED_1
CADD2:
CJNE A,#4,CADDEND
MOV A,LED_1
CJNE A,#2,CADDEND
CALL SYSINIT
CADDEND:
CALL SAVE1
RET
;-------------------------------
; 数据显示
;-------------------------------
SHOW:
MOV R0,#30H
MOV R1,#8
MOV R2,#B
SHOW1:
MOV A,R2
MOV P0,A
CALL CS2_ON
RR A
MOV R2,A
MOV A,@R0
MOVC A,@A+DPTR
MOV P0,A
CALL CS1_ON
CALL DELAY
MOV P0,#0FFH
CALL CS1_ON
CALL CS2_ON
INC R0
DJNZ R1,SHOW1
RET
CS1_ON:
CLR WR_ON
CLR CS1
SETB WR_ON
SETB CS1
RET
CS2_ON:
CLR WR_ON
CLR CS2
SETB WR_ON
SETB CS2
RET
;-------------------------------
; 数据储存
;-------------------------------
SAVE1:
MOV 51H,LED_1
MOV 52H,LED_2
MOV 54H,LED_4
MOV 55H,LED_5
MOV 57H,LED_7
MOV 58H,LED_8
RET
SAVE2:
MOV LED_1,51H
MOV LED_2,52H
MOV LED_4,54H
MOV LED_5,55H
MOV LED_7,57H
MOV LED_8,58H
RET
;-------------------------------
; 数据初始化
;-------------------------------
SYSINIT:
MOV LED_1,#0
MOV LED_2,#0
MOV LED_3,#10
MOV LED_4,#0
MOV LED_5,#0
MOV LED_6,#10
MOV LED_7,#0
MOV LED_8,#0
CALL SAVE1
MOV TIMER,#200
MOV MODE,#0
MOV FLASH,#0
MOV BUTTON1,#1
MOV BUTTON2,#1
MOV BUTTON3,#1
MOV BUTTON4,#3
MOV TH0,#03CH
MOV TL0,#0AFH
SETB TR0
SETB ET0
SETB EA
MOV DPTR,#TAB
RET
;-------------------------------
; 延迟
;-------------------------------
DELAY:
MOV R6,#255
DJNZ R6,$
RET
;-------------------------------
; 段码
;-------------------------------
TAB:
DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0BFH,0FFH
;0- "0"
;1- "1"
;2- "2"
;
;9- "9"
;10-"-"
;11-" "
END

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com