ORG 0000H
AJMP START1
ORG 000BH ;T0中断入口
NOP
NOP
JMP MT0
ORG 0100H
START1:
MOV SP,#60H
MOV TL0,#18H
MOV TH0,#0FCH
MOV TMOD,#01H ;置计数器模式
MOV IE,#8BH ;EA,ET0,ET1
SETB TR0 ;启动定时器
NOP
NOP
START2:
AJMP START2
MT0:
PUSH ACC
PUSH PSW
NOP
NOP
MOV 0C1H,#00111101B ;喂狗
MOV A,TL0
ADD A,#18H
MOV TL0,A
MOV TH0,#0FCH
CPL P1.0
POP PSW
POP ACC
RETI
END
#include
void InitTimer0(void)
{
TMOD = 0x01;
TH0 = 0x0FE;
TL0 = 0x0C;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void main(void)
{
InitTimer0();
while(1);
}
void Timer0Interrupt(void) interrupt 1
{
TH0 = 0x0FE;
TL0 = 0x0C;
P1.0=~P1.0;
}