 |
 |
| View previous topic :: View next topic |
| Author |
Message |
Salvacast
Joined: 27 Apr 2026 Posts: 1
|
| problem with the adc |
Posted: Mon Apr 27, 2026 6:49 pm |
|
|
Hello everybody im new to the pic programmers
im trying to program a pic which reads a tmp36gz and show the temperature in an LCD 16x2 but i have a problem which the LCD doesnt initialize correctly with the tmp36 for some reason and doesnt show any text when this is connected.
The code is the following:
#include <16f877a.h>
#device ADC = 10
#fuses HS, NOWDT, NOPROTECT, PUT, NOLVP, NOBROWNOUT
#use delay(clock=4M)
#define lcd_rs_pin pin_D2
#define lcd_rw_pin pin_D1
#define lcd_enable_pin pin_D3
#define lcd_data4 pin_D4
#define lcd_data5 pin_D5
#define lcd_data6 pin_D6
#define lcd_data7 pin_D7
#include <lcd.c>
long valor_adc;
float temperatura;
void main()
{
delay_ms(1000);
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
delay_ms(200);
lcd_init();
delay_ms(100);
lcd_putc("\f");
delay_ms(100);
while (true)
{
valor_adc = read_adc();
temperatura = (valor_adc * 500.0 / 1023.0) - 50.0;
lcd_gotoxy(1, 1);
printf(lcd_putc, "Temp: %.1f C", temperatura);
delay_ms(500);
}
}
Any advice would be appreciated
 |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20075
|
|
Posted: Tue Apr 28, 2026 12:55 am |
|
|
Lots of little things to say:
First, use the code buttons when posting code. This way it'll appear
with indentation, and make your post clearer.
Then, are you testing the LCD first?, Have you verified that the display
does work correctly when the sensor is not connected?. What you
describe could be a problem with your board/clock, rather than with the
sensor.
Then a comment. Remark your code. Remarks are your friend, and a
friend to us when trying to remember why you have done things, or
work out why you have done things.
Triple check your connections.
Then some detail comments:
/1023 is wrong. The ADC reads 0..1023, but gets to 1023 a count before
the input gets to the supply voltage. You need /1024.
ADC_CLOCK_INTERNAL is wrong as well. This should only be used when
you sleep the processor to do the sample, when the clock is over 1MHz.
Above this speed, you need to use the master oscillator. For 4MHz, /8. This
is note 2 of table 11-1 in the datasheet.
What LCD driver are you using?. You probably want a form feed or a
line feed between each output, otherwise the output will disappear off
the end of the display.
So, start by just displaying something like a counter. If this does not work,
then you have to look at how is the clock being generated, and your
board as a whole. Once you have this working, then try with the sensor,
but look again at how this is connected and powered. |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|