CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

i have problem with lm35 and adc

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cidik
Guest







i have problem with lm35 and adc
PostPosted: Wed Jan 09, 2008 6:18 pm     Reply with quote

i wrote this code but code is not working Crying or Very sad 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);
   }
}
deepakomanna



Joined: 06 Mar 2007
Posts: 92
Location: Pune,India

View user's profile Send private message AIM Address Yahoo Messenger

Re: i have problem with lm35 and adc
PostPosted: Thu Jan 10, 2008 2:43 am     Reply with quote

cidik wrote:
i wrote this code but code is not working Crying or Very sad 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
_________________
Thank You,
With Best Regards,
Deepak.
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Jan 10, 2008 10:58 am     Reply with quote

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
Guest








PostPosted: Thu Jan 10, 2008 1:48 pm     Reply with quote

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

u are helping me by the answering question. if it will not work i'll thank you anyway. i ll try this dude Wink thanks

my english is poor sorry for this. take care
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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