2
votes

PIC18F252

In assembly:

From A/D conversion, I have a 10-bit result left- or right-adjusted, at result registers ADRESH and ADRESL.

What's a clever method to get these 10 bits into TMR0H from bit 5 through TMR0L bit 4?

More specifically, with two 11s at the front:

XXXX XXXX XX00 0000 ADRESH ADRESL => 
11XX XXXX XXXX 0000 TMR0H TMR0L
1

1 Answers

2
votes

No tested...

bsf     STATUS, _C    ;Set Carry 
rrcf    ADRESH, f     ;Do 16 bit shift right of ADRES 
rrcf    ADRESL, f
bsf     STATUS, _C    ;Set Carry 
rrcf    ADRESH, w     ;Do high byte shift right
movwf   TMR0H         ;Copy WREG to destination 
rrcf    ADRESL, w     ;Do low byte shift right 
movwf   TMR0L         ;Copy WREG to destination 

Read also datasheet how TMR0 is updated: 10.4 16-Bit Mode Timer Reads and Writes