Here's one way with C18. Note I copied the Timers union from C18 timers.h and t1read.c so it's more visible than including timers.h and using the ReadTimer1 function.
#pragma config OSC=HS,LVP=OFF,WDT=OFF,MCLRE=OFF
/* used to hold 16-bit timer value */
unsigned int lt;
unsigned int Timer1Value = 0;
union Timers Timer;
Timer.bt = TMR1L; // Read Lower byte
Timer.bt = TMR1H; // Read upper byte
TMR1H = 0;
TMR1L = 0;
// 16-bit R/W mode, 1:1 prescale, int clk, Timer1 on
T1CON = 0b10000001;
Delay100TCYx(10); // wait 100 cycles * 10
Timer.bt = TMR1L; // read low byte
Timer.bt = TMR1H; // read high byte
Timer1Value = Timer.lt; // get 16-bit value
TMR1H = 0;
TMR1L = 0; // clear timer1 count
You can run it through MPSIM, make changes, and see how it works in both modes.
What is the name of the buffer for the high byte, TMR1H?
Yes it's still named TMR1H. It's just remapped so when in 16-bit mode, you're not actually reading TMR1H directly. It's a shadow buffer that is loaded with the actual Timer1 high byte count on read of TMR1L.
It is a tad confusing I guess, but you don't have direct access
to TMR1H in 16-bit R/W mode. Only the shadow buffer that TMR1H is mapped to.
post edited by breyno2 - 2007/09/22 12:00:09