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 to print float on LCD

Status
Not open for further replies.

stip

Newbie level 5
Joined
Jun 8, 2015
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
81
Hi everybody!
I am using the Mikroc compiler with PIC18F2550 and simulating with Proteus.
I want to print a float value in lcd. It is a current value from the ACS712 hall sensor, but it is not working. The LCD doesn't show anything.
The part of the code to display the information is below. If I forgot some important information, please lemme know.
Thanks in advance.


Code C - [expand]
1
2
3
4
5
6
7
while(1){
i = 0.0264*((valor_ad/1.75)-512); //the 1.75 is my ampop gain
FloatToStr(i,ch);
Lcd_Out(2,1,ch);
Lcd_Chr_CP('A');
Delay_ms(100);
}



I declared the "i" as a float and the "ch" as a char[15].
 
Last edited by a moderator:

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
ch is a char array ? Where are you reading ADC ?
 

stip

Newbie level 5
Joined
Jun 8, 2015
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
81
ch is a char array ? Where are you reading ADC ?

Yep, ch is a char array length [15] and I am reading the ADC from the channel A0. I configured the registers as below:

Code C - [expand]
1
2
3
4
TRISA.B0 = 1; // RA0 pin as input
 ADCON0 = 0X01; //Enable ADC in the A0 channel
 ADCON1 = 0X0E;// To configure RA0 as analogic input
 CMCON |= 7; // Disable comparators


Best regards.
 
Last edited by a moderator:

Aussie Susan

Advanced Member level 4
Joined
Jan 5, 2015
Messages
1,258
Helped
380
Reputation
760
Reaction score
376
Trophy points
83
Activity points
13,610
What is the calculated value of "i'?
What does the 'ch' array contain after the "FloatToStr" function?
If everything is correct to that point then it is probably a wiring or hardware (or simulator) issue with the LCD.
Perhaps you need to tell us what is working and a better description of what is not working (no characters displayed, wrong characters, etc.).
Susan
 

stip

Newbie level 5
Joined
Jun 8, 2015
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
81
What is the calculated value of "i'?
What does the 'ch' array contain after the "FloatToStr" function?
If everything is correct to that point then it is probably a wiring or hardware (or simulator) issue with the LCD.
Perhaps you need to tell us what is working and a better description of what is not working (no characters displayed, wrong characters, etc.).
Susan

I tested the simulator just printing the ADC value and it worked fine . The problem is when I want to print the 'ch' array. The display doesn't show anything. How can I see what the 'ch' array contain after the "FloatToStr"?

Thanks for reply!
 

xenos

Full Member level 4
Joined
May 9, 2015
Messages
212
Helped
82
Reputation
164
Reaction score
81
Trophy points
28
Location
127.0.0.1
Activity points
1,182
...How can I see what the 'ch' array contain after the "FloatToStr"?

Thanks for reply!
With a debugger (use "watch" window).
You can also post the FloatToStr so we can check it.
You also could add the following commands after the call to FloatToStr and see if you get anything on LCD:
Code:
       ch[0] = 'h';
       ch[1] = 'e';
       ch[2] = 'l';
       ch[3] = 'l';
       ch[4] = 'o';
       ch[5] = 0;
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
mikroE tells that if you want to use FlaotToStr() then ch length should be minimum 23. Try using ch[23]. Zip and post your complete mikroC PRO PIC project files. I will test it in Proteus and also hardware.
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
Fixed project attached. I have compiled the code for 4 MHz XT oscillator. MCLR is enabled. You have to pullup MCLR to 5V using a 10k resistor in hardware. Proteus 8.2 SP2 format file is included.

In 18F devices you have to use LATx_bit for output pins. I have tested the project in Proteus and also hardware and it works fine in both.

118300d1433936639-adc.png
 

Attachments

  • adc.png
    adc.png
    33.5 KB · Views: 20
  • ADC on PIC18F2550.rar
    116.2 KB · Views: 7
Last edited:

    V

    Points: 2
    Helpful Answer Positive Rating

stip

Newbie level 5
Joined
Jun 8, 2015
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
81
Fixed project attached. I have compiled the code for 4 MHz XT oscillator. MCLR is enabled. You have to pullup MCLR to 5V using a 10k resistor in hardware. Proteus 8.2 SP2 format file is included.

In 18F devices you have to use LATx_bit for output pins. I have tested the project in Proteus and also hardware and it works fine in both.

118300d1433936639-adc.png


First of all, thank you very much! Your project attached was very helpful. But there is a very strange thing. When I use your hex file it works fine, but if I compile your hex file in my compiler it doesn't work anymore. So, I suppose what I have is a software program. Could you tell me what is the version of your Mikroc and Proteus, please?
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
I am using mikroC PRO PIC 6.6.1 which is the latest version and Proteus 8.2 SP2.
 

stip

Newbie level 5
Joined
Jun 8, 2015
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
81
I am using mikroC PRO PIC 6.6.1 which is the latest version and Proteus 8.2 SP2.
So I think it was really a software problem. I am using Mikroc PRO PIC 5.6.1 and Proteus 8.0. Thanks again for the help.

Thank you all guys for the help. I couldn't have done it without all the support I have found on here.
Special thanks to milan.rajik.

Best regards.
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top