> static volatile unsigned INT TMR1 @ 0x0E; > > and do something like > > counter = -TMR1; This is a problem whether it appears to be working or not. Unless you know for sure that timer 1 is off during this statement, the low byte could wrap around between the reads of the two registers. Normally you read the high byte and save it, read the low byte and save it, then read the high byte and do it all again if it changed. > > and that works fine. The trouble is that on the '452, TMR1H is only > updated (it's really just a holding register) when TMR1L is read, and > unluckily for me > > counter = -TMR1; > > compiles/assembles to code that reads the high byte first, then the > low byte, and so the result in is worthless. > > What is an elegant way to stay as much as possible in 16-bit land yet > "persuade" the compiler to read the low byte first? I'm not familiar with your compiler, but this would be very easy in in-line assembler. There are several C-only answers that come to mind. You could create a union where COUNTER is overlayed with its two bytes. Note that this makes your code dependant on the machine byte ordering. Here is a "pure" C answer: counter = tmr1l; /* get the low byte, saves high byte snapshot in TMR1H */ counter = counter | (tmr1l << 8); /* get high byte and assemble in 16 bit word */ however, the left shift probably compiles to some rather unpleasant code unless the compiler is clever enough to detect shifts of a constant multiple of 8 and do the appropriate byte shuffling. ***************************************************************** Olin Lathrop, embedded systems consultant in Devens Massachusetts (978) 772-3129, olin@cognivis.com, http://www.cognivis.com -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu