Mohamed Rasheed
Newbie level 2
- Joined
- Apr 16, 2014
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 18
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.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 #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 } }
Last edited by a moderator: