Forum: Mikrocontroller und Digitale Elektronik Umwandlung


von Meglios Kraisis (Gast)


Lesenswert?

Hallo!
Habe ein Problem wuerde gerne eine 8bit Zahl mit dem Atmega8 in
Assembler in eine dec Zahl umwandeln und dann in Zehnerstellen
zerstueckeln. ZB 11111111=256 und daraus dann eine 2 eine 5 und eine 6
machen.
Wuerde die Ziffern dann gerne irgendwo zum  weiterverarbeiten speichern
wollen.
Bedanke mich vorraus fuer Eure Hilfe!

von michi (Gast)


Angehängte Dateien:

Lesenswert?

bitte schön!

von Matthias (Gast)


Lesenswert?

Hi

also das ein AVR einen DIV-Befehl hat ist mir neu. Ist mir das was
entgangen oder ist das MCS51?

Matthias

von Tobi (Gast)


Lesenswert?

hab ich auch noch nicht gesehen...

möglichkeit1:
;input: ADC result left aligned with AREF set to 5V r16(low byte),
r17(high byte)
;output: Voltage between 0 and 5V at memory location 0x60 to 0x62 =
digits '0' ... '9'
; 21 Words
; CPU cycles: 24



ADCResult2ASCII:
  ldi r25, '0'
  ldi r23, 5
  mul r17, r23
  mov r17, r0
  add r1, r25    ; convert number to ASCII
  sts 0x60, r1
  mul r16, r23
  mov r16, r0
  add r17, r1
  ldi r23, 10

  mul r17, r23
  mov r17, r0
  add r1, r25
  sts 0x61, r1

  mul r17, r23
  add r1, r25
  sts 0x62, r1

  ret

***** möglichkeit 2:
;*********************************************************************** 
*
;*                  *
;*      binary to bcd conversion      *
;*                  *
;*********************************************************************** 
*
;input: a1, a0 = 16 bit value 0 ... 65535
;output: a4, a3, a2, a1, a0 = digits '0' ... '9'
;cycle: 27 .. 183
;bytes:  42
;
binbcd:
  ldi  a4, -1 + '0'    ;Preload for ASCII output
_bib1:  inc  a4
  subi  a0, low(10000)    ;substract 10000
  sbci  a1, high(10000)
  brcc  _bib1      ;until value negative

  ldi  a3, 10 + '0'
_bib2:  dec  a3
  subi  a0, low(-1000)    ;add 1000
  sbci  a1, high(-1000)
  brcs  _bib2      ;until value positive

  ldi  a2, -1 + '0'
_bib3:  inc  a2
  subi  a0, low(100)    ;substract 100
  sbci  a1, high(100)
  brcc  _bib3      ;until value negative

  ldi  a1, 10 + '0'
_bib4:  dec  a1
  subi  a0, -10      ;add 10
  brcs  _bib4      ;until value positive

  subi  a0, -'0'    ;convert remaining ones to ASCII
  ret

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.