This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Timer

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

Parents
  • 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
    }
    

    thanks,
    vijay

Reply
  • 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
    }
    

    thanks,
    vijay

Children
No data