In T0 timer interrupt control P1 mouth only 8 led lights shining with period 2 second cycle, fosc12MHZ.
#include
Sbit led=P2 ^ 0;//define P2.0 mouth light
Void main ()
{
TMOD=0 x01;//set the timer works
TH0=(65536-50000)/256;//set the timer initial
TL0=(65536-50000) % 256;
EA=1;//always interrupt
ET0=1;//T0 timer overflow interrupt
TR0=1;//start T0
While (1);//wait for interrupt
}
Void Timer0 () interrupt 1//T0 timer interrupt handling subroutine
{
Int I;
for(i=0; I<40; I++)
{
TH0=(65536-50000)/256;//heavy initialise
TL0=(65536-50000) % 256;
}
Led=~ led;//control indicator lights flashing
} CodePudding user response:
To change the you,
#include
Sbit led=P2 ^ 0;//define P2.0 mouth light
Void main ()
{
TMOD=0 x01;//set the timer works
TH0=(65536-50000)/256;//set the timer initial
TL0=(65536-50000) % 256;
EA=1;//always interrupt
ET0=1;//T0 timer overflow interrupt
TR0=1;//start T0
While (1);//wait for interrupt
}
Void Timer0 () interrupt 1//T0 timer interrupt handling subroutine
{
int i;
for(i=0; I<40; I++)
{
TH0=(65536-50000)/256;//heavy initialise
TL0=(65536-50000) % 256;
}
Led=~ led;//control indicator lights flashing
} CodePudding user response: