![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
delifadzli
Joined: 12 Apr 2010 Posts: 27
|
please help on LM35 code... |
Posted: Mon Apr 12, 2010 12:23 am |
|
|
Here is sample source that I have made using PCW C compiler. Its about simple code on LM35 + LCD operation.
This source explain about the temperature which being detect by LM35 and display to LCD.
Here I wanna ask.... isn't this code can be used?
Since when I compile there is no error.....
Code: |
#include <16f877a.h>
#device ADC=10
#FUSES HS,NOWDT,NOPROTECT,NOLVP
#USE DELAY (CLOCK=20000000)
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <lcd.c>
//Define parameter
unsigned int temp_adc=0;
char L;
float temp;
void main()
{
set_tris_D(0x00); // Config PORTD for LCD display.
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL); // All channels are config as analog I/p.
lcd_init();
printf (L, "Temperature is:");
//procedure ADC
while(1)
{
temp_adc=read_adc();
temp= 5*temp_adc*(100.00/1023.00);
lcd_gotoxy(1,1);
lcd_putc('\f');
printf(lcd_putc,"Temp is:%f",temp);
delay_ms(50);
}
} |
I hope someone respond...
If there's no error, perhaps I will be concentrating more on the hardware part.
Some detail on my diagram...sorry the diagram can't be drawn...I don't know.
When I try to run it....the lcd doesn't show any result.
pin MCLR---connect to 5v
pin LM35- pin ANO
For lcd:
Quote: |
pin 1- Gnd
pin2- 5 v
pin 3- variable resistor 470 k
pin 4- RD0
pin 5- gnd
pin 6-RD1
pin 11- RD4
pin12-RD5
Pin13-RD6
Pin14-RD7
Pin15-5 v
pin16-Gnd
pin 13-osc1--directly goes to oscillator 10mhz
|
Please help me. I'm new in programming. Please. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19366
|
|
Posted: Mon Apr 12, 2010 4:29 am |
|
|
There are several things wrong with the code. Some minor, some major, and some just in comments.
Start with 'L'. This is defined as a character. You then use printf, with this given to the printff function as if this is the name of a function. It isn't. If you want to send the data to a _string_, then you should be using sprintf, not printf, and 'L' needs to be an array of characters. As written, it is garbage.
Then you have a comment 'All channels are config as analog I/p'. They aren't. Only AN0 is set as an analog by the statement on the line before.
Then you select 'ADC_CLOCK_INTERNAL'. Read the data sheet. This option is _not_ recommended for use above 1MHz processor clock. This won't stop the code working, but will degrade accuracy.
Then you never select an ADC channel to use. It _may_ default to the one channel you have selected, but normally most register bits default to '1', rather than '0', so I'd not expect it to.
Then 'temp_adc', is defined as an 'int'. In CCS, by default, an 'int' is 0 to 255. Your adc outout is 0-1023. You need a larger type here.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
delifadzli
Joined: 12 Apr 2010 Posts: 27
|
|
Posted: Mon Apr 12, 2010 5:33 am |
|
|
thanks for the respond...i will try to adjust the code.....hopefully with ur guidance....it will works....thanks anyway... ![Very Happy](images/smiles/icon_biggrin.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|