14 Eylül 2017 Perşembe

Timer0 overflow

Timer0 will be used with overflow


Proteus: the same circuit as in interrupt. RA2 connected to a LED and we will blink this LED at every 250ms which will be counted by timer0.


XCC: we will use timer0 but not for interrupt. maximum period value 262ms, we choose 250ms. 1:256 prescaler and FOSC/4 oscillator. internal 1MHZ osc selected and RA2 is selected for output.


XC8: We add a if statement inside the main while loop. If overflow occures (at 250ms) toggle RA2 LED and clear overflow. LED will blink at 250ms period.


   while (1)
    {
        // Add your application code
        if (TMR0_HasOverflowOccured()) //Has Timer0 Overflowed?
        {
            IO_RA2_Toggle(); //Switch state of RA2 LED when overflow occurs
            TMR0IF = 0;      //Clear the Timer0 overflow flag
        }
    }

download the example

Hiç yorum yok:

Yorum Gönder