单片机:80C51的中断系统及定时/计数器
2个回答
展开全部
org 0000h
ljmp reset
org 000bh
ljmp int_time
ORG 0030H
RESET: mov sp,#07h
mov r0,#7fh
clear0: mov @r0,a
djnz r0,clear0
MOV TMOD,#01H ;设定定时器0
MOV TL0,#0cH ;设定定时初值65536-500
MOV TH0,#0FeH
setb ea
setb ET0
setb tr0
ajmp $
int_time:
mov tl0,#0ch
mov th0,#0feh
cpl p1.1
reti
end
ljmp reset
org 000bh
ljmp int_time
ORG 0030H
RESET: mov sp,#07h
mov r0,#7fh
clear0: mov @r0,a
djnz r0,clear0
MOV TMOD,#01H ;设定定时器0
MOV TL0,#0cH ;设定定时初值65536-500
MOV TH0,#0FeH
setb ea
setb ET0
setb tr0
ajmp $
int_time:
mov tl0,#0ch
mov th0,#0feh
cpl p1.1
reti
end
展开全部
#include <reg51.h>
sbit OUT = P1^1;
void InitTimer0(void)//1ms定时中断初始化
{
TMOD = 0x01;
TH0 = 0x0FC;
TL0 = 0x18;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void main(void)
{
InitTimer0();
while(1);
}
void Timer0Interrupt(void) interrupt 1 //1ms定时中断
{
TH0 = 0x0FC;
TL0 = 0x18;
OUT = ~OUT;
}
sbit OUT = P1^1;
void InitTimer0(void)//1ms定时中断初始化
{
TMOD = 0x01;
TH0 = 0x0FC;
TL0 = 0x18;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void main(void)
{
InitTimer0();
while(1);
}
void Timer0Interrupt(void) interrupt 1 //1ms定时中断
{
TH0 = 0x0FC;
TL0 = 0x18;
OUT = ~OUT;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询