HARIS RASHID
Newbie level 4
hi
i have problem in adc part in pic 18f4520.my code is not working mean that when i vary the input analog voltage outputs are not change.can anyone help me plz
Device = 18F4520
Xtal=20
LCD_DTPin PORTD.4
LCD_RSPin PORTD.3
LCD_ENPin PORTD.2
Adin_Res 10 ' Set the resolution to 10
Adin_Tad FRC ' Choose the RC osc for ADC samples
Adin_Stime 100 ' Allow 100us for charge time
ADCON1 = %00001101 ' Set PORTA analog and right justify result
ADCON2=%10000111
Input PORTA.1
Dim raw As Word
Dim v As Float
Print Cls
Loop:
raw=ADIn 1
Print At 1,1,"Raw:", Dec4 raw
v=(5/1023)* raw
Print At 2,1,"volt:", Dec3 v
DelayMS 2000
GoTo Loop
Symbol LED1 = PORTD.0 'Pin where data is to be transmitted
Symbol LED2= PORTD.1
While 1 = 1 ' Loop forever
If raw< 256 Then '25% of Vdd
High LED2
Low LED1
ElseIf raw >256 And raw <1024 Then '50% of Vdd
High LED1
Low LED2
Else
Low LED2
Low LED1
EndIf
DelayMS 500 ' Wait for .5 second
Wend
i have problem in adc part in pic 18f4520.my code is not working mean that when i vary the input analog voltage outputs are not change.can anyone help me plz
Device = 18F4520
Xtal=20
LCD_DTPin PORTD.4
LCD_RSPin PORTD.3
LCD_ENPin PORTD.2
Adin_Res 10 ' Set the resolution to 10
Adin_Tad FRC ' Choose the RC osc for ADC samples
Adin_Stime 100 ' Allow 100us for charge time
ADCON1 = %00001101 ' Set PORTA analog and right justify result
ADCON2=%10000111
Input PORTA.1
Dim raw As Word
Dim v As Float
Print Cls
Loop:
raw=ADIn 1
Print At 1,1,"Raw:", Dec4 raw
v=(5/1023)* raw
Print At 2,1,"volt:", Dec3 v
DelayMS 2000
GoTo Loop
Symbol LED1 = PORTD.0 'Pin where data is to be transmitted
Symbol LED2= PORTD.1
While 1 = 1 ' Loop forever
If raw< 256 Then '25% of Vdd
High LED2
Low LED1
ElseIf raw >256 And raw <1024 Then '50% of Vdd
High LED1
Low LED2
Else
Low LED2
Low LED1
EndIf
DelayMS 500 ' Wait for .5 second
Wend