51单片机代码(定时器/计数器实验)求详细注释,非常谢谢
ORG0000HLJMPMAINORG000BHLJMPT0_INTORG0100MAIN:MOVTMOD,#01HMOVTH0,#0D8HMOVTL0,#0F0HMOV...
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP T0_INT
ORG 0100
MAIN:
MOV TMOD,#01H
MOV TH0,#0D8H
MOV TL0,#0F0H
MOV A,#00H
MOV P1,A
MOV R0,#20
SETB EA
SETB ET0
SETB TR0
LOOP: NOP
LJMP LOOP
T0_INT:
MOV TH0,#0D8H
MOV TL0,#0F0H
DJNZ R0,OUT
MOV R0,#20H
CPL A
MOV P1,A
OUT: RETI
END 展开
LJMP MAIN
ORG 000BH
LJMP T0_INT
ORG 0100
MAIN:
MOV TMOD,#01H
MOV TH0,#0D8H
MOV TL0,#0F0H
MOV A,#00H
MOV P1,A
MOV R0,#20
SETB EA
SETB ET0
SETB TR0
LOOP: NOP
LJMP LOOP
T0_INT:
MOV TH0,#0D8H
MOV TL0,#0F0H
DJNZ R0,OUT
MOV R0,#20H
CPL A
MOV P1,A
OUT: RETI
END 展开
1个回答
展开全部
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP T0_INT
ORG 0100
MAIN:
MOV TMOD,#01H ;定时器0设为模式1
MOV TH0,#0D8H ;赋初值(65536-10000)
MOV TL0,#0F0H
MOV A,#00H ;A=0
MOV P1,A ;P1=A
MOV R0,#20 ;R2=20
SETB EA ;开中断
SETB ET0 ;开定时器0中断
SETB TR0 ;启动定时器0
LOOP: NOP ;空操作
LJMP LOOP ;转LOOP
T0_INT:
MOV TH0,#0D8H ;重赋初值
MOV TL0,#0F0H
DJNZ R0,OUT ;R0减1不为0转OUT
MOV R0,#20H ;R0重赋初值
CPL A ;A取反
MOV P1,A ;P1=A
OUT: RETI
END
;该程序结果在P1上产生周期为400毫秒的脉冲输出,控制LED灯的话,以400毫秒周期闪烁
LJMP MAIN
ORG 000BH
LJMP T0_INT
ORG 0100
MAIN:
MOV TMOD,#01H ;定时器0设为模式1
MOV TH0,#0D8H ;赋初值(65536-10000)
MOV TL0,#0F0H
MOV A,#00H ;A=0
MOV P1,A ;P1=A
MOV R0,#20 ;R2=20
SETB EA ;开中断
SETB ET0 ;开定时器0中断
SETB TR0 ;启动定时器0
LOOP: NOP ;空操作
LJMP LOOP ;转LOOP
T0_INT:
MOV TH0,#0D8H ;重赋初值
MOV TL0,#0F0H
DJNZ R0,OUT ;R0减1不为0转OUT
MOV R0,#20H ;R0重赋初值
CPL A ;A取反
MOV P1,A ;P1=A
OUT: RETI
END
;该程序结果在P1上产生周期为400毫秒的脉冲输出,控制LED灯的话,以400毫秒周期闪烁
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询