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.

collecting the ADC value

Status
Not open for further replies.

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:

You forgot to turn OFF the LED otherwise :


Code C - [expand]
1
2
3
4
if (ADC_value>Temp35) 
{ RB0=1; }
else 
{ RB0=0; }





+++
 

thanx for the reply...

tried that but still does not work. im very new to this plx help me out.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top