// 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 volatile unsigned char counter; // 0-255 counter (uptadated in ISR) void main(void) {counter = 0; // Clear counter 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 PIE1 = 0b00000001; // Enable TIMER1 interrupt; see PERIPHERAL INTERRUPT ENABLE REGISTER 1 INTCON = 0b01000000; // Enables all peripheral interrupt; see INTERRUPT CONTROL REGISTER T1CON = 0b00110101; // See TIMER 1 CONTROL REGISTER // 0 Ignored // 0 Timer always count // 1 Prescaler set to 8 // 1 Prescaler set to 8 // 0 Ignored // x Ignored // 0 Internal clock // 1 Timer 1 enabled ei(); // Enable all interrupt for(;;) {PORTC = counter;} // Output counter to LEDs } void interrupt isr(void) // Interrupt routine {if( // Check if TIMER1 is the interrupt source (TMR1IE)&& // Is TIMER1 iterrupt enabled? AND (TMR1IF)) // Is TIMER1 overflowed? {counter++; // YES -> update counter TMR1IF=0; // Clear Interrupt Flag of Timer1 } }