In this recipe, we will learn how to define an interrupt service routine for the 8051 microcontroller.
Implementing an interrupt service routine
How to do it...
Follow these steps to complete this recipe:
- Switch to the build system we set up in Chapter 2, Setting Up the Environment.
- Make sure that the 8051 emulator is installed:
# apt install -y mcu8051ide
- Launch mcu8051ide and create a new project called Test.
- Create a new file called test.c and put the following code snippet into it. This increments an internal counter for each timer interrupt:
#include<mcs51reg.h>
volatile int Counter = 0;
void timer0_ISR (void) __interrupt(1) /*interrupt no. 1 for Timer0 */
{
Counter++;
}
void main(void)
{
...