PIC Microcontrollers Programming in C - Example 4 with MikroC Pro for PIC and Protheus

preview_player
Показать описание
Using timers TMR0, TMR1 and TMR2. Using interrupts, declaring new function...

If you have read the previous example, you probably have noticed a disadvantage of providing delays using loops. In all those cases, the microcontroller is ‘captive’ and does nothing. It simply waits for some time to pass. Such waste of time is an unacceptable luxury and some other method should be applied therefore. Do you remember the story about timers? Interrupts? This example makes links between them in a practical way. The schematic is still the same as well as the challenge. It is necessary to provide a delay long enough to notice changes on a port. Timer TMR0 with assigned prescaler is used for this purpose. An interrupt is generated on every timer register overflow and every interrupt routine automatically increments the cnt variable by 1. When it’s value reaches 400, the port B is incremented by 1. The whole procedure is performed ‘behind the scenes’, which enables the microcontroller to do something else.
Рекомендации по теме
welcome to shbcf.ru