Mercurial > public > hwos_code
comparison src/convert.asm @ 634:4050675965ea
3.10 stable release
| author | heinrichsweikamp |
|---|---|
| date | Tue, 28 Apr 2020 17:34:31 +0200 |
| parents | cd58f7fc86db |
| children | 75e90cd0c2c3 |
comparison
equal
deleted
inserted
replaced
| 633:690c48db7b5b | 634:4050675965ea |
|---|---|
| 1 ;============================================================================= | 1 ;============================================================================= |
| 2 ; | 2 ; |
| 3 ; File convert.asm combined next generation V3.04.2 | 3 ; File convert.asm combined next generation V3.09.4l |
| 4 ; | 4 ; |
| 5 ; Converts register values to string | 5 ; Converts register values to string |
| 6 ; | 6 ; |
| 7 ; Copyright (c) 2011, Matthias Heinrichs, HeinrichsWeikamp, all right reserved. | 7 ; Copyright (c) 2011, Matthias Heinrichs, HeinrichsWeikamp, all right reserved. |
| 8 ;============================================================================= | 8 ;============================================================================= |
| 9 ; HISTORY | 9 ; HISTORY |
| 10 ; 2007-10-07 : [MH] Creation for OSTC sources | 10 ; 2007-10-07 : [MH] Creation for OSTC sources |
| 11 ; 2010-12-10 : [jDG] Optimize macro size | 11 ; 2010-12-10 : [jDG] Optimize macro size |
| 12 ; | 12 ; |
| 13 | 13 |
| 14 #include "hwos.inc" ; Mandatory header | 14 #include "hwos.inc" |
| 15 | 15 #include "math.inc" |
| 16 convert CODE | 16 #include "strings.inc" |
| 17 | 17 |
| 18 ;============================================================================= | 18 |
| 19 | 19 ;============================================================================= |
| 20 convert1 CODE | |
| 21 ;============================================================================= | |
| 22 | |
| 23 | |
| 24 ;----------------------------------------------------------------------------- | |
| 25 ; Print last two Digits or double-dots if zero - big Font | |
| 26 ; | |
| 20 global output99DD_call | 27 global output99DD_call |
| 21 output99DD_call: | 28 output99DD_call: |
| 22 tstfsz lo ; value = 0 ? | 29 tstfsz lo ; value = 0 ? |
| 23 bra output99_call ; NO - do normal output | 30 bra output99_call ; NO - do normal output |
| 24 movlw " " ; YES - print a space | 31 movlw " " ; YES - print a space |
| 25 movwf POSTINC2 ; - ... | 32 movwf POSTINC2 ; - ... |
| 26 bra output99dd_cont ; - continue with the double dots | 33 bra print_doubledots ; - continue printing two dots |
| 27 | 34 |
| 28 | 35 |
| 36 ;----------------------------------------------------------------------------- | |
| 37 ; Print last two Digits or double-dots if zero - small Font | |
| 38 ; | |
| 29 global output99dd_call | 39 global output99dd_call |
| 30 output99dd_call: | 40 output99dd_call: |
| 31 tstfsz lo ; value = 0 ? | 41 tstfsz lo ; value = 0 ? |
| 32 bra output99_call ; NO - do normal output | 42 bra output99_call ; NO - do normal output |
| 33 output99dd_cont: | 43 bra print_doubledots ; YES - continue printing two dots |
| 34 movlw "." ; YES - print double dots | 44 |
| 35 movwf POSTINC2 ; - ... | 45 |
| 46 ;----------------------------------------------------------------------------- | |
| 47 ; Helper Function - Print two Dots | |
| 48 ; | |
| 49 print_doubledots: | |
| 50 movlw "." ; load a '.' | |
| 51 movwf POSTINC2 ; print 1st dot | |
| 52 movwf POSTINC2 ; print 2nd dot | |
| 53 bra output_common_finish ; clean-up and return | |
| 54 | |
| 55 | |
| 56 ;----------------------------------------------------------------------------- | |
| 57 ; Print last Digit from a 8 bit Integer (0-9) | |
| 58 ; | |
| 59 global output9_call | |
| 60 output9_call: | |
| 61 bsf hide_digit2 ; do not print digit 5, 4, 3 and 2 | |
| 62 bra output8_common ; continue with common part | |
| 63 | |
| 64 | |
| 65 ;----------------------------------------------------------------------------- | |
| 66 ; Print only last two Digits from a 8 bit Integer, with leading zero (00-99) | |
| 67 ; | |
| 68 global output99x_call | |
| 69 output99x_call: | |
| 70 bsf leading_zeros ; print leading zeros | |
| 71 ;bra output99_call ; continue with output99_call | |
| 72 | |
| 73 | |
| 74 ;----------------------------------------------------------------------------- | |
| 75 ; Print last two Digits from a 8 bit Integer (0-99) | |
| 76 ; | |
| 77 global output99_call | |
| 78 output99_call: | |
| 79 bsf hide_digit3 ; do not print digit 5, 4 and 3 | |
| 80 ;bra output8_common ; continue with common part | |
| 81 | |
| 82 | |
| 83 ;----------------------------------------------------------------------------- | |
| 84 ; Print 8 bit Integer (0-255) | |
| 85 ; | |
| 86 global output256_call | |
| 87 output256_call: | |
| 88 ;bra output8_common ; continue with common part | |
| 89 | |
| 90 | |
| 91 ;----------------------------------------------------------------------------- | |
| 92 ; Helper Function - common Part for Printing 8 Bit Integers | |
| 93 ; | |
| 94 output8_common: | |
| 95 bcf output_overflow ; clear overflow flag | |
| 96 movff lo,bin_lo ; copy value to show | |
| 97 rcall convert_bin8bcd ; compute bcd_hi (1 digit) and bcd_lo (2 digits) | |
| 98 btfsc hide_digit2 ; shall hide digit 2 ? | |
| 99 bsf hide_digit3 ; YES - hide digit 3 then, too | |
| 100 bra output_common_d3 ; start printing with digit 3 | |
| 101 | |
| 102 | |
| 103 ;----------------------------------------------------------------------------- | |
| 104 ; Print last four Digits from a 16 bit Value (0-9999) | |
| 105 ; | |
| 106 global output9999_call | |
| 107 output9999_call: | |
| 108 bsf hide_digit5 ; do not print digit 5 | |
| 109 bra output16_common ; continue with common part | |
| 110 | |
| 111 | |
| 112 ;----------------------------------------------------------------------------- | |
| 113 ; Print last three Digits from a 16 bit Value (0-999) | |
| 114 ; | |
| 115 global output999_call | |
| 116 output999_call: | |
| 117 bsf hide_digit4 ; do not print digit 4 and 5 | |
| 118 ;bra output16_common ; continue with common part | |
| 119 | |
| 120 | |
| 121 ;----------------------------------------------------------------------------- | |
| 122 ; Print a full 16 bit Value (0-65535) | |
| 123 ; | |
| 124 global output65535_call | |
| 125 output65535_call: | |
| 126 ;bra output16_common ; continue with common part | |
| 127 | |
| 128 | |
| 129 ;----------------------------------------------------------------------------- | |
| 130 ; Helper Function - common Part for Printing 16 Bit Integers | |
| 131 ; | |
| 132 output16_common: | |
| 133 bcf output_overflow ; clear overflow flag | |
| 134 movff lo,bin_lo ; copy value to show | |
| 135 movff hi,bin_hi ; ... | |
| 136 rcall convert_bin16bcd ; compute bcd_up (1 digit), bcd_hi (2 digits) and bcd_lo (2 digits) | |
| 137 btfsc hide_digit2 ; shall hide digit 2 ? | |
| 138 bsf hide_digit3 ; YES - hide digit 3 then, too | |
| 139 btfsc hide_digit3 ; shall hide digit 3 ? | |
| 140 bsf hide_digit4 ; YES - hide digit 4 then, too | |
| 141 btfsc hide_digit4 ; shall hide digit 4 ? | |
| 142 bsf hide_digit5 ; YES - hide digit 5 then, too | |
| 143 ;bra output_common_d5 ; start printing with digit 5 | |
| 144 | |
| 145 | |
| 146 ;----------------------------------------------------------------------------- | |
| 147 ; Helper Function - common Part for Printing 8 and 16 Bit Integers | |
| 148 ; | |
| 149 output_common_d5: | |
| 150 ; digit 5 | |
| 151 btfss hide_digit5 ; shall hide digit 5 ? | |
| 152 bra output_common_d5p ; NO - print digit 5 | |
| 153 movf bcd_up,W ; YES - get lower nibble (digit 5) into WREG | |
| 154 andlw 0x0F ; - is it zero? | |
| 155 bnz print_9999 ; NO - print '9999' | |
| 156 bra output_common_d4 ; YES - continue with digit 4 | |
| 157 output_common_d5p: | |
| 158 movf bcd_up,W ; copy 5th digit to lower nibble of WREG | |
| 159 rcall print_digit ; print the digit | |
| 160 | |
| 161 output_common_d4: | |
| 162 ; between digit 5 and 4 | |
| 163 btfsc decimal_digit3 ; shall print a decimal point in front of digit 3 ? | |
| 164 bsf leading_zeros ; YES - allow printing of zeros now | |
| 165 | |
| 166 ; digit 4 | |
| 167 btfss hide_digit4 ; shall hide digit 4 ? | |
| 168 bra output_common_d4p ; NO - print digit 4 | |
| 169 swapf bcd_hi,W ; YES - get upper nibble (digit 4) into WREG | |
| 170 andlw 0x0F ; - is it zero? | |
| 171 bnz print_999 ; NO - print '999' | |
| 172 bra output_common_d3 ; YES - continue with digit 3 | |
| 173 output_common_d4p: | |
| 174 swapf bcd_hi,W ; copy 4th digit to lower nibble of WREG | |
| 175 rcall print_digit ; print the digit | |
| 176 | |
| 177 output_common_d3: | |
| 178 ; between digit 4 and 3 | |
| 179 btfsc decimal_digit3 ; shall print a decimal point in front of digit 3 ? | |
| 180 rcall print_decimal ; YES - print a decimal pint now | |
| 181 btfsc decimal_digit2 ; shall print a decimal point in front of digit 2 ? | |
| 182 bsf leading_zeros ; YES - allow printing of zeros now | |
| 183 btfsc omit_digit_2 ; shall omit digits 2 and 1 ? | |
| 184 bsf leading_zeros ; YES - allow printing of zeros now | |
| 185 | |
| 186 ; digit 3 | |
| 187 btfss hide_digit3 ; shall hide digit 3 ? | |
| 188 bra output_common_d3p ; NO - print digit 3 | |
| 189 movf bcd_hi,W ; YES - get lower nibble (digit 3) into WREG | |
| 190 andlw 0x0F ; - is it zero? | |
| 191 bnz print_99 ; NO - print '99' | |
| 192 bra output_common_d2 ; YES - continue with digit 2 | |
| 193 output_common_d3p: | |
| 194 movf bcd_hi,W ; copy 3rd digit to lower nibble of WREG | |
| 195 rcall print_digit ; print the digit | |
| 196 | |
| 197 output_common_d2: | |
| 198 ; between digit 3 and 2 | |
| 199 btfsc decimal_digit2 ; shall print a decimal point in front of digit 2 ? | |
| 200 rcall print_decimal ; YES - print a decimal pint now | |
| 201 btfsc decimal_digit1 ; shall print a decimal point in front of digit 1 ? | |
| 202 bsf leading_zeros ; YES - allow printing of zeros now | |
| 203 btfsc omit_digit_1 ; shall omit digit 1 ? | |
| 204 bsf leading_zeros ; YES - allow printing of zeros now | |
| 205 | |
| 206 ; digit 2 | |
| 207 btfss hide_digit2 ; shall hide digit 2 ? | |
| 208 bra output_common_d2p ; NO - print digit 2 | |
| 209 swapf bcd_lo,W ; YES - get upper nibble (digit 2) into WREG | |
| 210 andlw 0x0F ; - is it zero? | |
| 211 bnz print_9 ; NO - print '9' | |
| 212 bra output_common_d1 ; YES - continue with digit 2 | |
| 213 output_common_d2p: | |
| 214 btfsc omit_digit_2 ; shall omit digit 2 ? | |
| 215 bra output_common_finish ; YES - finish output | |
| 216 swapf bcd_lo,W ; NO - copy 2nd digit to lower nibble of WREG | |
| 217 rcall print_digit ; - print the digit | |
| 218 | |
| 219 output_common_d1: | |
| 220 ; between digit 2 and 1 | |
| 221 btfsc decimal_digit1 ; shall print a decimal point in front of digit 1 ? | |
| 222 rcall print_decimal ; YES - print a decimal pint now | |
| 223 bsf leading_zeros ; allow printing of zeros now | |
| 224 | |
| 225 ; digit 1 | |
| 226 btfsc omit_digit_1 ; shall omit digit 1 ? | |
| 227 bra output_common_finish ; YES - finish output | |
| 228 movf bcd_lo,W ; NO - copy 1st digit to lower nibble of WREG | |
| 229 rcall print_digit ; - print the digit | |
| 230 | |
| 231 output_common_finish: | |
| 232 clrf INDF2 ; place a terminator at the current buffer position | |
| 233 clrf CVT_flags1 ; clear output format command flags | |
| 234 clrf CVT_flags2 ; ... | |
| 235 return ; done | |
| 236 | |
| 237 | |
| 238 ;----------------------------------------------------------------------------- | |
| 239 ; Helper Function - print a Digit or a decimal Point | |
| 240 ; | |
| 241 ; Input: lower nibble of WREG BCD code of digit | |
| 242 ; leading_zeros =1: print (leading) zeros | |
| 243 ; leftbind =1: do not print leading spaces | |
| 244 ; | |
| 245 print_digit: | |
| 246 andlw 0x0F ; keep only the lower nibble, is it zero? | |
| 247 bnz print_digit_digit ; NO - print in any case | |
| 248 btfsc leading_zeros ; YES - printing of zeros allowed? | |
| 249 bra print_digit_digit ; YES - print a zero | |
| 250 btfsc leftbind ; NO - shall print left-aligned? | |
| 251 return ; YES - done | |
| 252 movlw ' ' ; NO - load ASCII code of a space char | |
| 253 bra print_digit_print ; - print it | |
| 254 print_digit_digit: | |
| 255 bsf leading_zeros ; allow printing of zeros now | |
| 256 addlw '0' ; add ASCII code of '0' to BCD code to get final ASCII code | |
| 257 print_digit_print: | |
| 258 movwf POSTINC2 ; print the digit or char | |
| 259 return ; done | |
| 260 | |
| 261 print_decimal: | |
| 262 movlw '.' ; load ASCII code of a dot | |
| 263 bra print_digit_print ; print it | |
| 264 | |
| 265 | |
| 266 ;----------------------------------------------------------------------------- | |
| 267 ; Helper Function - print '9999' or '999' or '99' or '9' | |
| 268 ; | |
| 269 print_9999: | |
| 270 movlw '9' ; load a '9' digit | |
| 271 movwf POSTINC2 ; print digit 4 | |
| 272 print_999: | |
| 273 movlw '9' ; load a '9' digit (for those embarked lately) | |
| 274 movwf POSTINC2 ; print digit 3 | |
| 275 print_99: | |
| 276 movlw '9' ; load a '9' digit (for those embarked lately) | |
| 277 movwf POSTINC2 ; print digit 2 | |
| 278 print_9: | |
| 279 movlw '9' ; load a '9' digit (for those embarked lately) | |
| 280 movwf POSTINC2 ; print digit 1 | |
| 281 clrf INDF2 ; place a terminator at the current buffer position | |
| 282 clrf CVT_flags1 ; clear output format command flags | |
| 283 clrf CVT_flags2 ; ... | |
| 284 bsf output_overflow ; set overflow flag | |
| 285 return ; done | |
| 286 | |
| 287 | |
| 288 ;----------------------------------------------------------------------------- | |
| 289 ; Convert an 8 Bit Integer to BCD | |
| 290 ; | |
| 291 ; Input: bin_lo 8 bit integer | |
| 292 ; Output: bcd_hi,bcd_lo 3 BCD digits | |
| 293 ; | |
| 294 convert_bin8bcd: | |
| 295 clrf bcd_lo ; clear result variables | |
| 296 clrf bcd_hi ; ... | |
| 297 bsf bcd_hi,0 ; set loop counter to 8 | |
| 298 convert_bin8bcd_loop: | |
| 299 ; get MSB bit from binary | |
| 300 rlcf bin_lo,F ; shift-out MSB to CARRY | |
| 301 ; lower two BCDs | |
| 302 movf bcd_lo,W ; get lower BCDs to WREG | |
| 303 addwfc bcd_lo,W ; WREG = 2 * WREG + CARRY | |
| 304 daw ; decimal-adjust BCDs in WREG | |
| 305 movwf bcd_lo ; copy back WREG to lower BCDs | |
| 306 ; higher one BCD | |
| 307 rlcf bcd_hi ; higher BCD = 2*(higher BCD) + CARRY (special version for 1 BCD only) | |
| 308 ; loop control | |
| 309 bnc convert_bin8bcd_loop ; all 8 bits done? NO -> loop | |
| 310 return ; YES -> done | |
| 311 | |
| 312 | |
| 313 ;----------------------------------------------------------------------------- | |
| 314 ; Convert a 16 Bit Integer to BCD | |
| 315 ; | |
| 316 ; Input: bin_hi,bin_lo 16 bit integer | |
| 317 ; Output: bcd_up,bcd_hi,bcd_lo 5 BCD digits | |
| 318 ; | |
| 319 convert_bin16bcd: | |
| 320 clrf bcd_lo ; clear result variables | |
| 321 clrf bcd_hi ; ... | |
| 322 clrf bcd_up ; ... | |
| 323 movlw .16 ; 16 bits to do | |
| 324 movwf math_loop ; load loop counter | |
| 325 convert_bin16bcd_loop: | |
| 326 ; get MSB bit from binary | |
| 327 rlcf bin_lo,F ; shift-out MSB to CARRY | |
| 328 rlcf bin_hi,F ; ... | |
| 329 ; lower two BCDs | |
| 330 movf bcd_lo,W ; get lower BCDs to WREG | |
| 331 addwfc bcd_lo,W ; WREG = 2 * WREG + CARRY | |
| 332 daw ; decimal-adjust BCDs in WREG | |
| 333 movwf bcd_lo ; copy back WREG to lower BCDs | |
| 334 ; higher two BCDs | |
| 335 movf bcd_hi,W ; repeat for higher BCDs | |
| 336 addwfc bcd_hi,W ; ... | |
| 337 daw ; ... | |
| 338 movwf bcd_hi ; ... | |
| 339 ; upper one BCD | |
| 340 ; movf bcd_up,W ; repeat for upper BCD | |
| 341 ; addwfc bcd_up,W ; ... | |
| 342 ; daw ; ... | |
| 343 ; movwf bcd_up ; ... | |
| 344 rlcf bcd_up ; upper BCD = 2*(upper BCD) + CARRY (special version for 1 BCD only) | |
| 345 ; loop control | |
| 346 decfsz math_loop ; decrement bit counter, all done? | |
| 347 bra convert_bin16bcd_loop ; NO - loop | |
| 348 return ; YES - done | |
| 349 | |
| 350 | |
| 351 ;============================================================================= | |
| 352 convert2 CODE | |
| 353 ;============================================================================= | |
| 354 | |
| 355 | |
| 356 ;----------------------------------------------------------------------------- | |
| 357 ; Print Value in WREG as hex Number (00-FF) | |
| 358 ; | |
| 359 global outputHEX_call | |
| 360 outputHEX_call: | |
| 361 movwf bin_lo ; make a backup | |
| 362 swapf WREG,W ; swap nibbles to process upper nibble first | |
| 363 rcall outputHEX_nibble ; print nibble as ASCII | |
| 364 movf bin_lo,W ; recall backup | |
| 365 outputHEX_nibble: | |
| 366 andlw 0x0F ; isolate lower nibble | |
| 367 addlw +0x36 ; add 0x36 so that numbers >= decimal 10 will become >= 0x40 | |
| 368 btfss WREG,6 ; WREG >= 0x40 ? | |
| 369 addlw -0x07 ; NO - number is < 10, move back by offset between ASCII codes for 'A' and '9' | |
| 370 addlw +0x01 ; make final common move forward to align with ASCII code | |
| 371 movwf POSTINC2 ; write ASCII code to output buffer | |
| 372 clrf INDF2 ; place a terminator at the current buffer position | |
| 373 return ; done | |
| 374 | |
| 375 | |
| 376 ;============================================================================= | |
| 377 convert3 CODE | |
| 378 ;============================================================================= | |
| 379 | |
| 380 | |
| 381 ;----------------------------------------------------------------------------- | |
| 382 ; Convert signed 16 Bit to unsigned 16 Bit and put a '-' into the buffer if negative | |
| 383 ; | |
| 384 ; Input / Output: mpr:2 | |
| 385 ; | |
| 386 global convert_signed_16bit | |
| 387 convert_signed_16bit: | |
| 388 bcf neg_flag ; clear flag for negative number by default | |
| 389 btfss hi,7 ; negative number? | |
| 390 return ; NO - done | |
| 391 bsf neg_flag ; YES - set flag for negative number | |
| 392 comf hi ; - complement hi:lo | |
| 393 negf lo ; - ... | |
| 394 btfsc STATUS,C ; - ... | |
| 395 incf hi ; - ... | |
| 396 movlw '-' ; - print a minus sign | |
| 36 movwf POSTINC2 ; - ... | 397 movwf POSTINC2 ; - ... |
| 37 return ; - done | 398 return ; - done |
| 38 | 399 |
| 39 | 400 |
| 40 global output99_call | 401 ;============================================================================= |
| 41 output99_call: | 402 convert4 CODE |
| 42 clrf ignore_digits | 403 ;============================================================================= |
| 43 incf ignore_digits,F | 404 |
| 44 clrf cvt_temp4 | 405 |
| 45 ;bra output99 | 406 ;----------------------------------------------------------------------------- |
| 46 | 407 ; Convert Pressure in [mbar] to Depth in [cm] |
| 47 | 408 ; |
| 48 global output99 | 409 ; Input: mpr:2 pressure [mbar] |
| 49 output99: | 410 ; Output: mpr:2 depth [cm] |
| 50 movlw d'99' | 411 ; Destroys: up |
| 51 cpfslt lo | 412 ; |
| 52 movwf lo ; limit to 99 | 413 global convert_pres_to_depth |
| 53 movff lo,cvt_temp_lo | 414 convert_pres_to_depth: |
| 54 clrf cvt_temp_hi | 415 btfsc sensor_override_active ; in pressure sensor override (simulator) mode? |
| 55 bcf pre_zero_flag ; do not display leading zeros | 416 return ; YES - convert with factor 1.0, i.e. make [mbar] = [cm] |
| 56 | 417 |
| 57 LCD_val99_2: | 418 movff opt_salinity,WREG ; get salinity setting (0 - 4 %, see option_table.asm) |
| 58 movlw .10 ; 10 | 419 addlw d'100' ; add density of fresh water (1.00 kg/l) |
| 59 movwf cvt_temp2 | 420 movwf up ; store salinity factor in up |
| 60 clrf cvt_temp3 | 421 |
| 61 rcall DEC2ASCII | 422 movlw .101+salinity_max ; load (upper limit + 1) |
| 62 | 423 cpfslt up ; current setting > upper limit? |
| 63 movlw .1 ; 1 | 424 bra convert_fix_salinity ; YES - fix salinity setting |
| 64 movwf cvt_temp2 | 425 |
| 65 clrf cvt_temp3 | 426 movlw .99+salinity_min ; load (lower limit - 1) |
| 66 bsf pre_zero_flag ; last figure, display zero (0) | 427 cpfsgt up ; current setting > lower limit? |
| 67 rcall DEC2ASCII | 428 bra convert_fix_salinity ; YES - fix salinity setting |
| 429 | |
| 430 convert_pres_to_depth_1: | |
| 431 MOVII mpr, xA ; get pressure in [mbar] | |
| 432 MOVLI .102,xB ; conversion factor x 100 for fresh water (1.02 cm per each 1 mbar) | |
| 433 call mult16x16 ; xC:4 = xA:2 * xB:2 | |
| 434 movff up,xB+0 ; get salinity in [%] | |
| 435 clrf xB+1 ; ... | |
| 436 call div32x16 ; xC:4 = xC:4 / xB:2 with xA as remainder | |
| 437 MOVII xC,mpr ; copy back result as depth in [cm] | |
| 68 return | 438 return |
| 69 | 439 |
| 70 global output99x_call | 440 convert_fix_salinity: |
| 71 output99x_call: | 441 movlw .100 ; reset to 100%, i.e. set salinity to 0% |
| 72 clrf ignore_digits | 442 movwf up ; fix value in up |
| 73 incf ignore_digits,F | 443 bra convert_pres_to_depth_1 ; continue |
| 74 clrf cvt_temp4 | 444 |
| 75 | 445 |
| 76 movlw d'99' | 446 ;============================================================================= |
| 77 cpfslt lo | 447 convert5 CODE |
| 78 movwf lo ; limit to 99 | 448 ;============================================================================= |
| 79 movff lo,cvt_temp_lo | 449 |
| 80 clrf cvt_temp_hi | 450 |
| 81 bsf pre_zero_flag ; display leading zeros | 451 ;----------------------------------------------------------------------------- |
| 82 bra LCD_val99_2 | 452 ; Convert Depth in [cm] to Depth in [feet] |
| 83 | 453 ; |
| 84 | 454 ; Input: mpr:2 depth in [cm] |
| 85 global output8_call | 455 ; Output: mpr:2 depth in [ft] |
| 86 output8_call: | 456 ; |
| 87 clrf ignore_digits | 457 global convert_cm_to_feet |
| 88 incf ignore_digits,F | 458 convert_cm_to_feet: |
| 89 clrf cvt_temp4 | 459 MOVII mpr, xA ; depth in [cm] |
| 90 | 460 btfsc sensor_override_active ; in pressure sensor override (simulator) mode? |
| 91 output8: | 461 bra convert_meter_to_feet_1 ; YES - convert with 334feet/100m |
| 92 movff lo,cvt_temp_lo | 462 MOVLI .328,xB ; NO - convert with 328feet/100m |
| 93 clrf cvt_temp_hi | 463 bra convert_common_to_feet ; - continue with common part |
| 94 bcf pre_zero_flag ; do not display leading zeros | 464 |
| 95 movlw .100 ; 100 | 465 |
| 96 movwf cvt_temp2 | 466 ;----------------------------------------------------------------------------- |
| 97 clrf cvt_temp3 | 467 ; Convert Depth in [m] to Depth in [feet] |
| 98 rcall DEC2ASCII | 468 ; |
| 99 bra LCD_val99_2 | 469 ; Input: lo depth in [m] |
| 100 | 470 ; Output: mpr:2 depth in [ft] |
| 101 | 471 ; |
| 102 global output16_4_call | 472 global convert_meter_to_feet |
| 103 output16_4_call: ; limit to 9999 | 473 convert_meter_to_feet: |
| 104 bsf show_last4 | 474 movf lo,W ; depth in [m] |
| 105 ; 9999 = 27 0F = [39][15] | 475 mullw .100 ; factor to convert [m] to [cm] |
| 106 movlw .40 | 476 MOVII PRODL,xA ; copy depth in [cm] to xA |
| 107 cpfslt hi ; hi < 40 ? | 477 convert_meter_to_feet_1: |
| 108 bra output16_4_call_2 ; NO - hi >= 40, do limit | 478 MOVLI .334, xB ; convert with 334feet/100m to have 10ft, 20ft, 30ft, ... for stop depths |
| 109 ; YES - hi <= 39 | 479 ;bra convert_common_to_feet ; continue with common part |
| 110 movlw .39 | 480 |
| 111 cpfseq hi ; hi = 39 ? | 481 |
| 112 bra output16_4_call_3 ; NO - hi < 39, no limit needed | 482 ;----------------------------------------------------------------------------- |
| 113 ; YES - hi = 39 | 483 ; Helper Function to convert_cm_to_feet and convert_meter_to_feet |
| 114 movlw .15 | 484 ; |
| 115 cpfslt lo ; lo < 15 | 485 convert_common_to_feet: |
| 116 movwf lo ; NO - lo >= 15, set lo = 15 | 486 call mult16x16 ; xC = xA * xB = depth in [cm] * 334 feet/100 m = depth in 0.0001 feet |
| 117 ; YES - lo <= 14 or lo set to =15 | 487 MOVLI .10000,xB ; divide by 10000 to turn into full feet |
| 118 bra output16_4_call_3 ; - done | 488 call div32x16 ; xC = xC / xB with xA as remainder |
| 119 | 489 MOVII xC,mpr ; store result |
| 120 output16_4_call_2: ; set to 9999 | 490 return ; done |
| 121 MOVLI .9999,mpr | 491 |
| 122 output16_4_call_3: | 492 |
| 123 bra output16_call | 493 ;============================================================================= |
| 124 | 494 convert6 CODE |
| 125 | 495 ;============================================================================= |
| 126 global output16_3_call | 496 |
| 127 global output16_call | 497 |
| 128 global output16 | 498 ;----------------------------------------------------------------------------- |
| 129 output16_3_call: ; limit to 999 | 499 ; Convert Temperature in Celsius to Fahrenheit |
| 130 bsf show_last3 | 500 ; |
| 131 ; Limit to 3 | 501 ; Input: mpr:2 temperature in [0.1 °C] |
| 132 movlw .4 | 502 ; Output: mpr:2 temperature in [0.1 °F] |
| 133 cpfslt hi | 503 ; |
| 134 bra output16_3_call_2 | 504 global convert_celsius_to_fahrenheit |
| 135 movlw .3 | 505 convert_celsius_to_fahrenheit: |
| 136 cpfseq hi ; = 3 ? | 506 MOVII mpr,xA ; temperature in 1/10 of °C |
| 137 bra output16_3_call_3 ; NO - done | 507 ADDLI .1000,xA ; add offset of 1000 to get out of any negative numbers |
| 138 movlw .231 ; limit to 231(+768=999...) | 508 ; adjust scaling: 1°C = 1.8°F: |
| 139 cpfslt lo | 509 MOVLI .18,xB ; multiply with 18: |
| 140 movwf lo | 510 call mult16x16 ; ... |
| 141 bra output16_3_call_3 ; done | 511 MOVLI .10,xB ; divide by 10 |
| 142 output16_3_call_2: ; set to .999 | 512 call div32x16 ; ... |
| 143 MOVLI .999,mpr | 513 SUBLI .1480,xC ; subtract above offset (1000 * 1.8 = 1800) and add Fahrenheit-Offset (32 * 10 = 320) => subtract 1480 |
| 144 output16_3_call_3: | 514 MOVII xC,mpr ; store result in mpr:2 |
| 145 output16_call: | 515 return ; done |
| 146 clrf ignore_digits | 516 |
| 147 incf ignore_digits,F | 517 |
| 148 clrf WREG | 518 ;============================================================================= |
| 149 output16: | 519 convert7 CODE |
| 150 movwf cvt_temp4 ; passed from output16dp macro, cleared by others. | 520 ;============================================================================= |
| 151 bcf all_zeros_flag ; do not display any zero from here unless there was at least one figure /zero | 521 |
| 152 bsf leading_zeros | 522 |
| 153 tstfsz cvt_temp4 ; display leading zeros at all? | 523 ;----------------------------------------------------------------------------- |
| 154 bcf leading_zeros | 524 ; Convert Minutes to Hours and Minutes / Seconds to Minutes and Seconds |
| 155 bsf DP_done2 | 525 ; |
| 156 tstfsz cvt_temp4 | 526 ; Input: hi:lo minutes / seconds |
| 157 bcf DP_done2 ; decimal point not yet set | 527 ; Output: up:hi hours / minutes |
| 158 movff lo,cvt_temp_lo ; copy hi:lo to cvt_temp_hi:cvt_temp_lo | 528 ; lo minutes / seconds |
| 159 movff hi,cvt_temp_hi ; ... | 529 ; |
| 160 bcf pre_zero_flag ; do not display leading zeros | 530 ; trashes xA, xB, xC |
| 161 movlw b'00010000' ; 10000s | 531 ; |
| 162 movwf cvt_temp2 | 532 global convert_time |
| 163 movlw b'00100111' | 533 convert_time: |
| 164 movwf cvt_temp3 | 534 movff lo,xA+0 ; copy hi:lo to xA |
| 165 btfsc show_last3 ; display only last three figures? | 535 movff hi,xA+1 ; ... |
| 166 bra output16_sk5 | 536 movlw d'60' ; set divisor to 60 |
| 167 btfsc show_last4 ; display only last four figures? | 537 movwf xB+0 ; write 60 to xB |
| 168 bra output16_sk5 | 538 clrf xB+1 ; ... |
| 169 rcall DEC2ASCII ; NO - show all, here: 5th order digit | 539 call div16x16 ; xC = xA / xB with xA as remainder |
| 170 | 540 movff xC+1,up ; result is hours / minutes, copy to up (high byte) |
| 171 output16_sk5: | 541 movff xC+0,hi ; result is hours / minutes, copy to hi (low byte) |
| 172 bcf show_last4 | 542 movff xA+0,lo ; remainder is minutes / seconds, copy to lo |
| 173 movlw b'11101000' ; 1000s | 543 return ; done |
| 174 movwf cvt_temp2 | 544 |
| 175 movlw b'00000011' | 545 |
| 176 movwf cvt_temp3 | 546 ;============================================================================= |
| 177 btfsc DP_done2 ; is there a decimal point at all? | 547 convert8 CODE |
| 178 bra output16_2 ; NO - use normal display mode | 548 ;============================================================================= |
| 179 | 549 |
| 180 btfsc all_zeros_flag ; display any zero from here | 550 |
| 181 bra output16_1 ; there was a figure /zero already | 551 ;----------------------------------------------------------------------------- |
| 182 | 552 ; Print full Date |
| 183 bsf pre_zero_flag ; display figure if zero? | 553 ; |
| 184 decfsz cvt_temp4,W | 554 ; Input: lo year |
| 185 bcf pre_zero_flag ; NO | 555 ; hi month |
| 186 | 556 ; up day |
| 187 output16_1: | 557 ; |
| 188 btfsc DP_done ; decimal point set already? | 558 ; Output format depends on value of option opt_dateformat: |
| 189 bsf pre_zero_flag ; YES - so display the rest | 559 ; 0: MM.DD.YY |
| 190 output16_2: | 560 ; 1: DD.MM.YY |
| 191 btfss show_last3 ; display only last three figures? | 561 ; 2: YY.MM.DD |
| 192 rcall DEC2ASCII ; NO - show all. Here: 4th order digit | 562 ; |
| 193 bcf show_last3 ; YES - so display the rest | 563 ; Destroyed: hy |
| 194 movlw b'01100100' ; 100s | 564 ; |
| 195 movwf cvt_temp2 | 565 global output_date |
| 196 clrf cvt_temp3 | 566 output_date: |
| 197 btfsc ignore_digit3 ; ignore 3rd-5th digit? | 567 movff opt_dateformat,EEDATA ; get format (EEDATA used as temp here) |
| 198 bra output16_5 ; YES - skip the rest | 568 tstfsz EEDATA ; shall use format 0 ? |
| 199 btfsc DP_done2 ; is there a decimal point at all? | 569 bra TFT_convert_date_1 ; NO - check for format 1 or 2 |
| 200 bra output16_3 ; NO - use normal display mode | 570 ; YES - use format 0: MM.DD.YY |
| 201 btfsc all_zeros_flag ; display any zero from here | 571 movff lo,hy ; - backup year to hy |
| 202 bra output16_2_1 ; there was a figure /zero already | 572 movff hi,lo ; - copy month to lo |
| 203 bsf pre_zero_flag ; display figure if zero? | 573 movff up,hi ; - copy day to hi |
| 204 decfsz cvt_temp4,W | 574 movff hy,up ; - copy year to up |
| 205 bcf pre_zero_flag ; NO | 575 bra TFT_convert_date_common ; - start output |
| 206 | 576 TFT_convert_date_1: |
| 207 output16_2_1: | 577 decfsz EEDATA,F ; shall use format 1 ? |
| 208 btfsc DP_done ; decimal point set already? | 578 bra TFT_convert_date_common ; NO - use format 2: YY.MM.DD - can print directly |
| 209 bsf pre_zero_flag ; YES - so display the rest | 579 ; YES - use format 1: DD.MM.YY |
| 210 btfsc DP_done2 ; is there a decimal point at all? | 580 movff lo,hy ; - backup year to hy |
| 211 bsf pre_zero_flag ; NO - so display the rest | 581 movff up,lo ; - copy day to lo |
| 212 output16_3: | 582 movff hy,up ; - copy year to up |
| 213 rcall DEC2ASCII ; 3th order digit... | 583 |
| 214 movlw b'00001010' ; 10s | 584 TFT_convert_date_common: |
| 215 movwf cvt_temp2 | 585 call output99x_call ; print lo (00-99) |
| 216 clrf cvt_temp3 | 586 PUTC '.' ; print spacing dot |
| 217 btfsc DP_done2 | 587 movff hi,lo ; print hi (00-99) |
| 218 bra output16_4 | 588 call output99x_call ; ... |
| 219 btfsc all_zeros_flag ; display any zero from here | 589 PUTC '.' ; print spacing dot |
| 220 bra output16_3_1 ; there was a figure /zero already | 590 movff up,lo ; print up (00-99) |
| 221 bsf pre_zero_flag | 591 call output99x_call ; ... |
| 222 decfsz cvt_temp4,W | 592 return ; done |
| 223 bcf pre_zero_flag | 593 |
| 224 | 594 |
| 225 output16_3_1: | 595 ;============================================================================= |
| 226 btfsc DP_done | 596 convert9 CODE |
| 227 bsf pre_zero_flag | 597 ;============================================================================= |
| 228 btfsc DP_done2 | 598 |
| 229 bsf pre_zero_flag | 599 |
| 230 output16_4: | 600 ;----------------------------------------------------------------------------- |
| 231 btfsc ignore_digit4 ; ignore 4-5th digit? | 601 ; Print Date by Month & Day |
| 232 bra output16_5 ; YES - skip the rest | 602 ; |
| 233 rcall DEC2ASCII ; 2nd order digit | 603 ; Input: hi month |
| 234 | 604 ; up day |
| 235 movlw b'00000001' ; 1s | 605 ; |
| 236 movwf cvt_temp2 | 606 ; Output format depends on value of option opt_dateformat: |
| 237 clrf cvt_temp3 | 607 ; 0: MM.DD |
| 238 bsf pre_zero_flag | 608 ; 1: DD.MM |
| 239 btfss ignore_digit5 ; ignore 5th digit? | 609 ; 2: MM.DD |
| 240 rcall DEC2ASCII ; 1st order digit | 610 ; |
| 241 bcf ignore_digit5 ; YES - clear flag | 611 ; Destroyed: lo |
| 242 output16_5: | 612 ; |
| 243 bcf ignore_digit4 ; clear flag | 613 global output_date_short |
| 244 bcf ignore_digit3 ; clear flag | 614 output_date_short: |
| 245 clrf ignore_digits | 615 movff opt_dateformat,EEDATA ; get format (EEDATA used as temp here) |
| 246 incf ignore_digits,F | 616 tstfsz EEDATA ; shall use format 0 ? |
| 247 bcf DP_done | 617 bra TFT_convert_date_short2 ; NO - check for format 1 or 2 |
| 248 return ; done with convert.asm... | 618 TFT_convert_date_short1: ; YES - use format 0: MMDD |
| 249 | 619 movff hi,lo ; - copy month to lo |
| 250 | 620 movff up,hi ; - copy day to hi |
| 251 DEC2ASCII: | 621 bra TFT_convert_date_short3 ; - start output |
| 252 clrf cvt_temp1 ; converts into ASCII code | 622 TFT_convert_date_short2: |
| 253 DEC2ASCII_2: | 623 decfsz EEDATA,F ; format 1 ? |
| 254 movf cvt_temp3,W | 624 bra TFT_convert_date_short1 ; NO - use format 2: MMDD (here its like format 0) |
| 255 subwf cvt_temp_hi,W | 625 ; YES - use format 1: DDMM |
| 256 btfss STATUS,C | 626 movff up,lo ; - copy day to lo, |
| 257 bra DEC2ASCII_4 | 627 ; - month is already in hi |
| 258 bnz DEC2ASCII_3 | 628 TFT_convert_date_short3: |
| 259 movf cvt_temp2,W | 629 call output99x_call ; print lo (00-99) |
| 260 subwf cvt_temp_lo,W | 630 PUTC '.' ; print spacing dot |
| 261 btfss STATUS,C | 631 movff hi,lo ; print hi (00-99) |
| 262 bra DEC2ASCII_4 | 632 call output99x_call ; ... |
| 263 DEC2ASCII_3: | 633 return ; done |
| 264 movf cvt_temp3,W | 634 |
| 265 subwf cvt_temp_hi,F | 635 |
| 266 movf cvt_temp2,W | 636 ;============================================================================= |
| 267 subwf cvt_temp_lo,F | 637 convert10 CODE |
| 268 btfss STATUS,C | 638 ;============================================================================= |
| 269 decf cvt_temp_hi,F | 639 |
| 270 incf cvt_temp1,F | 640 |
| 271 bsf pre_zero_flag | 641 global output_secs_as_days_hours |
| 272 bra DEC2ASCII_2 | 642 output_secs_as_days_hours: |
| 273 DEC2ASCII_4: | 643 MOVLI .3600,xB ; one hour = 3600s |
| 274 decfsz ignore_digits,F | 644 call div32x16 ; xC:4 = xC:4 / xB:2 with xA as remainder -> xC+1:xC+0 holds full hours |
| 275 return | 645 MOVII xC, xA ; transfer result to xA |
| 276 incf ignore_digits,F ; so ignore_digits stays zero for the test above | 646 MOVLI .24,xB ; one day = 24 hours |
| 277 movlw '0' ; offset for ASCII-value | 647 call div16x16 ; xC:2 = xA:2 / xB:2 with xA as remainder -> xC+1:xC+0 holds full days, xA holds full hours |
| 278 addwf cvt_temp1,W | 648 MOVII xC,mpr ; copy full days into hi:lo |
| 279 btfsc pre_zero_flag ; is this a leading zero? | 649 call output99_call ; print days (0-99) |
| 280 bra DEC2ASCII_4_1 ; NO | 650 PUTC "d" ; append unit |
| 281 btfsc leftbind | 651 movff xA+0,lo ; get full hours |
| 282 bra DEC2ASCII_6 | 652 call output99x_call ; print full hours (00-99) |
| 283 movlw ' ' ; instead of leading zeros a space! | 653 PUTC "h" ; append unit |
| 284 bra DEC2ASCII_5 | 654 return ; done |
| 285 DEC2ASCII_4_1: | 655 |
| 286 bsf all_zeros_flag ; display any zero from here | 656 |
| 287 DEC2ASCII_5: | 657 ;----------------------------------------------------------------------------- |
| 288 movwf POSTINC2 | |
| 289 DEC2ASCII_6: | |
| 290 decfsz cvt_temp4,F ; set decimal point? | |
| 291 RETURN ; NO | |
| 292 movlw "." ; YES | |
| 293 movwf POSTINC2 | |
| 294 bsf DP_done | |
| 295 return | |
| 296 | |
| 297 | |
| 298 global outputHEX_call | |
| 299 outputHEX_call: ; coverts 8 Bit integer into two hex digits | |
| 300 movwf cvt_temp1 ; copy byte to process from WREG to local temp | |
| 301 swapf cvt_temp1,F ; swap nibbles to process upper nibble first | |
| 302 rcall outputHEX_nibble ; print nibble as ASCII | |
| 303 swapf cvt_temp1,F ; swap back to process lower nibble | |
| 304 outputHEX_nibble: | |
| 305 movff cvt_temp1,cvt_temp2 ; create a working copy | |
| 306 movlw 0x0F ; mask for lower nibble | |
| 307 andwf cvt_temp2,F ; isolate lower nibble | |
| 308 movlw 0x30 ; offset from binary 0 to ASCII code for "0" | |
| 309 addwf cvt_temp2,F ; add offset | |
| 310 movlw 0x39 ; ASCII code for "9" | |
| 311 cpfsgt cvt_temp2 ; character code in cvt_temp2 pointing to something after "9"? | |
| 312 bra outputHEX_1 ; NO - character code represents "0"..."9", can be printed | |
| 313 movlw 0x07 ; YES - offset from ASCII code for character after "9" to character "A" | |
| 314 addwf cvt_temp2,F ; - add offset, character code now represents "A"..."F", can be printed now | |
| 315 outputHEX_1: | |
| 316 movff cvt_temp2,POSTINC2 ; copy character code to output buffer | |
| 317 return | |
| 318 | |
| 319 | 658 |
| 320 END | 659 END |
