phrbob93
Member level 1
- Joined
- Mar 28, 2014
- Messages
- 38
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Location
- Jalandhar, punjab
- Activity points
- 343
i am Generating 1 second delay using timers in 8051
my concept is like this
iam using 11.0592 crystal frequency
time required for 1 machine cycle is1.085 micro second
if timer is set to 0000h then time required for timer to run once is 65536*1.085= 7.11 ms
now if 7.11*142(times the loop runs) = 1000ms=1sec
so here is my code
im not getting delay of 1 second, instead i am geting delay of mili seconds.. plz help me where iam wrong
my concept is like this
iam using 11.0592 crystal frequency
time required for 1 machine cycle is1.085 micro second
if timer is set to 0000h then time required for timer to run once is 65536*1.085= 7.11 ms
now if 7.11*142(times the loop runs) = 1000ms=1sec
so here is my code
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #include<reg51.h> void delay(void); void main() { while(1) { P2=0x00; // led off delay(); // delay for 1sec P2=0xFF; // led on delay(); // delay for 1 sec } } void delay(void) { int i; TMOD=0x01; // timer 0 in mode 1 for(i=0;i<14;i++) { TL0=0x00; // starting value from 0 TH0=0x00; TR0=1; // sart timer while(TF0==0); // polling TF flag for high TR0=0; // stop timer TF0=0; // clear flag TF0 } }
im not getting delay of 1 second, instead i am geting delay of mili seconds.. plz help me where iam wrong
Last edited: