normad
Member
hey guys im trying to use timer1 to measure time.. Ive enabled interrupts set up timer 1 in timer mode and initialized it to 53036 so that it'll give a 0.1 second interrupt. Im running on an external 4Mhz crystal.
i dont know whats wrong
its a very simple code but the interrupt isnt occuring
please help
my displays are working fine.. but its only displaying 123456 its not incrementing
i dont know whats wrong
my displays are working fine.. but its only displaying 123456 its not incrementing
Code:
#include <htc.h>
__CONFIG(MCLREN & UNPROTECT & WDTDIS & XT & PWRTDIS & LVPDIS & PWRTDIS & BORDIS);
#define _XTAL_FREQ 4000000
unsigned char a = 1, b = 2,c = 3,d = 4,e = 5,f = 6;
unsigned int len_thrs = 60 , time = 0 , count = 0;
void init_mpu(void);
void disp(void);
void disp_thrs(void);
void main(void) {
init_mpu();
disp();
while(1) {
}
}
void init_mpu(void) {
TRISA = 0b00010000; // 00010000
TRISB = 0b11000001; // 11000001
PORTA = 0x00;
PORTB = 0x00;
ei(); //enable global interrupts
TMR1CS = 0;
T1CKPS0 = 1;
T1CKPS0 = 1;
TMR1IF = 0;
TMR1ON = 0;
T1OSCEN = 0;
TMR1L = 0b11100100;
TMR1H = 0b00101101;
TMR1ON = 1;
TMR1IE = 1; //enable timer 1 interrupt
}
void disp(void) {
PORTA = f;
RB1 = 0;
RB2 = 0;
RB3 = 0;
RB4 = 1;
__delay_us(10);
RB4 = 0;
PORTA = e;
RB1 = 1;
RB2 = 0;
RB3 = 0;
RB4 = 1;
__delay_us(10);
RB4 = 0;
PORTA = d;
RB1 = 0;
RB2 = 1;
RB3 = 0;
RB4 = 1;
__delay_us(10);
RB4 = 0;
PORTA = c;
RB1 = 1;
RB2 = 1;
RB3 = 0;
RB4 = 1;
__delay_us(10);
RB4 = 0;
PORTA = b;
RB1 = 0;
RB2 = 0;
RB3 = 1;
RB4 = 1;
__delay_us(10);
RB4 = 0;
PORTA = a;
RB1 = 1;
RB2 = 0;
RB3 = 1;
RB4 = 1;
__delay_us(10);
RB4 = 0;
}
static void interrupt int_handler(void) {
if(TMR1IF) {
TMR1IF = 0;
TMR1ON = 0;
TMR1L = 0b11100100;
TMR1H = 0b00101101;
TMR1ON = 1;
time++;
if(time>10) {
time = 0;
a++;
b++;
c++;
d++;
e++;
f++;
disp();
}
}
}