I want 10 sec delay for the system how to implement it in keil c. kindly help me.
for example: consider a road signal which has three aspects and when the aspect changes from green to red it goes to yellow aspect and there is a delay of 5 to 10 sec. how to implement it. I implemented it by using for loops. But there is any way to implement using Hardware timer concepts
comment on the following program for approx 10 sec delay.
#include <REGX52.H> #include<stdio.h> static unsigned long overflow_count = 0; void timer1_ISR (void) interrupt 3 { overflow_count++; if(overflow_count==(0x60000)) { P0=P0^0xFF; overflow_count=0; } } void main (void) { TMOD = (TMOD & 0x0F) | 0x20; TH1 = 0XFF ; TL1 = TH1; ET1 = 1; TR1 = 1; EA = 1; while(1); }
thanks, vijay
what about this program for 10 sec delay without interrupt.
#include<stdio.h> #include <REG54.H> #define S 10 /*select your time in seconds*/ void delay(); void main() { int i; while(1) { P0=~P0; for(i=0;i<20*S;i++) / delay(); } } void delay() /* delay subroutine */ { TMOD &= 0xF0; // Clear all T0 bits (T1 left unchanged) TMOD |= 0x01; // Set required T0 bits (T1 left unchanged) ET0 = 0; // No interupts // Values for 50 ms delay /* calculation for 50 ms (50ms/1000ms)*1000000=50000 65536-50000=15536=3CB0 TH0=3C TL0=B0 */ TH0 = 0x3C; // Timer 0 initial value (High Byte) TL0 = 0xB0; // Timer 0 initial value (Low Byte) TF0 = 0; // Clear overflow flag TR0 = 1; // Start timer 0 while (TF0 == 0); // Loop until Timer 0 overflows (TF0 == 1) TR0 = 0; // Stop Timer 0 }