;************************************************************************* ;* subroutine: convert 16bit-word -> decimal -> ASCII -> plot HPGL ;************************************************************************* DecOut: rcall Div10 ; get "ones" digit ori Temp1,$30 ; convert to ASCII mov D0001,Temp1 ; and save it rcall Div10 ; get "tens" digit ori Temp1,$30 ; convert to ASCII mov D0010,Temp1 ; and save it rcall Div10 ; get "hundreds" digit ori Temp1,$30 ; convert to ASCII mov D0100,Temp1 ; and save it rcall Div10 ; get "thousands" digit tst Temp1 ; omit leading zero breq DecOu1 ; ori Temp1,$30 ; convert to ASCII rcall Serout ; print thousands DecOu1: mov Temp1,D0100 ; fetch hundreds rcall Serout ; and print it mov Temp1,D0010 ; fetch tens rcall Serout ; and print it mov Temp1,D0001 ; fetch ones rcall Serout ; and print it ret ; ;************************************************************************* ;* Subroutine: divide 16bit word in TempH/TempL by 10, ;* results: quotient in TempH/TempL, remainder in Temp1 = decimal digit ;* taken from "Trampert, AVR-Mikrocontroller" Franzis ISBN.... pg... ;************************************************************************* Div10: push Cnt ; clr Temp1 ; lsl TempL ; input word is shifted out to the left rol TempH ; filled up with zeroes from the right rol Temp1 ; lsl TempL ; rol TempH ; most significant 3 bits are always < 10 rol Temp1 ; so just shift out and in via Cy 3 times lsl TempL ; rol TempH ; rol Temp1 ; ldi Cnt,13 ; start loop for next 13 bits Div10a: lsl TempL ; rol TempH ; rol Temp1 ; subi Temp1,10 ; remainder >10 ? -> subtract 10 brlo Div10b ; was <10, LSB of output word = 0 inc TempL ; LSB of output word = 1 rjmp Div10c Div10b: subi Temp1,-10 ; back to old value <10 Div10c: dec Cnt ; next bit brne Div10a ; pop Cnt ; ret ;