I use this code to calculate crc's for various one wire things ds18b20 etc i would like to make a user command out of it
its limitation is in having all variables in bank 0 ,to avoid mucking about with bank switching, i assuming using these macros will make this a lot easier and more reliable
my question is what is the best way to go about it
should the crc var be a system var and the other just temps located anywhere ?
can you pass more than one var to a user command ?
can you pass optional var/s to a user command ?
code snippet:
GOTO BEGIN
asm
_CRCA
MOVLW 8
MOVWF _BC
YY MOVF _D,W
MOVWF _TMPS
MOVF _CRC,W
XORWF _TMPS,F
RRF _TMPS,F
BTFSS STATUS,C
GOTO XX
MOVLW 0X18
XORWF _CRC,F
XX RRF _CRC,F
RRF _D,F
DECFSZ _BC,F
GOTO YY
RETURN
ENDASM
BEGIN:
CRC VAR BYTE bank0 'CRC value system?
D VAR BYTE bank0 'input DATA to add to crc
BC VAR BYTE bank0 'temp var BIT COUNT
TMPS VAR BYTE bank0 'temp storage of byte to be crc'ed
main:
crc=0 'set crc to 0
some code
d= "z" ' a byte to crc
call crca
do some more code
d= "x" more data to crc
call crca
send crc to something
goto main '
its limitation is in having all variables in bank 0 ,to avoid mucking about with bank switching, i assuming using these macros will make this a lot easier and more reliable
my question is what is the best way to go about it
should the crc var be a system var and the other just temps located anywhere ?
can you pass more than one var to a user command ?
can you pass optional var/s to a user command ?
code snippet:
GOTO BEGIN
asm
_CRCA
MOVLW 8
MOVWF _BC
YY MOVF _D,W
MOVWF _TMPS
MOVF _CRC,W
XORWF _TMPS,F
RRF _TMPS,F
BTFSS STATUS,C
GOTO XX
MOVLW 0X18
XORWF _CRC,F
XX RRF _CRC,F
RRF _D,F
DECFSZ _BC,F
GOTO YY
RETURN
ENDASM
BEGIN:
CRC VAR BYTE bank0 'CRC value system?
D VAR BYTE bank0 'input DATA to add to crc
BC VAR BYTE bank0 'temp var BIT COUNT
TMPS VAR BYTE bank0 'temp storage of byte to be crc'ed
main:
crc=0 'set crc to 0
some code
d= "z" ' a byte to crc
call crca
do some more code
d= "x" more data to crc
call crca
send crc to something
goto main '
Comment