I am completing a project to use my old Casio graphics calculator as a datalogger and graphical display for a Picaxe project.
The Picaxe gathers the data and sends the data to the calculator. It all works very nicely - I have a rolling set of data points being captured and the data is being graphed dynamically.
I currently have a limit of the data transmitted between 0 and 255, though I think 0 to 65335 is very practical. I cannot get my head around the coding relative to a CRC check the Casio requires and the hanlding of WORD numbers in BCD format.
The code below is the code I writen to create the CRC but it also shows the limits of the BCD data handling (actually the limit is in theory 999 but my sensor only returns currently returns 0-255).
The checksum calculation is shown in the table below:
The CRC essentially can be resolved to the code I have defined in the test routine - this will only work for 0-999 numbers - I want to change the code to be 0-65535 but I am struggling to get my mind around handling BCD and summing the BCD numbers (or the decimal equivilent) - my will fail at above 999 as I am 'mucking around' with the BCD numbering scheme to get the results I want.
A typical set of data to be sent from the Pixace to the Casio is as follows - this is a hardcoded value to send 123456789. The data format is described in the table shown in the attachment.
I have implemented a checksum sub routines, support 0-999 as follows using the code shown above. An example - of a value of 255, retuuns BCD values $25 and $50 with a checksum of $7F.
Any thoughts on how I can make handling the BCD easier and then to expand the handling to 65535 (or WORDS).
Thank you,
Anobium
The Picaxe gathers the data and sends the data to the calculator. It all works very nicely - I have a rolling set of data points being captured and the data is being graphed dynamically.
I currently have a limit of the data transmitted between 0 and 255, though I think 0 to 65335 is very practical. I cannot get my head around the coding relative to a CRC check the Casio requires and the hanlding of WORD numbers in BCD format.
The code below is the code I writen to create the CRC but it also shows the limits of the BCD data handling (actually the limit is in theory 999 but my sensor only returns currently returns 0-255).
The checksum calculation is shown in the table below:
The CRC essentially can be resolved to the code I have defined in the test routine - this will only work for 0-999 numbers - I want to change the code to be 0-65535 but I am struggling to get my mind around handling BCD and summing the BCD numbers (or the decimal equivilent) - my will fail at above 999 as I am 'mucking around' with the BCD numbering scheme to get the results I want.
Code:
symbol valueout = w2
symbol majval = b20
symbol minval = b21
symbol units = b22
symbol tens= b23
symbol hundreds = b24
symbol vname = b26
symbol checksum = b27
for w1 = 1 to 999
valueout = w1
bintoascii valueout, hundreds, tens, units
' maj
majval = hundreds - $30
majval = majval * 16
minval = tens - $30
majval = majval + minval
'min
minval = units - $30
minval = minval * 16
checksum = majval + minval + 12
checksum = NOT checksum
checksum = checksum + 1
next
Code:
serout 2, T9600_16, ( $3A,$00,$01,$00,$01,$01,$23, $45, $67, $89, $00, $00, $00, $01, $09, $9b)
Code:
gosub crc: 'this routine sets up checksum, majval and minval as BCD values
serout 2, T9600_16, ( $3A,$00,$01,$00,$01,$00,$00, $00, $00, majval, minval, $00, $00, $01, $09, checksum)
Thank you,
Anobium
Last edited: