Using PIC16F18446 TMR0 module to create a 1 second delay WITHOUT the use of the interrupts. Here is the program so far:
I'm new to embedded programming. Essentially I've selected internal 8 MHz oscillator and the TMR0 clock source is Fosc/4 so 2 MHz. I've also enabled 1:256 pre-scalar and my math to create 1 second delay is as follows:
2MHz / 256
= 7182.5
TMR0 has to count to 7182 in order to last 1 second. My problem is how do I read the two registers TMR0H and TMR0L together, in an if statement to check whether it has exceeded this number, as efficiently as I can. There are a lot of peripherals in this PIC chip that utilities two registers to hold one value and the datasheet isn't clear to me on how to read the values in both registers as one total value. So how do I combine the registers in a single read and while I'm asking how can I do the same for writing?
Code:
void main(void) {
// Oscillator Settings:
// HFINTOSC 8 MHz
OSCCON1 = 0b01110100;
OSCFRQ = 0b00000011;
// Data Direction Settings
TRISA = 0x00;
// Data Port Settings
// TMR0 Settings
T0CON0 = 0b10010000; // TMR0 Enabled / 16-bit mode
T0CON1 = 0b01001000; // Fosc/4 Source / Synchronized / 1:256 Pre-scalar
while(1){
if ( "TIMER0 < 7182" ){
//BLINK LED CODE
}
}
return;
}
2MHz / 256
= 7182.5
TMR0 has to count to 7182 in order to last 1 second. My problem is how do I read the two registers TMR0H and TMR0L together, in an if statement to check whether it has exceeded this number, as efficiently as I can. There are a lot of peripherals in this PIC chip that utilities two registers to hold one value and the datasheet isn't clear to me on how to read the values in both registers as one total value. So how do I combine the registers in a single read and while I'm asking how can I do the same for writing?