hey guys, I'm having some trouble with the division part of pic16f877a calculator...
u see only the quotent part of the division part is shown on the LCD
what should i do?
here is the "effy" part:
I'm actially taking the two numbers from ports C,D and I identified the result variable as float the pogram is c of course
thanks!!
u see only the quotent part of the division part is shown on the LCD
what should i do?
here is the "effy" part:
Rich (BB code):
result=(float)portc/portd;
thanks!!
Rich (BB code):
sbit lcd_rs at rb2_bit;
sbit lcd_en at rb3_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_rs_direction at trisb2_bit;
sbit lcd_en_direction at trisb3_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;
int i,j,k,l;
char txt[20];
int operation;
float result;
char opsymb;
char x[20];
char y[20];
char resultchr[20];
void interrupt()
{
if(intcon.t0if==1&&(portd!=i||portc!=j||portb.b0!=k||portb.b1!=l))
{inttostr(portc,x);
inttostr(portd,y);
operation=portb.b0+portb.b1;
switch(operation)
{
case 0:
result=portd+portc;
opsymb='+';
break;
case 1:
if(portb.b1>portb.b0)
{result=portd*portc;
opsymb='x';
}
else
{
result=(float)portc/portd;
opsymb='/';
}
break;
case 2:
result=portc-portd;
opsymb='-';
break;
}
lcd_cmd(_LCD_CLEAR);
bytetostr(portc,x);
bytetostr(portd,y);
lcd_out(1,1,x);
lcd_chr_cp(opsymb);
lcd_out_cp(y);
if(portd==0&&opsymb=='/')
{
lcd_out_cp("error");
delay_ms(500);
lcd_cmd(_lcd_clear);
}
else
{floattostr(result,resultchr);
lcd_chr_cp('=');
lcd_out(2,1,resultchr);
}
tmr0=0;
intcon.t0if=0;
i=portd;
j=portc;
k=portb.b0;
l=portb.b1;
}
}
void main() {
trisd=0xff;
trisc=0xff;
lcd_init();
intcon=0xA0;
option_reg=0x07;
tmr0=0;
}
Last edited by a moderator: