CE_PICaPart11
Newbie level 3
Hello, I can't seem to be getting my timer 1 to work. I have a 20 Mhz clock for the PIC. I am pretty new at using PICs. I do have a question about the clock and timer1. I have timer1 hooked up to the internal oscillator... but there is no internal oscillator. Am I configuring timer1 correctly? Also, can I put my interrupt service routine inside timer.c?
My main.c file is:
My timer.c file is:
Thanks for any help at all.
My main.c file is:
Code:
#include "htc.h"
#include "../include/timer.h"
#define _XTAL_FREQ 20000000
__CONFIG(WDTDIS & PWRTDIS & BORDIS & DEBUGDIS & UNPROTECT & HS);
void interrupt ISR(void)
{
if(TMR1IF)
{
counter++;
if(counter == 20) /* wait some time */
{
RB7 = ~RB7;
counter = 0;
}
TMR1L = 0x00; /* Low byte */
TMR1H = 0x00; /* High byte */
TMR1IF = 0; /* Clear interrupt flag */
}
}
void io_init(void)
{
TRISA = 0; /* PORTA is 6-bit wide - make all outputs */
TRISB = 0; /* PORTB is 8-bit wide - make all outputs */
PORTA = 0; /* Initial output is 0 */
PORTB = 0b01010101;
}
void main(void)
{
io_init();
timer_init();
RB7 = 0;
RB6 = 1;
while(1)
{
}
}
My timer.c file is:
Code:
#include "../include/timer.h"
void timer_init(void)
{
T1CKPS1 = 1; /* Prescaler of 8 */
T1CKPS0 = 1;
TMR1ON = 1; /* Enable timer1 */
TMR1IE = 1; /* Enable timer1 interrupts */
TMR1L = 0x00; /* Low byte */
TMR1H = 0x00; /* High byte */
}
Thanks for any help at all.