# [SOLVED]Problem to print float on LCD

Status
Not open for further replies.

#### stip

##### Newbie level 5
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.

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
ch is a char array ? Where are you reading ADC ?

#### stip

##### Newbie level 5
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
ADCON1 = 0X0E;// To configure RA0 as analogic input
CMCON |= 7; // Disable comparators

Best regards.

Last edited by a moderator:

#### Aussie Susan

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
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"?

#### xenos

##### Full Member level 4
...How can I see what the 'ch' array contain after the "FloatToStr"?

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
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
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.

#### Attachments

33.5 KB · Views: 20
116.2 KB · Views: 7
Last edited:

V
Points: 2

#### stip

##### Newbie level 5
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.

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
I am using mikroC PRO PIC 6.6.1 which is the latest version and Proteus 8.2 SP2.

#### stip

##### Newbie level 5
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.