PDA

View Full Version : reading / resetting timer0 in 16 bit mode



iw2fvo
- 24th April 2021, 15:00
good day to all in this forum,
I am using pic18f877 as a counter and I would like to use timer0 in 16 bit mode for reading an external signal.
At the moment I am not able to read the whole 16 bit content of the timer correctly.
Any sample picbasic code please ? / any help please ?
Thank in advance
regards,
Bye

HenrikOlsson
- 24th April 2021, 16:31
I didn't know there was an PIC18F877 and I can't seem to find a datasheet for it so I would guess you're using the 16F877 but that doesn't have a 16bit TMR0 so you'd need to clarify that a bit.

But generally speaking, you read the TMR0L first which latches the high byte of the timer/counter into TMR0H for you to read.

myCount VAR WORD

myCount.BYTE0 = TMR0L ' Get low byte and latch content of high byte
myCount.BYTE1 = TMR0H ' Get high byte


/Henrik.

iw2fvo
- 24th April 2021, 21:03
Thanks Henrik;
I am sorry for the PIC type: it is a PIC18F452.
I understand that I must read the low byte first and then read the high byte.
I must write the high byte first and then write the low byte ...
Am I correct please ?
Thanks
Bye

HenrikOlsson
- 24th April 2021, 21:18
That is correct.