Interrupts! You use them to detect the change in pin status, timers, communication and so on. I’m sure if you reached this post in need of using interrupts (or having trouble with interrupts), then I assume you know what interrupts are and what you are trying to use.
With XC8, using interrupts is programmatically simple, since most of the code layout is given to you by <xc.h>. Now setting up interrupts is as simple as using the keyword “interrupt” before the function which should be called when an interrupt happens. I am not going to cover the difference between C18 and XC8 (XC8 makes your life a lot easier), but I’ll show you how to use interrupts in XC8. This post will have only the input from pin change. The timer interrupt will be covered later in the timer chapter.
I encourage you to read the datasheet in order to understand much better about interrupt registers.
- Set RB0 as input pin (set the TRIS as 1)
- Enable the interrupt bit for RB0
- Set rising or falling edge interrupt
- clear the interrupt for the pin (just to make sure)
Microchip Xc8 Download
- Check if the interrupt flag to make sure the IO pin caused the interrupt (or the peripheral you are looking for)
- Do your task
- Reset your interrupt flag
![Descargar Mplab Xc8 Descargar Mplab Xc8](/uploads/1/3/7/2/137247166/268918902.jpg)