Hallo,

ich habe gerade ein bisschen mit meinem ATMega32 rumgespielt. Und zwar habe ich an den PA0 ein 25k-Poti als einstellbaren Spannungsteiler angeschlossen.
Der Wert wird eingelesen und dann auf das angeschlossene LCD ausgegeben, also zwischen 0 (=0V) und 1023 (=5V). Das funktioniert auch soweit.
Nur wollte ich jetzt das Programm erweitern, dass der Wert umgerechnet wird, sodass anstatt 1023 5,00V angezeigt wird.
Irgendwie klappt aber das Umwandeln der Variablen nicht,
kann mir da jemand von Euch weiterhelfen, bin noch ein Noob...

Code:
'--------------------------------------------------------------------
'                  ADC_INT.BAS
'  demonstration of GETADC() function in combintion with the idle mode
'  for a better noise immunity
'  Getadc() will also work for other AVR chips that have an ADC converter
'--------------------------------------------------------------------
$regfile = "m32def.dat"                                     'ATMega32
$crystal = 12000000                                         'Quarz 12 MHz
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.3 , Rs = Portc.2
Config Lcd = 20 * 4                                         ' LCD mit 4 Zeilen und 20 Zeichen pro Zeile

'configure single mode and auto prescaler setting
'The single mode must be used with the GETADC() function

'The prescaler divides the internal clock by 2,4,8,16,32,64 or 128
'Because the ADC needs a clock from 50-200 KHz
'The AUTO feature, will select the highest clockrate possible
Config Adc = Single , Prescaler = Auto
'Now give power to the chip
On Adc Adc_isr Nosave
Enable Adc
Enable Interrupts


Dim W As Word , V As Double , Spannung As Double , Channel As Byte

Channel = 0
'now read A/D value from channel 0

Cls

Do
  Channel = 0
  'idle will put the micro into sleep.
  'an interrupt will wake the micro.
  Start Adc
  Idle
  Stop Adc
  Locate 1 , 1                                              'springe in 1.Zeile 1.Spalte
  Cls                                                       'Clear Screen vom LCD
  Lcd "Channel " ; Channel ; " value " ; W                  'Ausgabe aufs LCD
  V = W                                                     'Variablenwert von W in V übertragen
  Spannung = V / 204.6                                      'umrechnen, damit 1023 5V entspricht
  Lowerline                                                 'springe in 2. Zeile
  Lcd "Spannung: " ; Spannung ; "V"                         'Ausgabe aufs LCD
  Waitms 500
Loop
End

Adc_isr:
  push r24
  in r24,sreg
  push r24
  push r25
  W = Getadc(channel)
  pop r25
  pop r24
  !out sreg,r24
  pop r24
Return
MfG, Dane