hallo allemaal
Ik zoek een stukje software om een hex woord (bv ff)
op een display te zetten als 255. Dus omzetting van hex naar dec.
Ik moet dus uiteindelijk 3 ascii woorden krijgen 32, 35 en 35.
Zo ook h10 als 16 op een display.
Ik werk graag in assambler. wie kan me helpen
Joop
Arco
Special Member
Arco - "Simplicity is a prerequisite for reliability" - hard-, firm-, en software ontwikkeling: www.arcovox.com
Had dit nog liggen:
disp_asc: clrf digit
movwf temp
disp_asc_lp movlw d'10'
subwf temp,w
btfss status,c
goto disp_asc_2
movwf temp
incf digit,f
goto disp_asc_lp
disp_asc_2 swapf digit,f
movf temp,w
xorwf digit,f
swapf digit,w
andlw 0x0F
iorlw 0x30
call ShowTheDigitInLcd ;Lcd routine
movf digit,w
andlw 0x0F
iorlw 0x30
call ShowTheDigitInLcd ;Lcd routine
return
Verandert een waarde van 00 tot 99 in "00" tot "99" op een LCD display
(Voor 255 / 3 digits nog wat aan te passen)
bedankt voor je reactie.
Dit zoek ik eigenlijk niet. Ik heb bv hex ff.
Dit moet eerst uit elkaar getrokken worden in 5 eenheden, 5 tientallen en 2 honderdtallen.
hier wil ik dan Hex 30 bij optellen en dan heb ik de ascii notatie.
Het is de bedoeling dat ik een voedings spanning op het display wil hebben van ""12.5"" volt.
De A/D meting werkt, de display aansturing werkt maar hier kom ik niet aan uit.
Joop
Arco
Special Member
Arco - "Simplicity is a prerequisite for reliability" - hard-, firm-, en software ontwikkeling: www.arcovox.com
Zoals ik al zei, zie mijn voorbeeld boven. Moet alleen uitgebreid worden tot 3 digits. (Nu tot max. 99 = 0x63, omdat er nu eenmaal niet meer in 2 digits gaat
). Als ik nog tijd heb zal ik kijken of ik 't kan aanpassen...
Zo iets dus:
;------------------------------------------------------------------------
;BYTE TO ASCII CONVERSION
;------------------------------------------------------------------------
B2A_table addwf PCL,f ; add index to program counter
retlw 0x64 ; 100 decimal
retlw 0x0a ; 10 decimal
;-----------------------------------------------------------------------
BYT2ASC movwf B2A_number
movlw 0x30 ; init result with ASCII '0'
movwf B2A_hund
movwf B2A_ten
movwf B2A_one
clrf B2A_index ; init work registers
clrf B2A_dig_ctr
B2A_subtr movf B2A_index,w ; get current index into W
call B2A_table ; get chunk for subtraction
subwf B2A_number,f
btfsc STATUS,C ; test carry flag
goto B2A_incdig
movlw B2A_RESULT ; load base address of table
movwf FSR
movf B2A_index,w ; get index
addwf FSR,f ; add offset
movf B2A_dig_ctr,w ; get digit counter contents
addwf INDF,f ; add to '0' at digit loc (indexed)
movf B2A_index,w ; get index
call B2A_table ; get chunk for addition
addwf B2A_number,f ; add back
movf B2A_index,w ; get index
sublw 0x01 ; index = 1
btfsc STATUS,Z
goto B2A_finish
incf B2A_index,f
clrf B2A_dig_ctr
goto B2A_subtr
;------------------------------------------
B2A_incdig incf B2A_dig_ctr,f ; increment digit counter
goto B2A_subtr
;------------------------------------------
B2A_finish movf B2A_number,w ; get 1's = remainder
addwf B2A_one,f ; add to '0'
return ; done
;------------------------------------------------------------------------
;END BYTE TO ASCII CONVERSION
;------------------------------------------------------------------------
Hou er rekening mee dat de B2A_TABLE in de eerste code pagina terechtkomt, anders moet je PCLATH goed zetten. Ik moet ook nog een versie hebben die die tabel niet nodig heeft, maar die kon ik zo gauw niet vinden.
Arco
Special Member
Arco - "Simplicity is a prerequisite for reliability" - hard-, firm-, en software ontwikkeling: www.arcovox.com
Dit zou het moeten doen:
disp_asc: movwf temp
movlw digit3
movwf fsr
movlw d'100'
call disp_subt
movlw d'10'
call disp_subt
movlw d'1'
disp_subt movwf subval
movlw 0x30
movwf indf
disp_asc_lp movf subval,w
subwf temp,w
btfss status,c
goto disp_s_ret
movwf temp
incf indf,f
goto disp_asc_lp
disp_s_ret incf fsr,f
return
Bij start moet de byte waarde in W staan, resultaat is in digit3, 2, 1 (resp. honderd,tiental,eenheid)
Digit 3, 2, 1 moeten opeenvolgende geheugenplaatsen zijn.