Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

need sample code for adc turnon and conversion to shows on lcd for pic 16f877a

Status
Not open for further replies.

peter002

Member level 3
Joined
Mar 18, 2013
Messages
56
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Hindusthaan
Activity points
1,765
helo everyone. i m trying to use the ad feature of the pic to show the conversion result on the lcd, i using microc pro for programming and the software shows 3 commans in ad header file that are adc_init, adc_read and adc_sample_read

but using these commands i m getting nothing on the lcd
below is the code i tried
sbit lcd_rs at rc0_bit;
sbit lcd_en at rc1_bit;
sbit lcd_d7 at rb7_bit;
sbit lcd_d6 at rb6_bit;
sbit lcd_d5 at rb5_bit;
sbit lcd_d4 at rb4_bit;
sbit lcd_d3 at rb3_bit;
sbit lcd_d2 at rb2_bit;
sbit lcd_d1 at rb1_bit;
sbit lcd_d0 at rb0_bit;

sbit lcd_rs_direction at trisc0_bit;
sbit lcd_en_direction at trisc1_bit;
sbit lcd_d7_direction at trisb7_bit;
sbit lcd_d6_direction at trisb6_bit;
sbit lcd_d5_direction at trisb5_bit;
sbit lcd_d4_direction at trisb4_bit;
sbit lcd_d3_direction at trisb3_bit;
sbit lcd_d2_direction at trisb2_bit;
sbit lcd_d1_direction at trisb1_bit;
sbit lcd_d0_direction at trisb0_bit;

char txt1[]="Mohit";

char txt2[]="Akash anand";

char i;
int x;
void main()
{
lcd_init();
lcd_cmd(_lcd_clear);
lcd_cmd(_lcd_cursor_off);

trisa=0xff;
adc_init();
delay_ms(50);
adcon1=0x00;
adcon0=0b10000000;
go_bit=1;
while(go_bit==1)
{
}

x= adc_get_sample(0);
lcd_out(1,3,"x=");
}
}
lcd working ok, and i know i hav a lot of mistakes in that code, indeed i m an assembler, and in assembly i hav done that successfuly, but i wanna try in c now, plz hlp..
thanc in advance
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
Why are you using 8 bit LCD code. mikroC PRO PIC comes with 4 bit LCD library. Where did you get the 8 bit LCD library for mikroC PRO PIC ? LCD 8 bit library comes with mikroC not mikroC PRO.

- - - Updated - - -

Try this mikroC PRO PIC code.

 

Attachments

peter002

Member level 3
Joined
Mar 18, 2013
Messages
56
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Hindusthaan
Activity points
1,765
well, i use 8 bit mode because it has a bit faster speed that 4 bit mode, and even in the 8bit mode the lcd is working fine.. thanx for the code, i m chking it...

- - - Updated - - -

your code seems very simple and clean bro, can u plz xplain me the meaning of folowing code lines?? thanx in advance
Code:
FloatToStr(adcVal, str);
                    Ltrim(str);
 

yag1064

Newbie level 1
Joined
May 22, 2015
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
6
Good Morning,
Your C program seems to have a flaw. You have an uneven number of {} these. That means your program may have compiled but the action is uncertain. The last } looks like an orphan. Where does the program counter go after the last command statement? Try putting a while(1){}; after lcd_out line. Good luck.
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
FloatToStr() converts floating point value to string for LCD printing. Ltrim() removes the leading spaces in the string.
 
Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top