|
“嘀、嘀、……”报警声
5.程序框图
主程序框图
中断服务程序框图
图4.18.2
6.汇编源程序
T02SA EQU 30H
T02SB EQU 31H
FLAG BIT 00H
ORG 00H
LJMP START
ORG 0BH
LJMP INT_T0
START: MOV T02SA,#00H
MOV T02SB,#00H
CLR FLAG
MOV TMOD,#01H
MOV TH0,#(65536-500) / 256
MOV TL0,#(65536-500) MOD 256
SETB TR0
SETB ET0
SETB EA
SJMP $
INT_T0:
MOV TH0,#(65536-500) / 256
MOV TL0,#(65536-500) MOD 256
INC T02SA
MOV A,T02SA
CJNE A,#100,NEXT
INC T02SB
MOV A,T02SB
CJNE A,#04H,NEXT
MOV T02SA,#00H
MOV T02SB,#00H
CPL FLAG
NEXT: JB FLAG,DONE
CPL P1.0
DONE: RETI
END
7.C语言源程序
#include
unsigned int t02s;
unsigned char t05ms;
bit flag;
void main(void)
{
TMOD=0x01;
TH0=(65536-500)/256;
TL0=(65536-500)%6;
TR0=1;
ET0=1;
EA=1;
while(1);
}
void t0(void) interrupt 1 using 0
{
TH0=(65536-500)/256;
TL0=(65536-500)%6;
t02s++;
if(t02s==400)
{
t02s=0;
flag=~flag;
}
if(flag==0)
{
P1_0=~P1_0;
}
} |
|