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.

ADC value convert to Hex value

Status
Not open for further replies.

ragav4456

Full Member level 4
Joined
Aug 1, 2012
Messages
228
Helped
19
Reputation
38
Reaction score
17
Trophy points
1,308
Activity points
2,568
How to convert analog value to hexadecimal value
 

Your question is not clear.

Make it a clear question.
 

ADC value convert to display in led light?

- - - Updated - - -

I need to adc value display in led light, how to display it?
 

this program will convert binary to hex, this would help you.



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
#include<reg51.h>
#define input P0  //Input port to read the values of ADc
#define output P2  // Output port, connected to LED's.
 
sbit wr= P1^1;  // Write pin. It is used to start the conversion. 
sbit rd= P1^0;  // Read pin. It is used to extract the data from internal register to the output pins of ADC.
sbit intr= P1^2;  // Interrupt pin. This is used to indicate the end of conversion. It goes low when conversion is complete.
 
void delay(unsigned int msec )  // The delay function provides delay in msec.
{
int i,j ;
for(i=0;i<msec;i++)
  for(j=0; j<1275; j++);
}
void Bin2Dec(char n)
{
int bin,n,r,s=0,i;
n=bin;
for(i=0;n!=0;i++)
{
r=n%10;
s=s+r*(int)pow(2,i);
n=n/10;
}
s=output  // s is havin decimal value now
}
void adc()  // Function to read the values from ADC and display on the LED's.
{
rd=1;     
wr=0;     
delay(1);
wr=1;
while(intr==1);
rd=0;
output=input;
delay(1);
intr=1;
}
void main()
{
  input=0xff;  // Declare port 0 as input port.       
while(1)
{
   adc();
  }
}


- - - Updated - - -

sorry that program will convert binary to decimal n i forgot to call bin2dec() function in adc() function, pls do that, and refer this function for converting decimal 2 hex.


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
void Dec2Hex()
{
int n,r[10],i;
printf("Enter a number to get its hexadecimal equivalent\n");
scanf("%d",&n);
for(i=0;n!=0;i++)
{
r[i]=n%16;
n=n/16;
}
i--;
for(;i>=0;i--)
{
if(r[i]==10)
printf("A");
else if(r[i]==11)
printf("B");
else if(r[i]==12)
printf("C");
else if(r[i]==13)
printf("D");
else if(r[i]==14)
printf("E");
else if(r[i]==15)
printf("F");
else
printf("%d",r[i]);
}
printf("\n");
}

 
Last edited by a moderator:

I need for pic 16f877 controller? ccs compiler
 

I need for pic 16f877 controller? ccs compiler

you can port it easily

- - - Updated - - -

do u want to display the value of ADC on seven segment? if so there is no need to convert to hex.

please let me know if iam getting it right so that i can help you also let me know h0w many 7 segments you are using
 

Want to display in led only. 8 led connected to port d...
 

you should have clearly mentioned that , well set your uart to 8 bit resolution and use the value to update LEDS

- - - Updated - - -

value=ADC_read();
PORTD=value;
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top