Device = 18F4520
Clock = 20
Include "adc.bas"
Include "Utils.bas"
Include "usart.bas"
Include "convert.bas"
Dim value As Word
#option USART_BRGH = True
TRISA = %00000001
ADC.SetConfig($0E) // set ADCON1 for AN0 analog, rest digital
SetBaudrate(br9600)
While true
Select ADC.Read(0)
Case <50
Write("No button",13,10)'no button pressed
DelayMS (200)
Case <150 ' ideal=92
Write("button1",13,10) 'button 1 pressed
DelayMS (200)
Case <250 ' ideal=185
Write("button2",13,10) 'button 2 pressed
DelayMS (200)
Case <350 'ideal=278
Write("button3",13,10) 'button 3 pressed
DelayMS (200)
Case <450 'ideal=371
Write("button4",13,10) 'button 4 pressed
DelayMS (200)
Case <550 'ideal=464
Write("button5",13,10)'button 5 pressed
DelayMS (200)
Case <650 'ideal=557
Write("button6",13,10) 'button 6 pressed
DelayMS (200)
Case <750 'ideal=650
Write("button7",13,10) 'button 7 pressed
DelayMS (200)
Case <850 'ideal=743
Write("button8",13,10) 'button 8 pressed
DelayMS (200)
Case <950 'ideal=836
Write("button9",13,10) 'button 9 pressed
DelayMS (200)
Case <1050 'ideal=929
Write("button10",13,10) 'button 10 pressed
DelayMS (200)
Else
'something is wrong
End Select
DelayMS (1000)
Wend