- 8051

8051 itimer interrupt program to display value of 'Y' at P0 and 'n' at P2. Also generate square wave of 10 KHz at P2^0 with timer0 in interrupt mode.Using XTAL@22MHz

I have explained the calculations for the timer in my previous post.please have a look .
CODE:

#include<REGx51.h>
sbit sqwave=P2^0;
void timer0() interrupt 1
{
    sqwave=~sqwave;  //generating sq wave
}
void main()
{
  TMOD=0x02;  //Timer0 in 8 bit autoreload mode
IE=0x82; //enabling intrupt
TH0=0x47; //loading the calculated value
     TR0=1;     //starting timer
while(1)
{
  P0='y';
  P2='n';
}
}

Leave a Reply