# PIC MCU: XC8 Not treating TMR0 as a 16 Bit Register

I recently finished a project programming a PIC18F2620. All was good, but I decided to explore the new stuff Microchip has to offer, and am now trying out the PIC18F47Q43.

I'm getting a strange problem when loading a value into Timer 0. For the 18F2620, all you had to write in MPLAB was "TRM0 = 65535" and boom the thing has it's 16 bit value. When I try and do the same with this micro though, it's saying its not a 16 bit register, and I'm getting this error:

I know that TMR0 isn't actually a register, it is just a tool put together in XC8 to make things easier, but they wouldn't have revoked this feature in later releases would they?

• Not an answer yet because I don't have confidence, but can you try writing the value as 255 into TMR0L and 255 into TMR0H? Datasheet page 380 suggests that the timer register is split into two. Sep 3 '20 at 15:29
• Refer to the datasheet section 24.1.2 on page 380 (as nanofarad commented above). You need to write TMR0H & TMR0L individually - and you must write TMR0H before TMR0L. When reading it's the opposite, so read TMR0L then TMR0H. Sep 3 '20 at 15:55
• There should be a config or register for 16-bit timer value. You must chage it. Read datasheet. Never used this pic but I saw that in others. Sep 3 '20 at 21:34
• Check the XC8 header file for this particular processor. You might find it’s not named TMR0 for some reason. For example if there is an 8-bit mode, as hunted by other answers, it would not make sense to always write 16 bits. Sep 3 '20 at 22:19

Everyone is right about the reading and writing order of the two 8 bit registers. I've also found the XC8 functions WRITETIMERx(value) & READTIMERx() which control the correct reading and writing procedures of the TMRxH and TMRxL registers.

Additionally, the PIC18F47Q43 datasheet states that while Timer 0 is active in 16-bit mode, no writes are allowed.

///////////////////////////////////////////[FROM PAGE 380]

//////////////////////////////////////////////////////////////////////////

Upon reading this I initially thought all you had to do before writing a 16-bit value was disable the timer in OSCCON0, but that is not the case for this particular device. Good thing Timer 0 has a plethora of pre and post scaling options to pick from.

NOTE: In 8-bit mode, an overflow interrupt gets flagged when TMR0L matches TMR0H, so to control the period just have to write your values to the TMR0H register.

in the data sheet

section: 24.1

page 379,

It states that the time 0 can be either 16 bit or 8 bit.

Timer0 can operate as either an 8-bit or 16-bit timer. The mode is selected with the MD16 bit

24.5.1 T0CON0
Name: T0CON0