'ATmega32, AD-Wandler dB-Meter 40...120 dBµV
$regfile = "m32def.dat"
$crystal = 11059200
$hwstack = 16
$swstack = 32
$framesize = 32
Baud = 9600
Dim N As Integer
Dim D As Integer
Dim Dd As Long
Dim Db As Single
Dim Bereich As Byte
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.3 , Rs = Portb.2
Config Lcd = 16 * 2
Initlcd
Cls
Locate 1 , 1
Lcd "AD"
Config Adc = Single , Prescaler = 64 , Reference = Internal
Start Adc
Waitms 1000
Cls
Bereich = 1
Do
If Bereich = 1 Then
Dd = 0
For N = 1 To 1000
D = Getadc(11) ' (ADC1-ADC0)*200
If D > 512 Then
D = D - 1024
End If
D = Abs(d)
Dd = Dd + D
Next N
Dd = Dd / 33
If Dd > 5000 Then Bereich = 2
End If
If Bereich = 2 Then
Dd = 0
For N = 1 To 1000
D = Getadc(9) ' (ADC1-ADC0)*10
If D > 512 Then
D = D - 1024
End If
D = Abs(d)
Dd = Dd + D
Next N
Dd = Dd / 33
If Dd > 5000 Then Bereich = 3
If Dd < 300 Then Bereich = 1
Dd = Dd * 20
End If
If Bereich = 3 Then
Dd = 0
For N = 1 To 1000
D = Getadc(16) ' (ADC0-ADC1)*1
If D > 512 Then
D = D - 1024
End If
D = Abs(d)
Dd = Dd + D
Next N
Dd = Dd / 33
If Dd < 300 Then Bereich = 2
Dd = Dd * 200
End If
Locate 1 , 1
Lcd Dd
Lcd " uV "
Lcd Bereich
Lcd " "
Db = Dd
Db = Log10(db)
Db = Db * 20
Locate 2 , 1
Dd = Db
Lcd Dd
Lcd " dBuV "
Waitms 1000
Loop
End