ELE2303 WORKSHOP 7 – Interrupts Demo section How to set up an interrupt and test it. Problem section 1. Start with a new project for a PIC18F4620 processor (assume Fosc = 10Mhz) [ Make sure you include #pragma config WDT = OFF in your main file ] Write a program and interrupt routine (similar to the demo) which triggers an interrupt on INT2 (RB2) that toggles (flashes) the state of 4 LEDS on PortB 4-7. See Table 10-4 (from the PIC18F4620 data sheet) below for register details. Test what happens when you comment out the line in the interrupt routine, which clears the interrupt flag. 2. Make a new project for a PIC18F4620 processor. Write a program and interrupt routine (based on the demo) which triggers on a Timer1 overflow interrupt and stores a counter value to port D. Make sure you also set the PEIE bit in the INCON register. See Table 12-2 below for register details. 3. Modify you timer project to use the low priority interrupt for Timer1 instead. Add code from the previous project for a high priority interrupt for INT2. The interrupt for Timer1 overflow is to store the counter value to port D. The interrupt on INT2 is to toggle (flash) the state of 4 LEDS on PortB 4-7./* * File: main.c * Author: phythian * * when tested on PICsimlab, click on button RB1 * to see changes on LEDs on PORTD */ #pragma config WDT = OFF #define _XTAL_FREQ 10000000 #include int count=0; interrupt high_ISR (void) { if (INTCON3bits.INT1IF) { count++; LATD = count; INTCON3bits.INT1IF = 0; } } void main(void) { // unsigned so it can count to 255 unsigned char c; // zeros for outputs TRISD = 0x00; LATD = 0x00; TRISB = 0x0F; // ones for inputs // priority disabled RCONbits.IPEN = 0; INTCON = 0x80; // enable INT1 input INTCON3bits.INT1IE = 1; while(1) { __delay_ms(10); // delay so code can be stopped in loop } }