- #include <xc.h>
- // PIC16F1719 Configuration Bit Settings
- // For more on Configuration Bits, consult y**ice data sheet
- // CONFIG1
- #pragma config FOSC = ECH // External Clock, 4-20 MHz
- #pragma config WDTE = OFF // Watchdog Timer (WDT) disabled
- #pragma config PWRTE = OFF // Power-up Timer disabled
- #pragma config MCLRE = ON // MCLR/VPP pin function is MCLR
- #pragma config CP = OFF // Flash Memory Code Protection off
- #pragma config BOREN = ON // Brown-out Reset enabled
- #pragma config CLKOUTEN = OFF // Clock Out disabled.
- #pragma config IESO = ON // Internal/External Switchover on
- #pragma config FCMEN = ON // Fail-Safe Clock Monitor enabled
- // CONFIG2
- #pragma config WRT = OFF // Flash Memory Self-Write Protect off
- #pragma config PPS1WAY = ON // PPS one-way control enabled
- #pragma config ZCDDIS = ON // Zero-cross detect disabled
- #pragma config PLLEN = OFF // Phase Lock Loop disable
- #pragma config STVREN = ON // Stack Over/Underflow Reset enabled
- #pragma config BORV = LO // Brown-out Reset low trip point
- #pragma config LPBOR = OFF // Low-Power Brown Out Reset disabled
- #pragma config LVP = OFF // Low-Voltage Programming disabled
- // Interrupt function
- void interrupt isr(void){
- // only process Timer0-triggered interrupts
- if(INTCONbits.TMR0IE && INTCONbits.TMR0IF) {
- // static variable for permanent storage duration
- static unsigned char portValue;
- // write to port latches
- LATD = portValue++; // RD[0:3] = LED[0:3]
- LATB = (portValue++ >> 4); // RB[0:3] = LED[4:7]
- // clear this interrupt condition
- INTCONbits.TMR0IF = 0;
- }
- }
- void main(void){
- // Port D access
- ANSELD = 0x0; // set to digital I/O (not analog)
- TRISD = 0x0; // set all port bits to be output
- // Port B access
- ANSELB = 0x0; // set to digital I/O (not analog)
- TRISB = 0x0; // set all port bits to be output
- // Timer0 setup
- OPTION_REG = 0xD7; // timer 0 internal clock, prescaler 1:256
- INTCONbits.TMR0IE = 1; // enable interrupts for timer 0
- ei(); // enable all interrupts
- while(1);
- return;
- }
|