// PIC18F14K50 in C - Versione 0.6 - Febbraio 2012 // Copyright (c) 2010-2012 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 // Esternal High Priority Interrupt INT0 #include #include //#pragma config FOSC = IRCCLKOUT // Internal RC oscillator (F/4 to OSC2 - pin 3) #pragma config FOSC = HS // High speed crystal #pragma config WDTEN = OFF // Watchdog disabled #pragma config LVP = OFF // Disable Low Voltage Programming #pragma config MCLRE = ON // Enable MCLR - Required for debug... maybe 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) {if (INTCONbits.INT0IF == 1) {PORTC+=2; // Increments LEDs status INTCONbits.INT0IF = 0; // Clear interrupt status } } void main (void) // Program start here {TRISC = 0x01; // xxxx 0001 - Set RC1-RC2-RC3 as Output, RC0 as input PORTC = 0x00; // xxxx 000x - Turn off LEDs on port C ANSEL = 0x00; // Set as Digital I/O RCONbits.IPEN = 1; // Enable priority levels on interrupts INTCON2bits.INTEDG0 = 1; // Interrupt on rising edge INTCONbits.INT0IE = 1; // Enables INT0 interrupts INTCONbits.INT0IF = 0; // Clear interrupt status to avoid automatic interrupt ad "boot time" INTCONbits.GIEH = 1; // Enables all interrupts (required even for LOW priority) while (1); // Never ending loop }