#pragma config FOSC=INTRCIO, WDTE=OFF, PWRTE=OFF, MCLRE=ON, CP=OFF, \ set the configuration bits: internal OSC, everything off except MCLR In this example we will mimic the functionality of the _delay_ms() function. The easiest way to understand how timers work is to look at some examples.Įxample 1: Using a timer to wait a specific amount of time. Therefore the amount of time that passes in between timer interrupts is dependent on the speed of the clock feeding the timer and the starting value placed in the timer register. If enabled, an interrupt will also occur. goes from 255 to 0 in an 8-bit timer), a status flag is set. When the register is incremented to the point that it rolls over (e.g. Each timer has a register that is incremented by a clock. What if we wanted to make an LED blink once per second, but also perform other tasks at the same time? One solution is to use a timer.Ī timer is essentially a flexible counter. This served our purposes well, but the CPU is unable to do anything useful during the delay. ![]() ![]() ![]() ![]() In this example, we used the _delay_ms() function to halt the CPU for a specified amount of time. In the Digital I/O section I provided some code to make an LED blink:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |