hello:

I have written code to take a 16 bit number (in bytes nh, nl) & convert to 5 characters of ASCII to send out via the UART. The code shown is not yet fully tested. Is there a simplers/easier/more compact way to do this? I haven't seen any. I looked around a bit (no pun) & only saw a few routines that proided packed BCD. I want separate bytes & a short program. Any thoughts on bettering this are appreciated...note this is untested as my debug session is just starting.

Also, is there a "quicker" way to test a word against a specified value (say $ABCD)...I didn't see anything useful in the AVR. Loved those 8096 days!

Hoyt Clagwell

; 16 bit binary to 5 digit ASCII conversion ; the 16 bit value is in bytes nh & nl ; each of the 5 ascii digits is stored (sent) to a separate memory located (UART xmt buffer) ;NOTE---the data storage is not yet in this code ;NOTE this code has not been fully tested (but is about to be) ; 10000 base 10=$2710, 1000 base 10 =$03E7, 100 base 10=0064, 10 base 10= $000A ; clr temp ;digit count ldi temp2, $30 ;ASCII conversion value (number to char) loop10k: cpi nh,$27 brlo end10k ;if too low, <10000 brpl ok10k ;if more>10000 do subtract cpi nl,$10 ;if msd's equal, compare lsd's brlo end10k ok10k: subi nl, $10 ;subtract 10000 sbci nh,$27 inc temp ;count up 10k "counts" rjmp loop10k end10k: add temp,temp2 ;convert to ASCII ;do store 10k char now clr temp ;reset digit conversion count loop1k: cpi nh,$03 brlo end1k ;if too low, <1000 brpl ok1k ;if more>1000 do subtract cpi nl,$E8 ;if msd's equal, compare lsd's brlo end1k ok1k: subi nl, $E8 ;subtract 1000 sbci nh,$03 inc temp ;count up 1k "counts" rjmp loop1k end1k: add temp,temp2 ;convert to ASCII ;do store 1k digit clr temp ;reset digit conversion count loop100: cpi nh,$00 brlo end100 ;if too low, <100 brpl ok100 ;if more>100 do subtract cpi nl,$64 ;if msd's equal, compare lsd's brlo end100 ok100: subi nl, $64 ;subtract 100 sbci nh,$00 inc temp ;count up 100's "counts" rjmp loop100 end100: add temp,temp2 ;convert to ASCII ;do store 100's digit clr temp ;reset digit conversion count loop10: cpi nh,$00 brlo end10 ;if too low, <10 brpl ok10 ;if more>10 do subtract cpi nl,$0A ;if msd's equal, compare lsd's brlo end10 ok10: subi nl, $0A ;subtract 10 sbci nh,$00 inc temp ;count up 10's "counts" rjmp loop10 end10: add temp,temp2 ;convert to ASCII ;do store 10's digit add nl,temp2 ;convert 1's digit to ASCII ;do store 1's digit (value held by nl) wait4evr: rjmp wait4evr