yes this works!
I tried to make a working program that will show exact digital binary value of RA2 pin onto LCD but I don't know why the below source code doesn't work.
Code: Select all
//NOTE
//put jumper J1 to pull down position
//turn off DIP switch RA3
//put jumper on RA2 of A/D converter
program AD_converter;
label start;
var x,y:array[1..10] of word; //from 0-65,536
i:byte;
begin
ANSEL := %00000100; // Configure AN2 pin as analog
ANSELH := 0; // Configure other AN pins as digital I/O
TRISA := $FF; // PORTA is input
Lcd_Config(PORTB,3,2,1,0,PORTB,4,7,5); //Initializes LCD data port and ctrl port with pin settings you specify.
LCD_out(2,1,'RA2 dig value'); //writes "RA2 dig value
start:
y[10] := Adc_Read(2); // Get 10-bit digital value from RA2 analog pin
for i:=10 to 1 do
begin
x[i]:=y[i] mod 2;
y[i-1]:=y[i] div 2;
end;
for i:=1 to 10 do
if x[i]=1 then LCD_Out(1,i,'1') else LCD_Out(1,i,'0'); //show value on LCD
goto start;
end.
However the AD converter does work, as I tested it with this simplified version.
Code: Select all
//NOTE
//put jumper J1 to pull down position
//turn off DIP switch RA3
//put jumper on RA2 of A/D converter
program AD_converter;
label start;
var a: word; //from 0-65,536
i:word;
begin
ANSEL := %00000100; // Configure AN2 pin as analog
ANSELH := 0; // Configure other AN pins as digital I/O
TRISA := $FF; // PORTA is input
Lcd_Config(PORTB,3,2,1,0,PORTB,4,7,5); //Initializes LCD data port and ctrl port with pin settings you specify.
LCD_out(2,1,'RA2 dig value'); //writes "RA2 dig value" onto 2nd line of LCD
start:
a := Adc_Read(2); // Get 10-bit digital value from RA2 analog pin
if (a<%0000000011) and (a>%0000000010) then LCD_out(1,1,'%0000000010');
if (a<%0000000111) and (a>%0000000100) then LCD_out(1,1,'%0000000100');
if (a<%0000001111) and (a>%0000001000) then LCD_out(1,1,'%0000001000');
if (a<%0000011111) and (a>%0000010000) then LCD_out(1,1,'%0000010000');
if (a<%0000111111) and (a>%0000100000) then LCD_out(1,1,'%0000100000');
if (a<%0001111111) and (a>%0001000000) then LCD_out(1,1,'%0001000000');
if (a<%0011111111) and (a>%0010000000) then LCD_out(1,1,'%0010000000');
if (a<%0111111111) and (a>%0100000000) then LCD_out(1,1,'%0100000000');
if (a<%1111111111) and (a>%1000000000) then LCD_out(1,1,'%1000000000');
goto start;
end.