Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

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
 

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.

broken link removed
 

Attachments

  • ADC.rar
    83.9 KB · Views: 85
  • adc.png
    adc.png
    36 KB · Views: 118
Last edited by a moderator:
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);
 

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.
 

FloatToStr() converts floating point value to string for LCD printing. Ltrim() removes the leading spaces in the string.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top