I was just about to start naively storing all the bits sequentially, but thought of a better method (I'm probably not the first to think of this).
Instead there is a pattern of 5 bytes, the first 4 contain exactly what was in the least significant bits of the first 4 analog to digital conversions. The 5th byte is packed with four sets of the extra 2 bits from each conversion.
I'm pretty sure this is much faster than doing it the other way, both packing and unpacking.
I haven't included the code for setting the FSR to the start point of the store, the loop or the readAD subroutine because they are more application specific.
Code:
Instead there is a pattern of 5 bytes, the first 4 contain exactly what was in the least significant bits of the first 4 analog to digital conversions. The 5th byte is packed with four sets of the extra 2 bits from each conversion.
I'm pretty sure this is much faster than doing it the other way, both packing and unpacking.
I haven't included the code for setting the FSR to the start point of the store, the loop or the readAD subroutine because they are more application specific.
Code:
Rich (BB code):
call readAD ;First byte
movf ADRESLtemp, W
movwf INDF
movlw 0x04
addwf FSR, F ;FSR + 4
clrf INDF
btfsc ADRESHtemp, 1
bsf INDF, 7
btfsc ADRESHtemp, 0
bsf INDF, 6
movlw 0x03 ;FSR - 3
subwf FSR, F
call readAD ;Second byte
movf ADRESLtemp, W
movwf INDF
movlw 0x03
addwf FSR, F ;FSR + 3
btfsc ADRESHtemp, 1
bsf INDF, 5
btfsc ADRESHtemp, 0
bsf INDF, 4
movlw 0x02 ;FSR - 2
subwf FSR, F
call readAD ;Third byte
movf ADRESLtemp, W
movwf INDF
movlw 0x02
addwf FSR, F ;FSR + 2
btfsc ADRESHtemp, 1
bsf INDF, 3
btfsc ADRESHtemp, 0
bsf INDF, 2
movlw 0x01 ;FSR - 1
subwf FSR, F
call readAD ;Fourth byte
movf ADRESLtemp, W
movwf INDF
movlw 0x01
addwf FSR, F ;FSR + 1
btfsc ADRESHtemp, 1
bsf INDF, 1
btfsc ADRESHtemp, 0
bsf INDF, 0
movlw 0x1 ;FSR + 1
addwf FSR, F
Last edited: