  
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
uint i,count;
sbit s1=P1^0;
void main()
{
TMOD=0x01;
TH1=(65536-60000)/256; //高8位
TL1=(65536-60000)%256; //低8位
P1=0x00;
EA=1; //打开中断总开关,1表示打开,0表示关闭
ET0=1; //打开定时/计数器中断0
TR0=1; //启动定时器
while(1);
{
if(s1==0)
count++;
if(count==20)
P1=0x00;
}
}
void interrupt_0()interrupt 1
{
TH1=(65536-60000)/256; //高8位
TL1=(65536-60000)%256; //低8位
count--;
if(i<=0)
{
i=20;
P1=~P1;
}
}
|