Nikunj Tanna
Advanced Member level 4
- Joined
- Dec 8, 2009
- Messages
- 115
- Helped
- 23
- Reputation
- 46
- Reaction score
- 15
- Trophy points
- 1,298
- Location
- Ahmedabad, Gujarat, India
- Activity points
- 1,985
Hello all,
I am working on 16 bit adc ADS 7825, I've got output of it which is in form of 2's complement. I've also converted that hex value into decimal, now I want to display the voltage value like 2.45xx, 3.4267 etc., on six digit 7 segment.
So, I need to multiply the decimal value with 5V / 65536(16 bit). So I got float value to multiplied with the decimal. Now how to handle this float value calculation and how to display the resultant float value on 7 segment..?
I am using codevision avr and the controller is ATMEGA 128.
The code is given below::
#include <stdio.h>
#include <stdlib.h>
#define CLK PORTA.0
#define DATA PORTA.2
#define LATCH PORTA.1
#define A1 PORTA.3
#define A0 PORTA.4
#define byte PORTA.5
#define rc PORTA.6
#define busy PORTA.7
unsigned char digit[5];
void main(void)
{
unsigned char data,data2,data3,data4,i,j;
unsigned int final=0,fi2=0;
while(1)
{
rc = 1;
A1 = 0;
A0 = 0;
PORTG &= 0x00; // portg.2 (contc) = 0
byte = 0;
rc = 0;
delay_us(4);
rc = 1;
while(busy == 0);
data = PINC;
byte = 1;
for(i=0;i<1;i++) for(j=0;j<2;j++);
data2 = PINC;
data3 = ~ data;
data4 = ~ data2;
final = (data3<<8) + data4 + 1; // 2's complement
fi2=hex2dec(final); // getting decimal value
}
}
int hex2dec(unsigned int lnum)
{
unsigned char i=0;
unsigned int deci;
while(lnum > 10)
{
digit = lnum % 0x0a;
lnum = lnum / 0x0a;
i++;
}
deci = atoi (digit);
return deci;
}
NIKS
I am working on 16 bit adc ADS 7825, I've got output of it which is in form of 2's complement. I've also converted that hex value into decimal, now I want to display the voltage value like 2.45xx, 3.4267 etc., on six digit 7 segment.
So, I need to multiply the decimal value with 5V / 65536(16 bit). So I got float value to multiplied with the decimal. Now how to handle this float value calculation and how to display the resultant float value on 7 segment..?
I am using codevision avr and the controller is ATMEGA 128.
The code is given below::
#include <stdio.h>
#include <stdlib.h>
#define CLK PORTA.0
#define DATA PORTA.2
#define LATCH PORTA.1
#define A1 PORTA.3
#define A0 PORTA.4
#define byte PORTA.5
#define rc PORTA.6
#define busy PORTA.7
unsigned char digit[5];
void main(void)
{
unsigned char data,data2,data3,data4,i,j;
unsigned int final=0,fi2=0;
while(1)
{
rc = 1;
A1 = 0;
A0 = 0;
PORTG &= 0x00; // portg.2 (contc) = 0
byte = 0;
rc = 0;
delay_us(4);
rc = 1;
while(busy == 0);
data = PINC;
byte = 1;
for(i=0;i<1;i++) for(j=0;j<2;j++);
data2 = PINC;
data3 = ~ data;
data4 = ~ data2;
final = (data3<<8) + data4 + 1; // 2's complement
fi2=hex2dec(final); // getting decimal value
}
}
int hex2dec(unsigned int lnum)
{
unsigned char i=0;
unsigned int deci;
while(lnum > 10)
{
digit = lnum % 0x0a;
lnum = lnum / 0x0a;
i++;
}
deci = atoi (digit);
return deci;
}
NIKS