Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] problem with Floating point display on LCD

Status
Not open for further replies.

vibodha

Newbie level 6
Joined
Jun 3, 2013
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,365
I have made a small program to measure voltage(0-5) on AN2. Its works fine but have a little problem. When the voltage less than 1v (ie. 0.99) it shows wrong voltage on LCD.
ie when voltage 0.568V , Lcd shows 5.68v
0.0213v -----> 0.213v

Can anyone correct me..
here is the program (mikroc)

Code:
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
char txt1[] = "ADC Example";
char txt[2];
char txt2[5];
unsigned int temp_res;
float data2;

void main() {
ansel=4;  // Configure AN2 pin as analog
  anselh=0;
  c1on_bit=0;
  c2on_bit=0;
   ////////////////////////////////////////////////////////////////
  TRISA  = 0xFF;              // PORTA is input
  Lcd_Init();
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,1,txt1);
  adc_init();
  do {

    temp_res = ADC_read(2);   // Get 10-bit results of AD conversion
   

    data2 =  (temp_res*5)/1023.0;
    FloatToStr(data2,txt2);
    txt2[5]=0;
    Lcd_Out(2,1,txt2);
    Delay_ms(1000);
    }
    while(1) ;


}
 

I'm Using PIC16F887 .. I have used ADC library in mikroC
 

Try this code.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
 
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
 
char txt1[] = "ADC Example";
char txt[23];
float data2;
 
void main() {
 
    TRISA  = 0xFF;              // PORTA is input
    TRISB  = 0x00;              // PORTA is input
    PORTA  = 0x00;              // PORTA is input
    PORTB  = 0x00;              // PORTA is input
    ANSEL  = 0x04;              // Configure AN2 pin as analog
    ANSELH = 0x00;
    ADCON1 = 0x80;
    c1on_bit=0;
    c2on_bit=0;
        
    Lcd_Init();
    Lcd_Cmd(_LCD_CLEAR);        // Clear display
    Lcd_Cmd(_LCD_CURSOR_OFF);   // Cursor off
    Lcd_Out(1,1,txt1);
  
    do {
 
        data2 = ADC_read(2);    // Get 10-bit results of AD conversion
        data2 =  data2 * 5.0 / 1023.0;
        FloatToStr(data2,txt2);
        Lcd_Out(2,1,txt2);
        Delay_ms(1000);
    }
    while(1) ;
 
 
}

 

what reason to increase size of array?
is it like
float = 4byte
so

5*4 = 20;?
 

Mr. jayanth I tried the way but the problem is same... but somehow I found another method here is the changed code.
Code:
unsigned long ADC_Value, value, ADC_Value1, value1;
char *volts = "00.00 V";


/////////// Inside the main Function //////////////
ADC_Value = ADC_read(2);
    value = (ADC_Value * 500)/1023;
   volts[0] = value/1000+ 48 ;
   volts[1] = (value/100)%10 + 48;
   volts[3] = (value/10)%10 + 48;
   volts[4] = (value)%10 + 48;
   Lcd_Out(2,1,volts )   ;





I got this from internet searching and of that I cannot understand some parts:shock::shock: such as the meaning of "48" of the following code
Code:
 volts[0] = value/1000+ 48 ;

Thank You very much for your contribution
 

48 in decimal is equal to character '0' and hex 0x30. By adding 48 you are converting the integer value to character. 0 + 48 = 48 = '0' = 0x30.
 

Mr.jayanth.devarayanadurga Thank you very much for the help
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top