51单片机,用定时器中断,在P1口实现1S移动一次的流水灯,用汇编语言编写的程序
2个回答
展开全部
//晶振12M
DSEG AT 30H
timetemp: DS 1
LED: DS 1
CSEG AT 00H
ORG 0000H
LJMP START
ORG 000BH
LJMP Timer0Interrupt
START:
MOV SP,#60H
MOV timetemp,#20
MOV P1,#0FFH;LED低电平点亮
LCALL InitTimer0
MOV LED,#0FEH
LOOP:
MOV P1,LED ;add your code here!
LJMP LOOP
InitTimer0:
MOV TMOD,#01H
MOV TH0,#HIGH(65536-50000)
MOV TL0,#LOW(65536-50000);延时50ms
SETB EA
SETB ET0
SETB TR0
RET
Timer0Interrupt:
PUSH ACC
PUSH PSW
CLR TR1
MOV A,TL1
ADD A,#LOW(65536-50000)+7
MOV TL1,A
CLR A
ADDC A,#HIGH(65536-50000)
SETB TR1
DJNZ timetemp,NEXTT1
MOV timetemp,#20
;========================
MOV A,LED
RL A
MOV LED,A;add your code here!
;========================
POP PSW
POP ACC
RETI
DSEG AT 30H
timetemp: DS 1
LED: DS 1
CSEG AT 00H
ORG 0000H
LJMP START
ORG 000BH
LJMP Timer0Interrupt
START:
MOV SP,#60H
MOV timetemp,#20
MOV P1,#0FFH;LED低电平点亮
LCALL InitTimer0
MOV LED,#0FEH
LOOP:
MOV P1,LED ;add your code here!
LJMP LOOP
InitTimer0:
MOV TMOD,#01H
MOV TH0,#HIGH(65536-50000)
MOV TL0,#LOW(65536-50000);延时50ms
SETB EA
SETB ET0
SETB TR0
RET
Timer0Interrupt:
PUSH ACC
PUSH PSW
CLR TR1
MOV A,TL1
ADD A,#LOW(65536-50000)+7
MOV TL1,A
CLR A
ADDC A,#HIGH(65536-50000)
SETB TR1
DJNZ timetemp,NEXTT1
MOV timetemp,#20
;========================
MOV A,LED
RL A
MOV LED,A;add your code here!
;========================
POP PSW
POP ACC
RETI
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
CNT EQU 30H
ORG 0000H
SJMP STA
ORG 000BH
LJMP T0ISR
ORG 0050H
STA:
MOV TMOD,#01H
MOV TH0,#3CH
MOV TL0,#0B0H ;50ms
MOV P1,#0FEH
MOV CNT,#20
SETB ET0
SETB TR0
SETB EA
SJMP $
T0ISR:
CLR TR0
MOV TH0,#3CH
MOV TL0,#0B0H ;50ms
SETB TR0
DEC CNT
MOV A,CNT
JNZ T0ISRE
MOV CNT,#20
MOV A,P1
RL A
MOV P1,A
T0ISRE:
RETI
END
ORG 0000H
SJMP STA
ORG 000BH
LJMP T0ISR
ORG 0050H
STA:
MOV TMOD,#01H
MOV TH0,#3CH
MOV TL0,#0B0H ;50ms
MOV P1,#0FEH
MOV CNT,#20
SETB ET0
SETB TR0
SETB EA
SJMP $
T0ISR:
CLR TR0
MOV TH0,#3CH
MOV TL0,#0B0H ;50ms
SETB TR0
DEC CNT
MOV A,CNT
JNZ T0ISRE
MOV CNT,#20
MOV A,P1
RL A
MOV P1,A
T0ISRE:
RETI
END
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询