// 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 // Internal Timer: Low Priority Interrupt #include #include #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 Low_Int (void); // ISR function prototype #pragma code low_vector = 0x18 // Setup interrupt vector void interrupt_low (void) { _asm GOTO Low_Int _endasm } // Jump to ISR function (in-line assembler) #pragma code // Back to normal code #pragma interruptlow Low_Int void Low_Int (void) {if (INTCONbits.TMR0IF == 1 ) // Interrupt from Timer0? {PORTC++; // Change LEDs status INTCONbits.TMR0IF = 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 RCONbits.IPEN = 1; // Enable priority levels on interrupts OpenTimer0( TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_EDGE_FALL & T0_PS_1_128 ); INTCON2bits.TMR0IP = 0; // Set low priority interrupt INTCONbits.GIEL = 1; // Enables all low priority interrupts INTCONbits.GIEH = 1; // Enables all high priority interrupts (required even for LOW priority) while (1) { } }