#include <stdio.h>
#include <reg66x.h>
sbit light=P2^0;
sbit switc=P2^1;
#define TH0_R 0xB7
#define TL0_R 0xFF
#define on 0
#define off 1
void tinit0(void); //timer 0 init function
void init_intt();
void set_light(unsigned int t);
unsigned int ttcounter=0;
void main()
{light=off;
init_intt();
tinit0(); //init timer 0
while(1)
{
if (switc==0) set_light(6000);
}}
void tinit0(void) //timer init fuction
{TMOD=0x09; //set timer 0 to mode 1 and gate 0
//TH0=0x6F; //set higher timer reg to 0
//TL0=0xFF; //set lower timer reg to 0
TR0=1;
} //return the pulse width
void init_intt(void)
{
ET0=1;
EA=1;
}
void timer_int (void) interrupt 1
{
TH0=0xB7;
TL0=0xFF;
ttcounter++;
}
void set_light(unsigned int t)
{light=on;
while(ttcounter<t);
light=off;
ttcounter=0;
}