因为周期为10毫秒,定时器中断方式,所以初值应该为:65536-(10/2)*1000=65536-5000
TH0=(65536-5000)/256
TL0=(65536-5000)%256
程序如下:
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP T0ISR
ORG 0030H
MAIN:
MOV TMOD,#01H
MOV TH0,#HIGH(65536-5000)
MOV TL0,#LOW(65536-5000)
SETB TR0
SETB ET0
SETB EA
SJMP $
T0ISR:
CLR TR0
MOV TH0,#HIGH(65536-5000)
MOV TL0,#LOW(65536-5000)
SETB TR0
CPL P1.0
RETI
END
#include
sbit flag=P1^4;
void main()
{EA=1;
ET1=1;
TMOD=0x01;
TH0=(2^16-2500)/256;
TL0=(2^16-2500)/256;
TR0=1;
while(1);
}
void T()interrupt 1
{flag=!flag;
TH0=(2^16-2500)/256;
TL0=(2^16-2500)/256;
}