// PIC16F690 in C - Versione 0.2d - Dicembre 2009 // Copyright (c) 2009, 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/PIC16F690 #include __CONFIG(INTIO & // Use internal clock WDTDIS & // Disable watchdog PWRTEN & // Delay after power on enabled MCLRDIS & // Internal External Switch Over Mode Disable UNPROTECT & // Disable memory protection BORDIS & // Disable reset on low volage IESODIS & // Internal External Switch Over Mode Disable FCMDIS); // Disable Fail clock monitoring void main(void) {OSCCON=0x70; // x111 0000 - 8 Mhz internal clock TRISC = 0x00; // Set PORTC as Output ANSEL = 0; // Set as Digital I/O ANSELH = 0; // Set as Digital I/O PORTC = 0; // All LEDs off //TRISA = 0xFF; // Set PORTA as input (RA3 is always input if MCLR disabled) IOCA3 = 1; // Enable RA3 pin interrupt; see INTERRUPT-ON-CHANGE PORTA REGISTER RABIE = 1; // Enable interrupt on PORTA and PORTB ei(); // Enable all interrupt (GIE = 1) for(;;); // Do nothing... } void interrupt isr(void) // Interrupt Service Routine {if (RABIF) // Interrupt from PORTA/B ? {if (!RA3) // If RA3 = 0 (key pressed) PORTC++; // PORTC increment RABIF = 0; // Clear PORTA/B interrupg flag } }