# How to shift decimal point on seven segment displays.

#### shivalitambe

Joined Jul 3, 2014
8
Hello,

Is anyone can help me for my program to display voltage and current on 4 seven segment display.I am using 8052, adc 0809 in my proj & for programming Keil 4 using c. I hav used lookup table and m able to extract all the 4 nos. but problem is that how to shift decimal point for diff values like 12.33,9.999,999.9 etc.

Plz help me....

#### MrCarlos

Joined Jan 2, 2010
400
Hello shivalitambe

I can not imagine how your design is built.
The four 7-segment displays are connected to the multiplexing system?
Or, How are they connected?

In your lookup table, You could put that decimal point?
or not?

#### ErnieM

Joined Apr 24, 2011
8,082
You have a number to convert, somehow you extract the digits to get then thru your lookup table, so you must be familiar with scaling your numbers. Similarly you can checn the range of your number to see what decimal point to light:

Rich (BB code):
if (number < 1)
{
// light 1st dp .---
}
elseif (number < 10)
{
// light 2nd dp -.--
}
elseif (number < 100)
{
// light 3rd dp --.-
}
elseif (number < 1000)
{
// light 1st dp ---.
}
else
{
// good lord how did you get here?
// the number is too large to display
}
Note with no idea how your hardware connects I have no suggestion about how one lights a decimal point.

#### shivalitambe

Joined Jul 3, 2014
8
Hello MRCARLOS

yes 4 7 segments are multiplexed.

#### shivalitambe

Joined Jul 3, 2014
8
Thanx Ernime...

I thought like above logic. but how should i add no.for dp in lookup table for separate display as all are multiplexed.

#### shivalitambe

Joined Jul 3, 2014
8
I have one more problem,
I am sensing voltages , currents , calculating power factor using formula
t=t1-t2;
x=(2*3.14*50*t)/1000;
pf=cos(x);
i used float variables. but i dont know how to round off float no. upto 4 digits only as m using only 4 seven segmen displays.?

#### shivalitambe

Joined Jul 3, 2014
8
If anyone have program for displaying parameters like voltage, current, power factor, kva, kvar etc. plz send me. or plz help me how to display it using 4 seven segment displays. I am sensing voltage n current using zero crossing detectors, sending it to adc and 8052.

Plz help me...

#### sanuzr

Joined Mar 29, 2012
7
Can you please post your schematic ? because without knowing the hardware, it is near to impossible to explain the software.

#### djsfantasi

Joined Apr 11, 2010
7,226
Can you please post your schematic ? because without knowing the hardware, it is near to impossible to explain the software.
I second that. As far as scaling your floating point numbers, consider the following.

If the number is over 1000, take the integer portion. Save the decimal position as 0.*
If the number is between 100 and 1000, multiply by 10 and take the integer portion. Save the decimal position as 1.
Between 10 and 100, multiply by 100. The decimal position is 3.
Between 0 and 10, multiply by 1000 and the decimal position is 4.

Less than 0 may or may not be possible, depending on your hardware (what decimal points are available on the 7 segment displays).

* the decimal point indices depend on whether the dp appears to the right or left of the 7 segment displays. These assume they are positioned to the right.

#### shivalitambe

Joined Jul 3, 2014
8
PLZ see my code and help me to sort out the problems....and suggest corrections

Rich (BB code):
unsigned char ds1,ds2,ds3,ds4;
float i,t,t1,t2,v;
unsigned int d,set_value=0xd2,digit,j;
float x,y,pf;

sbit sl1=P0^7;     //select lines for display
sbit sl2=P0^6;
sbit sl3=P0^5;
sbit sl4=P0^4;

sbit a=P3^6;       //for channel selection c is msb
sbit b=P3^7;
sbit c=P3^2;

sbit start=P3^0;
sbit ale=P3^5;
sbit eoc=P3^1;
sbit oe=P3^4;

void display();
unsigned char lookup(int x);
void delay();
void control(int num);

void main()
{
ds1='0';
ds2='0';
ds3='0';
ds4='0';

while(1)
{

a=0;          // select channel in0
b=0;
c=0;

num=v;
display();

a=1;      //seect channel in1
b=0;
c=0;

num=i;
display();

p=v*i;        //apparant power
num=p;
// led3=0xff;      //led on for power
display();

a=0;       // select channel for t1      in2
b=1;
c=0;

a=1;           //select channel for t2     in3
b=1;
c=0;

t=t1-t2;
x=(2*3.14*50*t)/1000;
pf=cos(x);               //display power factor
display();
}

{
ale=0;
oe=0;
start=0;

ale=1;
delay();
ale=0;

start=1;
delay();
start=0;

while(!eoc)     //monitor eoc
{
}
oe=1;

delay();

oe=0;
}

void display()
{
sl1=0;                            //display1 initialisation
sl2=1;
sl3=1;
sl4=1;

digit=num%10;
ds1=lookup(digit);
delay();

sl1=1;                            //display2 initialisation
sl2=0;
sl3=1;
sl4=1;

digit=(num/10)%10;
ds2=lookup(digit);
delay();

sl1=1;                            //display3 initialisation
sl2=1;
sl3=0;
sl4=1;

digit=(num/100)%10;
ds3=lookup(digit);
delay();

sl1=1;                            //display4 initialisation
sl2=1;
sl3=1;
sl4=0;

digit=(num/1000);
ds4=lookup(digit);
delay();

//range();

ds1=ds2=ds3=ds4=0;
//delay();
}
unsigned char lookup(int x)
{
switch(x)
{
//  seg a=P2.5,b=P2.4,c=P2.2,d=P2.1,e=P2.2,f=P2.6,g=P2.7,dp=P2.3
case 0: return 0x88;
case 1: return 0xeb;
case 2: return 0x4c;
case 3: return 0x49;
case 4: return 0x2b;
case 5: return 0x19;
case 6: return 0x18;
case 7: return 0xcb;
case 8: return 0x08;
case 9: return 0x09;
case 10:return 0xf7; for dp

}
}

void delay()
{
for(j=0;j<1275;j++);
}

Last edited by a moderator: