// PIC18F14K50 in C - Versione 0.4 - Novembre 2010 // Copyright (c) 2010 VincenzoV.net // Creative Commons | Attribuzione-Condividi allo stesso modo 3.0 Unported. // Creative Commons | Attribution-Share Alike 3.0 Unported // https://www.vincenzov.net/tutorial/elettronica-di-base/PIC18F14K50 // Switch: High Priority Interrupt // Please, read: https://www.vincenzov.net/tutorial/elettronica-di-base/PIC18F14K50/interrupt-old.htm #include #pragma config FOSC = IRCCLKOUT // Internal RC oscillator (F/4 to OSC2 - pin 3) #pragma config WDTEN = OFF // Watchdog disabled #pragma config LVP = OFF // Disable Low Voltage Programming #pragma config MCLRE = OFF // Disable MCLR void High_Int (void); // ISR function prototype #pragma code high_vector = 0x08 // Setup interrupt vector void interrupt (void) { _asm GOTO High_Int _endasm } // Jump to ISR function (in-line assembler) #pragma code // Back to normal code #pragma interrupt High_Int void High_Int (void) {char dummy; if (INTCONbits.RABIF == 1) {dummy = PORTA; // Need to read PORTA to clear interrupt PORTC=0; // Clear LEDs status INTCONbits.RABIF = 0; // Clear interrupt status } } void main (void) // Program start here { OSCCON = 0x70; // Set internal clock to 16 MHz TRISC = 0x00; // Set PORTC as Output PORTC = 0x05; // xxxx 0101 - Turn on some LEDs on port C ANSEL = 0; // Set as Digital I/O ANSELH = 0; // Set as Digital I/O TRISA = 0xFF; // Set PORTA as input (PA3 is always input if MCLR disabled) WPUAbits.WPUA3 = 1; // RA3: pull-up enabled IOCAbits.IOCA3 = 1; // RA3: Interrupt-on-change enabled INTCONbits.RABIE = 1; // RA and RB Port Change Interrupt Enable bit RCONbits.IPEN = 1; // Enable priority levels on interrupts INTCON2bits.RABIP = 1; // High priority INTCONbits.GIEL = 0; // Disable all low priority interrupts INTCONbits.GIEH = 1; // Enables all high priority interrupts (required even for LOW priority) while (1) {PORTC++; // Change LEDs status Delay10KTCYx(200); // Delay 200 x 10.000 NOP cycle } }