hassanakhtar91
Newbie level 5
- Joined
- Jan 31, 2014
- Messages
- 8
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 71
I'm using PIC 16F877A microcontroller for my project in which I need to display current and voltage values on LCD using ADC of PIC. When I display float values on LCD using floattostr function, LCD doesen't show anything. I suspect this function takes a lots of memory of PIC and microcontroller can't operate. Is there any alternative code that I can replace instead of floattostr function so the microcontroller doesent take a lot of space and display is perfectly shown on LCD.
My code is given below. The problem is in current_Read(void) function.
My code is given below. The problem is in current_Read(void) function.
Code:
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
float v;
char txt[5];
char txt1[5];
void voltage_READ(void)
{
float max;
int i;
int t[40];
ADCON0.ADON=1;
for(i=0; i<=39; i++)
{
v= ADC_Read(0);
v =v*(10.0/1023.0);
v=(v-5.0);
t[i]=v*110.1909091;
}
ADCON0.ADON=0;
max=t[0];
for(i=0; i<=39; i++)
{
if(max<t[i])
max=t[i];
}
max=max*.707106781*18.33;
intToStr(max, txt);
Lcd_out(1,9,txt);
delay_ms(200);
}
void current_READ(void)
{
float max;
int i,current;
int t[40];
ADCON0.ADON=1;
for(i=0; i<=39; i++)
{
v= ADC_Read(1);
v =v*(10.0/1023.0);
v=(v-5.0);
t[i]=v*10;
}
ADCON0.ADON=0;
max=t[0];
for(i=0; i<=39; i++)
{
if(max<t[i])
max=t[i];
}
max=max*.707106781;
intToStr(max, txt1);
Lcd_out(2,8,txt1);
delay_ms(1000);
}
void main()
{
Lcd_Init(); // Initialize LCD
ADCON0.ADCS1=1;
ADCON0.ADCS1=0;
ADCON0.ADON=0;
while(1)
{
Lcd_out(1,1, "voltage:");
Lcd_out(2,1, "Current:");
voltage_READ();
current_READ();
}
}
Last edited by a moderator: