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.

VOLTMETER using pic18f4550....Help needed

Status
Not open for further replies.

waseem309

Newbie level 3
Joined
Jan 12, 2013
Messages
3
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,332
i need help in this code///nothing is displayed on LCD //




#include <p18F4550.h>
#define lcdport PORTB
#define rs PORTAbits.RA0
#define rw PORTAbits.RA1
#define en PORTAbits.RA2


void lcd_ini() ;
void lcdcmd(unsigned char) ;
void lcddata(unsigned char);
void adc_con(unsigned int) ;
void adc_init();
void DELAY(int time);

unsigned char data[20]="ADC OUTPUT=";
unsigned int digital_out[10],avg_output=0,temp;
unsigned int i=0;
void main()
{
TRISCbits.TRISC0=0;
TRISA=0; // Configure RA0 as input pin
PORTA=0;
TRISB=0;
PORTB=0; // Configure Port B as output port


lcdcmd(0x38); // Configure the LCD in 8-bit mode, 2 line and 5x7 font
lcdcmd(0x0E); // Display On and Cursor Off
lcdcmd(0x01); // Clear display screen
lcdcmd(0x06); // Increment cursor
lcdcmd(0x86); // Set cursor position to 1st line, 1st column
lcddata('w');

while(data!='\0')
{
lcdport=*data; // Call lcddata function to send character one by from 'data' array
i++;
}

ADCON1=0xCE; // Make RA0/AN0 pin as analog pin (Other pins remain to be digital I/O)
ADCON0=0x81; // Select Channel0 & ADC off
ADCON2=0x8A; // Left justified, 2TAD acquiciation time, Fosc/32 clock option
ADCON0bits.GO=1; // Enable ADC

while(1)
{
temp=0;
for(i=0;i<10;i++)
{
ADCON0bits.GO=1; // Start A/D conversion
while(ADCON0bits.DONE=1); // Wait until conversion gets over
digital_out=((ADRESL)|(ADRESH<<8)); // Store 10-bit output into a 16-bit variable
DELAY (20);
temp=temp+digital_out;
}
avg_output=temp/10; // Take average of ten digital values for stablity
adc_con(avg_output); // Function to convert the decimal vaule to its corresponding ASCII
}
}




void adc_con(unsigned int adc_out)
{
unsigned int adc_out1;
int i=0;
char position=0xC3;
for(i=0;i<=3;i++)
{
adc_out1=adc_out%10; // To exract the unit position digit
adc_out=adc_out/10;
lcdcmd(position);
lcddata(48+adc_out1); // Convert into its corresponding ASCII
position--;
}
}


void lcdcmd(unsigned char cmdout)
{
lcdport=cmdout; //Send command to lcdport=PORTB
rs=0;
rw=0;
en=1;
DELAY(50);
en=0;
}


void lcddata(unsigned char dataout)
{
lcdport=dataout; //Send data to lcdport=PORTB
rs=1;
rw=0;
en=1;
DELAY(50);
en=0;
}

void DELAY(int time)
{
int k=0,j=0,r=0,a=0;
for (k;k<time;k++)
for (j;j<25;j++)
for (a;a<25;a++)
for (r;r<25;r++);
}

صص.png
 

Hello!

If you just publish your code, it's very difficult to help you. You should explain
what goes wrong (in which function, at which line, and what exactly goes wrong).

Dora.
 

ADCON1=0xCE; // Make RA0/AN0 pin as analog pin (Other pins remain to be digital I/O)
You are using RC0 as your ADC input and configured RA) for ADC input. Make the changes. You have connected RA0 to LCD.
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top