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