Hello everyone, I'm new here
this looks like a friendly forum
So, I've been scratching my head for the past 3 days trying to get my PIC2550(first PIC to work with) to do timer0 interrupt, using external oscilator, 16MHz crystal, 22p caps.
the code toggle two leds, and that is exactly what happens, but
I don't feel like i'm able to control the TMR0 at all.
When T08BIT is set, no matter what is the value of TMR0H or TMR0L, the LED toggles every exactly 4 seconds.
When T08BIT is not set, no matter what is the value of TMR0L, the LED toggles very fast.I read the datasheet and still reading it. most relevant pages 26,32,34, & 127 in the datasheet
http://ww1.microchip.com/downloads/en/devicedoc/39632c.pdfThe code is very small and I put comments on every command to explain it. It's easier to read it by downloading the attached file, i use tabs not spaces :/
#include <xc.h>;
#define _XTAL_FREQ 16000000
// BEGIN CONFIG
#pragma config FOSC = HS //External High-Speed Crystal
#pragma config WDT = OFF //Watchdog Timer disabled
#pragma config LVP = OFF //Single-Supply ICSP disabled
//END CONFIG
#define LED_PORT PORTCbits.RC0
#define LED_TRIS TRISCbits.TRISC0
#define LED2_PORT PORTCbits.RC1
#define LED2_TRIS TRISCbits.TRISC1
void SetupTimer0()
{
TMR0L = 0x00; //This value doesn't seem to be doing anything no matter what I put in it
TMR0H = 0x00; //This value doesn't seem to be doing anything no matter what I put in it
T0PS0 = 1; //1:256 Prescale value
T0PS1 = 1; //1:256 Prescale value
T0PS2 = 1; //1:256 Prescale value
PSA = 0; //prescaler is assigned. Timer0 clock input comes from prescaler output.
T0SE = 0; //Increment on high-to-low transition on T0CKI pin
T0CS = 0; //Internal instruction cycle clock source(CLKO)
T08BIT = 1; //Timer0 is configured as a 8-bit timer/counter
TMR0ON = 1; //Enables Timer0
TMR0IE = 1; //Enable TIMER0 Interrupt
PEIE = 1; //Enable Peripheral Interrupt
}
void interrupt ISR()
{
if (TMR0IE && TMR0IF) {
TMR0IF = 0;
LED_PORT ^= 1; //Toggling led
LED2_PORT ^= 1; //Toggling led
}
}
void main()
{
LED_TRIS = 0; //set led port as output
LED_PORT = 1; //start LED ON.
LED2_TRIS = 0; //set led port as output
LED2_PORT = 0; //start LED off.
SetupTimer0();
ei(); // enable all interrupts
while(1);
}
I'm using xc8 compiler, on a linux os.
Thank you all in advance .