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].
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
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
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"?
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:
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.
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.
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?