I've spent hours on this but i can not get the timer 1 interrupt working using the Pic16F18855 and Pro for Pic.
I've tried the example given by the Timer Calculator (V4.0.0) and looked through the datasheet but i'm obviously missing something. I have proven that test_led does light by using the dip switches.
I've added my code below and would appreciate any help with this.
Ian
Code: Select all
sbit test_led at RB4_bit;
//mode
sbit mode_dip_sw_1 at RA0_bit;
sbit mode_dip_sw_2 at RA0_bit;
//sbit mode_dip_sw_3 at RE3_bit;
sbit mode_dip_sw_4 at RB5_bit;
//ON period
sbit on_dip_sw_1 at RB3_bit;
sbit on_dip_sw_2 at RB2_bit;
sbit on_dip_sw_3 at RB1_bit;
sbit on_dip_sw_4 at RB0_bit;
sbit on_dip_sw_5 at RC7_bit;
sbit on_dip_sw_6 at RC6_bit;
sbit on_dip_sw_7 at RC5_bit;
sbit on_dip_sw_8 at RC4_bit;
//OFFperiod
sbit off_dip_sw_1 at RA2_bit;
sbit off_dip_sw_2 at RA3_bit;
sbit off_dip_sw_3 at RA4_bit;
sbit off_dip_sw_4 at RA5_bit;
sbit off_dip_sw_5 at RA7_bit;
sbit off_dip_sw_6 at RA6_bit;
sbit off_dip_sw_7 at RC2_bit;
sbit off_dip_sw_8 at RC3_bit;
//required varibles
unsigned int
cnt = 0;
//dip switches
unsigned int
mode,
on_period,
off_period;
void interrupt() {
if (TMR1IF_bit) {
TMR1IF_bit = 0; // clear TMR0IF
TMR1H = 0x80;
TMR1L = 0x00;
cnt++; // increment cnt
if(cnt >= 1000){
test_led = 1;
cnt = 0;
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
void main() {
OSCCON1 = 0x92; // 16MHz internal oscillator
TRISA = 0xFF; // PORTA Directions
ANSELA = 0x00; // PORTA all digital pins
PORTA = 0; // clear PORTA
TRISB = 0x2F; // PORTB Directions
ANSELB = 0x00; // PORTB all digital pins
PORTB = 0; // clear PORTA
TRISC = 0xFF; // PORTC Directions
ANSELC = 0x00; // PORTC all outputs low
PORTC = 0x00; // clear PORTC
//Disable Comparators
CM1CON0 = CM2CON0 = 0x00;
//configure timer 1
T1CON = 0x01; // Timer1 settings
TMR1IF_bit = 0; // Clear the Timer 1 interrupt flag
TMR1H = 0xF0; // Initialize Timer1 register
TMR1L = 0x60;
TMR1IE_bit = 1; // Enable Timer 1 interrupt
cnt = 0; // initialize cnt
INTCON = 0xC0; // Set GIE, PEIE
//set weak pullups
WPUA = 0b11111111;
WPUB = 0b00101111;
WPUC = 0b11111100;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//main loop
while(1) {
//read the mode dipswitches
mode = 0;
if (!mode_dip_sw_1) { mode = mode + 1;}
if (!mode_dip_sw_2) { mode = mode + 2;}
if (!mode_dip_sw_4) { mode = mode + 4;}
//read the ON period dipswitches
on_period = 0;
if (!on_dip_sw_1) { on_period = on_period + 1;}
if (!on_dip_sw_2) { on_period = on_period + 2;}
if (!on_dip_sw_3) { on_period = on_period + 4;}
if (!on_dip_sw_4) { on_period = on_period + 8;}
if (!on_dip_sw_5) { on_period = on_period + 16;}
if (!on_dip_sw_6) { on_period = on_period + 32;}
if (!on_dip_sw_7) { on_period = on_period + 64;}
if (!on_dip_sw_8) { on_period = on_period + 128;}
//read the OFF period dipswitches
off_period = 0;
if (!off_dip_sw_1) { off_period = off_period + 1;}
if (!off_dip_sw_2) { off_period = off_period + 2;}
if (!off_dip_sw_3) { off_period = off_period + 4;}
if (!off_dip_sw_4) { off_period = off_period + 8;}
if (!off_dip_sw_5) { off_period = off_period + 16;}
if (!off_dip_sw_6) { off_period = off_period + 32;}
if (!off_dip_sw_7) { off_period = off_period + 64;}
if (!off_dip_sw_8) { off_period = off_period + 128;}
//if(off_period == 2){ test_led = 1; } else { test_led = 0; }
}
}
}