PIC18F4520 to LCD JHD162A LCD C- Program.

Status
Not open for further replies.

qlouis76

Newbie level 4
Joined
Jun 1, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,291
Location
Malaysia
Visit site
Activity points
1,331
Hi all,

Need some help to display the result to the LCD JHD162A LCD. exp : 6+4=10

below is my c-program. I am using MPlab.

#include <PIC18F4520.h>
#include <htc.h>
//--------------------------------
#define bit0 PORTAbits.RA0
#define bit1 PORTAbits.RA1
#define bit2 PORTAbits.RA2
#define bit3 PORTAbits.RA3
//--------------------------------
#define bit4 PORTBbits.RB0
#define bit5 PORTBbits.RB1
#define bit6 PORTBbits.RB2
#define bit7 PORTBbits.RB3
//--------------------------------
#define s1 PORTCbits.RC0
#define s2 PORTCbits.RC1
#define s3 PORTCbits.RC2
#define s4 PORTCbits.RC3
//--------------------------------

int main()
{
TRISAbits.TRISA0=1; //configure PortA 0,1,2,3 as input
TRISAbits.TRISA1=1;
TRISAbits.TRISA2=1;
TRISAbits.TRISA3=1;
//--------------------------------
TRISBbits.TRISB0=1; //configure PortB 0,1,2,3 as input
TRISBbits.TRISB1=1;
TRISBbits.TRISB2=1;
TRISBbits.TRISB3=1;
//--------------------------------
TRISCbits.TRISC0=1; //configure PortC 0,1,2,3 as input
TRISCbits.TRISC1=1;
TRISCbits.TRISC2=1;
TRISCbits.TRISC3=1;
//--------------------------------
TRISD=0; //output
//--------------------------------
{
unsigned int num1;
unsigned int num2;
unsigned int ans;

num1= ((bit0*1)+(bit1*2)+(bit2*4)+(bit3*8));
num2= ((bit4*1)+(bit5*2)+(bit6*4)+(bit7*8));


while (1)
{
if(s1 == 1) // '+' operation
{ ans = num1 + num2;
printf("num1+num2=%.2f",num1+num2);
break; //delay(10);
}
else if(s2 == 1) // '-' operation
{ ans = num1 - num2;
printf("num1-num2=%.2f",num1-num2);
break; //delay(10);
}
else if(s3 == 1) // '*' operation
{ ans = num1 * num2;
printf("num1*num2=%.2f",num1*num2);
break; //delay(10);
}
else if(s4 == 1) // '/' operation
{ ans = num1 / num2;
printf("num1/num2=%.2f",num1/num2);
break; //delay(10);
}
PORTB=ans;
return (0);
}
}
}

I tried to use printf, but i didn't work.

p/s: is my code got any mistake?

thank you so much
 

Hi,

you have just made the pin (PORTA) as an output but it is not defined in the code that the pin behavior is analog or digital. Its is done via writing to ADCON register. Select the pins you want to make digital.

Also post your complete code to help you out.

Enjoy!
 

LCD initialization required also print f not print directly print ur any data on lcd.

I thought PIC18 no need LCD initialization?

- - - Updated - - -


Above is my complete code. I am a beginner. Still learning C-program. Sorry.

ADCON? How am I suppose to use it? still learning!
 

How Compiler know ur assign pin such as LCD DATA pin, RW, RS & EN etc if u used LCD 16x2.
if u required initialization u get ready code on Google search.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…