I could not get a Proper software time delay as per calculation. I am using Timer 0 Mode 1 (16 bit timer) of Microchip AT89C51 with a crystal frequency 11.0592MHz.I have keil uVision 5. kindly let me know if i made a mistake. Here is a simple code that i've used to genrate 25ms delay at Port 2 pin 0. #include <reg51.h>
sbit mybit = P2^0; void T0M1_delay (void); void main(void) { TMOD = 0x01; while(1) { mybit =~mybit; T0M1_delay(); } } void T0M1_delay() { TL0=0xFE; TH0=0xA5; TR0=1; while(TF0==1); TR0=0; TF0=0; }
After compilation & built, it do not gives an error or warning. I measure the delay in a logic analizer, and found very small value about 17.4 microsecond Delay insted of 25ms.