![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
cidik Guest
|
i have problem with lm35 and adc |
Posted: Wed Jan 09, 2008 6:18 pm |
|
|
i wrote this code but code is not working can anyone help me? tnx
Code: | #include <16F877.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay(clock=4000000)
#define use_portb_lcd TRUE
#include <lcd.c>
unsigned long int ham;
float voltaj,sicaklik;
void main()
{
setup_psp(PSP_DISABLED); // PSP birimi devre dışı
setup_spi(SPI_SS_DISABLED); // SPI birimi devre dışı
setup_timer_1(T1_DISABLED); // T1 zamanlayıcısı devre dışı
setup_timer_2(T2_DISABLED,0,1); // T2 zamanlayıcısı devre dışı
setup_CCP1(CCP_OFF); // CCP1 birimi devre dışı
setup_CCP2(CCP_OFF); // CCP2 birimi devre dışı
setup_adc(adc_clock_div_32); // ADC clock frekansı internal RC
setup_adc_ports(AN0); // Tüm AN girişleri analog
lcd_init();
set_adc_channel(0);
delay_us(20);
printf(lcd_putc,"\fSicaklik=");
while(1)
{
delay_ms(50);
output_b(0x00);
ham=read_adc();
delay_ms(200);
output_b(0x00);
voltaj=(0.0048828125*ham)*1000;
sicaklik=(voltaj/10)+2;
lcd_gotoxy(10,1);
printf(lcd_putc,"%5.1f'C",sicaklik);
delay_ms(200);
output_high(pin_b0);
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
Re: i have problem with lm35 and adc |
Posted: Thu Jan 10, 2008 2:43 am |
|
|
cidik wrote: | i wrote this code but code is not working can anyone help me? tnx
Code: | #include <16F877.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay(clock=4000000)
#define use_portb_lcd TRUE
#include <lcd.c>
unsigned long int ham;
float voltaj,sicaklik;
void main()
{
setup_psp(PSP_DISABLED); // PSP birimi devre dışı
setup_spi(SPI_SS_DISABLED); // SPI birimi devre dışı
setup_timer_1(T1_DISABLED); // T1 zamanlayıcısı devre dışı
setup_timer_2(T2_DISABLED,0,1); // T2 zamanlayıcısı devre dışı
setup_CCP1(CCP_OFF); // CCP1 birimi devre dışı
setup_CCP2(CCP_OFF); // CCP2 birimi devre dışı
setup_adc(adc_clock_div_32); // ADC clock frekansı internal RC
setup_adc_ports(AN0); // Tüm AN girişleri analog
lcd_init();
set_adc_channel(0);
delay_us(20);
printf(lcd_putc,"\fSicaklik=");
while(1)
{
delay_ms(50);
output_b(0x00);
ham=read_adc();
delay_ms(200);
output_b(0x00);
voltaj=(0.0048828125*ham)*1000;
sicaklik=(voltaj/10)+2;
lcd_gotoxy(10,1);
printf(lcd_putc,"%5.1f'C",sicaklik);
delay_ms(200);
output_high(pin_b0);
}
}
|
|
try this,
SETUP_ADC_PORTS(sAN0|VSS_VDD );
& while reading ADC folow this ,
SET_ADC_CHANNEL(0);
DELAY_US(20);
TEMP_VALUE = READ_ADC();
SETUP_ADC(ADC_OFF);
hope i helped you ![Very Happy](images/smiles/icon_biggrin.gif) _________________ Thank You,
With Best Regards,
Deepak. |
|
![](templates/subSilver/images/spacer.gif) |
SET
Joined: 15 Nov 2005 Posts: 161 Location: Glasgow, UK
|
|
Posted: Thu Jan 10, 2008 10:58 am |
|
|
Quote: | Code: |
delay_ms(50);
output_b(0x00); <---
ham=read_adc();
delay_ms(200);
output_b(0x00); <---
voltaj=(0.0048828125*ham)*1000;
sicaklik=(voltaj/10)+2;
lcd_gotoxy(10,1);
printf(lcd_putc,"%5.1f'C",sicaklik); |
|
Why do you write 0 to Port B twice? It looks like you use Port B for the LCD module comms:
Quote: | Code: | #define use_portb_lcd TRUE | |
|
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Thu Jan 10, 2008 1:48 pm |
|
|
SET wrote: | Quote: | Code: |
delay_ms(50);
output_b(0x00); <---
ham=read_adc();
delay_ms(200);
output_b(0x00); <---
voltaj=(0.0048828125*ham)*1000;
sicaklik=(voltaj/10)+2;
lcd_gotoxy(10,1);
printf(lcd_putc,"%5.1f'C",sicaklik); |
|
Why do you write 0 to Port B twice? It looks like you use Port B for the LCD module comms:
Quote: | Code: | #define use_portb_lcd TRUE | |
|
hi i used this because i wrote a code. this code was sending (1) to b0 when adc_int is activated. i was delete that. and i ll try to delete this lines from program. im newbie on pic and ccs c. tnx for the answer.
Quote: |
try this,
SETUP_ADC_PORTS(sAN0|VSS_VDD );
& while reading ADC folow this ,
SET_ADC_CHANNEL(0);
DELAY_US(20);
TEMP_VALUE = READ_ADC();
SETUP_ADC(ADC_OFF);
hope i helped you ![Very Happy](images/smiles/icon_biggrin.gif) |
u are helping me by the answering question. if it will not work i'll thank you anyway. i ll try this dude thanks
my english is poor sorry for this. take care |
|
![](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
|