How to shift decimal point on seven segment displays.

Discussion in 'Programmer's Corner' started by shivalitambe, Jul 3, 2014.

  1. shivalitambe

    Thread Starter New Member

    Jul 3, 2014
    8
    0
    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....
     
  2. MrCarlos

    Active Member

    Jan 2, 2010
    400
    134
    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?
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    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:

    Code ( (Unknown Language)):
    1.  
    2. if (number < 1)
    3. {
    4.     // light 1st dp .---
    5. }
    6. elseif (number < 10)
    7. {
    8.     // light 2nd dp -.--
    9. }
    10. elseif (number < 100)
    11. {
    12.     // light 3rd dp --.-
    13. }
    14. elseif (number < 1000)
    15. {
    16.     // light 1st dp ---.
    17. }
    18. else
    19. {
    20.     // good lord how did you get here?
    21.     // the number is too large to display
    22. }
    23.  
    Note with no idea how your hardware connects I have no suggestion about how one lights a decimal point.
     
    absf likes this.
  4. shivalitambe

    Thread Starter New Member

    Jul 3, 2014
    8
    0
    Hello MRCARLOS

    Thanks for ur reply.

    yes 4 7 segments are multiplexed.
     
  5. shivalitambe

    Thread Starter New Member

    Jul 3, 2014
    8
    0
    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.
     
  6. shivalitambe

    Thread Starter New Member

    Jul 3, 2014
    8
    0
    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.?
     
  7. shivalitambe

    Thread Starter New Member

    Jul 3, 2014
    8
    0
    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...
     
  8. sanuzr

    New Member

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

    AAC Fanatic!

    Apr 11, 2010
    2,809
    834
    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.
     
  10. shivalitambe

    Thread Starter New Member

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


    Code ( (Unknown Language)):
    1.  
    2. unsigned char ds1,ds2,ds3,ds4;    
    3. float i,t,t1,t2,v;
    4. unsigned long int adc_data,num,p,kw,kvar,kva;
    5. unsigned int d,set_value=0xd2,digit,j;
    6. float x,y,pf;
    7.  
    8. sbit sl1=P0^7;     //select lines for display
    9. sbit sl2=P0^6;
    10. sbit sl3=P0^5;
    11. sbit sl4=P0^4;
    12.  
    13. sbit a=P3^6;       //for channel selection c is msb
    14. sbit b=P3^7;
    15. sbit c=P3^2;
    16.  
    17. //ADC pin selection
    18. sbit start=P3^0;
    19. sbit ale=P3^5;
    20. sbit eoc=P3^1;
    21. sbit oe=P3^4;
    22.  
    23. void display();
    24. unsigned char lookup(int x);
    25. void delay();
    26. void adc();
    27. void control(int num);
    28.  
    29. void main()                  
    30. {
    31. ds1='0';
    32. ds2='0';
    33. ds3='0';
    34. ds4='0';
    35.  
    36. while(1)
    37. {
    38.  
    39. a=0;          // select channel in0
    40. b=0;
    41. c=0;
    42.  
    43. adc();
    44.  
    45. v=adc_data*19.6;
    46. num=v;
    47. display();
    48.  
    49. a=1;      //seect channel in1
    50. b=0;
    51. c=0;
    52.  
    53. adc();
    54. i=adc_data*19.6;
    55. num=i;
    56. display();
    57.  
    58.   p=v*i;        //apparant power
    59.   num=p;                                                                            
    60.  // led3=0xff;      //led on for power
    61.   display();
    62.  
    63.  
    64.   a=0;       // select channel for t1      in2
    65.   b=1;
    66.   c=0;
    67.  
    68.   adc();
    69.   t1=adc_data;
    70.  
    71.   a=1;           //select channel for t2     in3
    72.   b=1;
    73.   c=0;
    74.  
    75.   adc();
    76.   t2=adc_data;
    77.  
    78.   t=t1-t2;
    79.   x=(2*3.14*50*t)/1000;
    80.   pf=cos(x);               //display power factor
    81.   display();
    82. }
    83.  
    84. void adc()
    85.  {
    86. ale=0;
    87. oe=0;            
    88. start=0;
    89.  
    90. ale=1;
    91. delay();
    92. ale=0;
    93.  
    94. start=1;
    95. delay();
    96. start=0;
    97.  
    98.  while(!eoc)     //monitor eoc
    99.  {
    100.  }
    101.   oe=1;
    102.  
    103.   adc_data=P3;
    104.   delay();
    105.    
    106.     oe=0;
    107. }
    108.                                                                                                                                                                                                                                                                                                                                                                                                                                                              
    109. void display()
    110. {
    111. sl1=0;                            //display1 initialisation
    112. sl2=1;
    113. sl3=1;
    114. sl4=1;
    115.  
    116. digit=num%10;
    117. ds1=lookup(digit);
    118. delay();
    119.  
    120. sl1=1;                            //display2 initialisation
    121. sl2=0;
    122. sl3=1;
    123. sl4=1;
    124.  
    125. digit=(num/10)%10;
    126. ds2=lookup(digit);
    127. delay();
    128.  
    129. sl1=1;                            //display3 initialisation
    130. sl2=1;
    131. sl3=0;
    132. sl4=1;
    133.  
    134. digit=(num/100)%10;
    135. ds3=lookup(digit);
    136. delay();
    137.  
    138. sl1=1;                            //display4 initialisation
    139. sl2=1;
    140. sl3=1;
    141. sl4=0;
    142.  
    143. digit=(num/1000);
    144. ds4=lookup(digit);
    145.  delay();
    146.  
    147. //range();
    148.  
    149. ds1=ds2=ds3=ds4=0;
    150. //delay();
    151. }
    152. unsigned char lookup(int x)
    153. {
    154. switch(x)    
    155. {
    156. //  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
    157. case 0: return 0x88;
    158. case 1: return 0xeb;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
    159. case 2: return 0x4c;
    160. case 3: return 0x49;
    161. case 4: return 0x2b;
    162. case 5: return 0x19;
    163. case 6: return 0x18;
    164. case 7: return 0xcb;
    165. case 8: return 0x08;
    166. case 9: return 0x09;
    167. case 10:return 0xf7; for dp
    168.  
    169. }
    170. }
    171.  
    172. void delay()
    173. {
    174. for(j=0;j<1275;j++);
    175. }
    176.  
     
    Last edited by a moderator: Jul 9, 2014
  11. shivalitambe

    Thread Starter New Member

    Jul 3, 2014
    8
    0
    Anyone, plz chk my code and suggest changes in it....
     
Loading...