Hi,
I am trying to send ADC value to LCD with PIC16F877A but only the first digit is displayed(picture attached). Can anybody help? here is the code:
void main(void)
{
sys_init();
lcd_init();
unsigned int adc;
int v;
char a,b,c,d;
while(1)
{
adc = adc_read();
v = ((adc*5)/1023)*100; //eg v=234
a = v%10+48; //4
b = v/10; //23
c = b%10+0x30; //3
d = b/10+0x30; //2
send_string("Volt: ");
send_char(d);
send_char('.');
send_char(c);
send_char(a);
__delay_ms(1000);
send_cmd(0x01); // clear the screen
}
}
the ADC code:
#include "adc.h"
unsigned int adc_read()
{
GO_nDONE = 1;
while(GO_nDONE);
return ((ADRESH<<8)+ADRESL);
}
the LCDd code:
void send_char(char data)
{
RS = 1; //select Data Reg.
PORTD = (PORTD & 0x0F)|(data & 0xF0); //send upper nibble
EN = 1;
__delay_ms(1);
EN = 0;
PORTD = (PORTD & 0x0F)|((data<<4) & 0xF0); //send lower nibble
EN = 1;
__delay_ms(1);
EN = 0;
}