guys i need your help... im using a TEMP sensor and an LED. i need to turn ON the LED what a certain temp. is this code correct.
#include<htc.h>
#include<pic.h>
#define _XTAL_FREQ 20000000
void InitADC(void)
{
ADCON1 = 0x80; // Make PORTA and PORTE analog pins
// Also, Vref+ = 5v and Vref- = GND
TRISA = 0x2f; // Make RA5, RA3, RA2, RA1, RA0 input
TRISE = 0x07; // Make RE0, RE1 and RE2 input
ADCON0 = 0x81; // Turn on the A/D Converter
}
unsigned int GetADCValue(unsigned char Channel)
{
ADCON0 &= 0xc7; // Clear Channel selection bits
ADCON0 |= (Channel<<3); // Select channel pin as ADC input
__delay_ms(10); // Time for Acqusition capacitor
// to charge up and show correct value
GO_nDONE = 1; // Enable Go/Done
while(GO_nDONE); // Wait for conversion completion
return ((ADRESH<<8)+ADRESL); // Return 10 bit ADC value
}
void main()
{
unsigned int ADC_value = 0;
PORTB=0x00;
TRISB = 0x00; //PORTB as output
InitADC(); //Initializes ADC Module
#define Temp35 71
#define Temp25 51
while(1){
ADC_value = GetADCValue(0); //Reading Analog Channel 0
if (ADC_value>Temp35){
RB0=1;
}
__delay_ms(30); //Delay
}
}
#include<htc.h>
#include<pic.h>
#define _XTAL_FREQ 20000000
void InitADC(void)
{
ADCON1 = 0x80; // Make PORTA and PORTE analog pins
// Also, Vref+ = 5v and Vref- = GND
TRISA = 0x2f; // Make RA5, RA3, RA2, RA1, RA0 input
TRISE = 0x07; // Make RE0, RE1 and RE2 input
ADCON0 = 0x81; // Turn on the A/D Converter
}
unsigned int GetADCValue(unsigned char Channel)
{
ADCON0 &= 0xc7; // Clear Channel selection bits
ADCON0 |= (Channel<<3); // Select channel pin as ADC input
__delay_ms(10); // Time for Acqusition capacitor
// to charge up and show correct value
GO_nDONE = 1; // Enable Go/Done
while(GO_nDONE); // Wait for conversion completion
return ((ADRESH<<8)+ADRESL); // Return 10 bit ADC value
}
void main()
{
unsigned int ADC_value = 0;
PORTB=0x00;
TRISB = 0x00; //PORTB as output
InitADC(); //Initializes ADC Module
#define Temp35 71
#define Temp25 51
while(1){
ADC_value = GetADCValue(0); //Reading Analog Channel 0
if (ADC_value>Temp35){
RB0=1;
}
__delay_ms(30); //Delay
}
}