$regfile = "m128def.dat"
$crystal = 4000000
Config Graphlcd = 240 * 64 , Dataport = Porta , Controlport = Portc , Ce = 2 , Cd = 3 , Wr = 0 , Rd = 1 , Reset = 4 , Fs = 5 , Mode = 6
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
'Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Up , Prescale = 1
Cls
Cursor Off
Dim Volt As Single
Dim W As Word
Dim X As Integer
Dim Ly As Integer
Dim Lly As Integer
Dim Lx As Integer
Dim Llx As Integer
Dim Lf As Single
Dim Dw As Single
Dim T As String * 10
Dim Alo As Single
Dim Ahi As Single
Dim Trg As Integer
Dim Tcnt As Integer
Config Portd.0 = Input
Config Portd.1 = Input
Config Portd.2 = Input
Dim A As Integer
Lf = 5 / 53
Dw = 5 / 1023
Lx = 3
Llx = 3
Lly = 0
Alo = 5
Ahi = 0
Trg = 0
Tcnt = 10
' FRAME ON LCD
Line(1 , 1) -(239 , 1) , 255
Line(1 , 102) -(239 , 102) , 255
Line(1 , 1) -(1 , 102) , 255
Line(239 , 1) -(239 , 102) , 255
Locate 3 , 3
Lcd " TEST AVR ADC VOLT"
Wait 1
Cls Text
Do
:
If Tcnt >= Trg Then
' Write pos
X = Lx - 1
Line(x , 106) -(x , 108) , 0
'adc use for input
' Write one
W = Getadc(0)
Volt = W * Lf
Ly = Int(volt) '*********** Ly is the add line Y to lcd
Volt = W * Dw
Volt = Volt + 10
If Volt > Ahi Then 'VOLT HIGH
Ahi = Volt
End If
If Volt < Alo Then 'VOLY LOW
Alo = Volt
End If
Ly = 100 - Ly
If Lly = 0 Then
Lly = Ly
End If
Line(llx , Lly ) -(lx , Ly) , 255
T = Fusing(volt , "#.###")
Locate 15 , 1 : Lcd "V " ; T
T = Fusing(ahi , "#.###")
Locate 15 , 21 : Lcd "HI " ; T
T = Fusing(alo , "#.###")
Locate 15 , 31 : Lcd "LO " ; T
Lly = Ly
' Set last X and incr LcdX
Llx = Lx
Incr Lx
' Wipe out One
X = Lx
Line(x , 2) -(x , 100) , 0
Incr X
Line(x , 2) -(x , 100) , 0
' End of track ?
If Lx > 236 Then
Lx = 3
Llx = 3
End If
Tcnt = 0
End If
Incr Tcnt
Debounce Pind.0 , 1 , Trgu , Sub 'trigger up button
Debounce Pind.1 , 1 , Trgd , Sub 'trigger down button
Debounce Pind.2 , 1 , Rehilo , Sub 'reset high low button
Loop
' TRIGGER SPEED
Trgu:
Trg = Trg + 100
Locate 15 , 1 : Lcd "TRIG " ; " "
Locate 15 , 1 : Lcd "TRIG " ; Trg
Return
Trgd:
Trg = Trg - 100
If Trg < 0 Then Trg = 0
Locate 15 , 1 : Lcd "TRIG " ; " "
Locate 15 , 1 : Lcd "TRIG " ; Trg
Return
Rehilo:
Alo = 15
Ahi = 0
Return
|