Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to read temperature from pic16f628 and css c compiler

Status
Not open for further replies.

KiuFelix

Newbie level 5
Joined
Apr 24, 2012
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,347
I am trying to read temperature values from a LM35. This is how my code is arranged
Code:
//************************************************************
// Function:  Temperature logger: UART at 9600 baud
// Processor: PIC16F628 at 4 MHz using internal RC oscillator
// Hardware:  K4
// Software:  CCS PCM
// Author:	  Cheruiyot Felix, felix@nairobicoder.com	
// Credit:    Lars Petersen, oz1bxm@pobox.com
//************************************************************

#include <16F628.h>
#fuses INTRC_IO, NOLVP, NOWDT, PUT, BROWNOUT
#device ADC=8;
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=pin_B2, rcv=pin_B1)

void main() {
//Initialize values
unsigned int val;
int t;
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
   while(read_adc()) {
	val=read_adc();
	t=round(val*0.48876);                   //as per http://www.best-microcontroller-projects.com/temperature-recorder.html tutorial
	delay_ms(500);
	printf("T%d",t);				//Output temperature
   }
}

My code looks ok and when trying to compile, I get this error:

Code:
Clean: Deleting intermediary and output files.
Clean: Deleted file "final.ESYM".
Clean Warning: File "C:\Program Files\PICC\final.o" doesn't exist.
Clean: Deleted file "final.ERR".
Clean: Done.
Executing: "C:\Program files\Picc\CCSC.exe" +FM "final.c" +DF +LN +T +A +M +Z +Y=9 +EA
*** Error 12 "final.c" Line 21(10,11): Undefined identifier  -- setup_adc
*** Error 12 "final.c" Line 22(16,17): Undefined identifier  -- setup_adc_ports
*** Error 12 "final.c" Line 23(16,17): Undefined identifier  -- set_adc_channel
*** Error 12 "final.c" Line 26(8,9): Undefined identifier  -- round
      4 Errors,  0 Warnings.
Build Failed.
Halting build on first failure as requested.
BUILD FAILED: Thu Apr 26 00:11:19 2012

Note the setup errors and the round error yet math.h is included.
When I change to #include <16F877A.h>, No errors except the round error. I am not supposed to use 16F877A though. Only 16F628 is available for me. Someone kindly help.
Thanks
 

LM35 is a temperature sensor with analog output. You can connect it to 16F628's AN0 or AN1.

Code:
void main(){
    init();  //disable interrupts, select analog input in, set tri-status, ans so on
    while (1){
       delay1ms();
       convert(temperature);  //convert the temperature at a certain interval
    }
}

What compiler and IDE did you use? HI-TECH and MPLAB? which version?
 

Thank you for reply. I am using CCS C compiler and I have just noticed that they don't have compiler support for 16F628 adc module. Hitech looks good too. Can you write for me a sample code in hitech that gets temperature from maybe LM35 attached to AN0 and transmit it via rs232? I am using 4mHz crystal. Kindly introduce me to it. Thanks once again.

[If we have tweek for ccs too, kindly let me know]
 

Thank you for reply. I am using CCS C compiler and I have just noticed that they don't have compiler support for 16F628 adc module. Hitech looks good too. Can you write for me a sample code in hitech that gets temperature from maybe LM35 attached to AN0 and transmit it via rs232? I am using 4mHz crystal. Kindly introduce me to it. Thanks once again.

[If we have tweek for ccs too, kindly let me know]


The 16F628 Does NOT have ADCs. AN0 and AN1 are comoparator inputs NOT ADCs. Read the datasheet. In the Table of Contents on page 3 there is no mention of Analog to Digital converters. On page 8 it does not show ADCs. There is no compiler that can change the fact.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top