Hi,
Ahh, well the TMR registers are like any other register in the PIC so you can read/write to/from them as you would with any other register. So to set the TMR0 registers to 0 (assuming a 16 bit TMR0 here):
To PRESET it you write whatever value you wish to the two registers:Code:MyCount var WORD 'This is my counter... TMR0L = 0 'Reset lower byte TMR0H = 0 'Reset hogher byte Start: MyCount.HighByte = TMR0H 'Get high byte of counter MyCount.LowByte = TMR0L 'Get low byte of counter LCDOUT $FE,1,#MyCount 'Display it Pause 100 Goto Start
That's really all there is to it. Well, one more thing. When reading the two TMR registers in the way shown above there is a slight chance the lower byte rolls over in the time between reading TMR0H and TMR0L. To come around that problem you can either enable 16bits read/writes (on PICs that supports it) or read the high byte two times, like:Code:TMR0H = 3 'Preset TMR0 to 878.... TMR0L = 110 ' ( 3 * 256 + 110 )
HTHCode:MyCount VAR WORD Temp var byte MyCount.HighByte = TMR0H 'Get high byte of counter MyCount.LowByte = TMR0L 'Get low byte of counter Temp = TMR0H 'Get high byte again IF Temp <> MyCount.HighByte then 'Do a fresh read MyCount.HighByte = TMR0H 'Get high byte of counter MyCount.LowByte = TMR0L 'Get low byte of counter EndIf
/Henrik Olsson.




Bookmarks