Displaying Memory Values on the LCD

A Dr. Taylor Tutorial

Binary to ASCII Conversions

       andi   r20, 0x0f
  masks the upper nibble to produce 0x05 = 0b00000101.
* Next we need to add 0x30 (since '0' = 0x30):
       subi   r20, -'0'
       cpi    r20, '9' + 1
       brlo   done
       subi   r20, -7
done:
       ret

Example Program

Flowchart for Conversion Function

Flowchart for Function that Converts a Nibble to an ASCII value

; Converts lower nibble of r20 into its ASCII equivalent
; The result is stored in r20
convert_lower_nibble:
       andi   r20, 0x0f     ; masking: clear upper nibble
       ; Convert to ASCII
       subi   r20, -'0'     ; add '0' to r20
       ; Correct conversion if digit is greater than '9'
       cpi    r20, '9' + 1
       brlo   done
       subi   r20, -7
done:
       ret

Tutorials for Other Courses

Additional Links

Site Mirror

This is a mirror to be used when http://myweb.msoe.edu/taylor/, (EDU instead of US) is not available.