Timer Interrupt:
#include <reg51.h>
sbit WAVE =P2^1;unsigned char cnt;
void tim() interrupt 1 {WAVE=~WAVE; //toggle pin}
void ti() interrupt 3 {cnt++; //increment counterP0=cnt; //display value on pins}
void main() {cnt=0; //set counter to 0TMOD=0x22;TH0=-46; //10 KHzIE=0x8f; //enable interruptsTR0=1; //start timer 0TR1=1;while (1); //wait until interrupted}