summersnow
Newbie level 6
temperature sensor code
i'm using PIC18F452 to do a project now..One of the features of the project is it can detect the temperature..i found a source code on the internet..But i face problem on convert it to the C language which suits the PIC and the programmer program that i use..the programmer that i use is MPLAB IDE v7.43..Is there anyone can help me on this?
below is the source code that i found:
DEFINE loader_used 1 ' Boot loader is being used
DEFINE debug_mode 0 ' Debug sending True serial data
DEFINE debug_reg portc ' Debug Port = PortCDEFINE debug_bit 6 ' Debug.bit = PortC.6
DEFINE debug_baud 9600 ' Default baud rate = 9600
DEFINE osc 4 ' We're using a 4 MHz oscillator
DEFINE ADC_BITS 8 ' Set A/D for 8-bit operation
DEFINE ADC_CLOCK 1 ' Set A/D clock Fosc/8
DEFINE ADC_SAMPLEUS 50 ' Set A/D sampling time @ 50 uS
samples VAR WORD ' Multiple A/D sample accumulator
sample VAR BYTE ' Holds number of samples to take
temp VAR BYTE ' Temperature storage
samples = 0 ' Clear samples accumulator on power-up
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %00000011 ' Set PORTA.0,1,2,5 = A/D, PortA.3 = +Vref
PAUSE 500 ' Wait .5 second
loop:
FOR sample = 1 TO 20 ' Take 20 samples
ADCIN 0, temp ' Read channel 0 into temp variable
samples = samples + temp ' Accumulate 20 samples
PAUSE 250 ' Wait approximately 1/4 seconds per loop
NEXT sample
temp = samples/20
DEBUG "Temperature is: ",DEC temp," Deg F",10,13
samples = 0 ' Clear old sample accumulator
GOTO loop ' Do it forever
END
basically the source code above is to display the temperature of the sensor on the computer..what i need is for specfic range of temperature,i will "on" the specific LED...such as for temperature within 20 celcius to 25 celcius,led1 will on..
for my circuit,i connect the LM35DZ to PORTA,A0..and there will be a Vref of 2.55V at PORTA,A3...
Q1:the part that i'm not clear is the ADCIN 0, temp ,i don't know for my PIC,what is this symbolize to..
Q2:if i want to compare the range of the temperature,is it that i need to compare with the temp?so if the temperature now is 20 celcius,is it that i compare temp with 20?
If my clarification is not clear enough,please let me know..
i'm really confuse with it..please help me...
i'm using PIC18F452 to do a project now..One of the features of the project is it can detect the temperature..i found a source code on the internet..But i face problem on convert it to the C language which suits the PIC and the programmer program that i use..the programmer that i use is MPLAB IDE v7.43..Is there anyone can help me on this?
below is the source code that i found:
DEFINE loader_used 1 ' Boot loader is being used
DEFINE debug_mode 0 ' Debug sending True serial data
DEFINE debug_reg portc ' Debug Port = PortCDEFINE debug_bit 6 ' Debug.bit = PortC.6
DEFINE debug_baud 9600 ' Default baud rate = 9600
DEFINE osc 4 ' We're using a 4 MHz oscillator
DEFINE ADC_BITS 8 ' Set A/D for 8-bit operation
DEFINE ADC_CLOCK 1 ' Set A/D clock Fosc/8
DEFINE ADC_SAMPLEUS 50 ' Set A/D sampling time @ 50 uS
samples VAR WORD ' Multiple A/D sample accumulator
sample VAR BYTE ' Holds number of samples to take
temp VAR BYTE ' Temperature storage
samples = 0 ' Clear samples accumulator on power-up
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %00000011 ' Set PORTA.0,1,2,5 = A/D, PortA.3 = +Vref
PAUSE 500 ' Wait .5 second
loop:
FOR sample = 1 TO 20 ' Take 20 samples
ADCIN 0, temp ' Read channel 0 into temp variable
samples = samples + temp ' Accumulate 20 samples
PAUSE 250 ' Wait approximately 1/4 seconds per loop
NEXT sample
temp = samples/20
DEBUG "Temperature is: ",DEC temp," Deg F",10,13
samples = 0 ' Clear old sample accumulator
GOTO loop ' Do it forever
END
basically the source code above is to display the temperature of the sensor on the computer..what i need is for specfic range of temperature,i will "on" the specific LED...such as for temperature within 20 celcius to 25 celcius,led1 will on..
for my circuit,i connect the LM35DZ to PORTA,A0..and there will be a Vref of 2.55V at PORTA,A3...
Q1:the part that i'm not clear is the ADCIN 0, temp ,i don't know for my PIC,what is this symbolize to..
Q2:if i want to compare the range of the temperature,is it that i need to compare with the temp?so if the temperature now is 20 celcius,is it that i compare temp with 20?
If my clarification is not clear enough,please let me know..
i'm really confuse with it..please help me...