CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

help on 7 segment display multiplexing

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nerdnicky



Joined: 02 Aug 2013
Posts: 13

View user's profile Send private message

help on 7 segment display multiplexing
PostPosted: Sun Aug 11, 2013 1:05 am     Reply with quote

hey guys
I am using a bcd to 7 segment decoder 74ls47 and pic 16f684
to design a simple 0-99 counter ...
The decoder is connected to pins C0,C1,C2,C3 of the pic
..and i also have connected two bc 547 npn transistors to the two select lines of the 7 segments to pins C4 and C5 .....
The code which i am posting is just disgusting....
I am not really able to understand how the multiplexing could take place....
and how the two segments may display dissimilar characters eventhough sharing the same lines.....
guys if anyone could help me...
I shall be highly obliged to him......
Code:

 #include <16f684.h>
#use delay(clock=4000000)
#fuses NOWDT

const char LED_DIGIT[10] =
{
  0b000000,
  0b000001,
  0b000010,
  0b000011,
  0b000100,
  0b000101,
  0b000110,
  0b000111,
  0b001000,
  0b001001
};

int i,j=0,k;

void main()
{
  setup_comparator(NC_NC_NC_NC);
  setup_adc(ADC_OFF);
  do
  {
   for(i=0;i<=99;i++)
   {
    output_high(PIN_C5);
    delay_ms(200);
    output_c(LED_DIGIT[i]);
    if(i>=9)
    {
     output_low(PIN_C5);
     output_high(PIN_C4);
     delay_ms(200);
     output_c(LED_DIGIT[i]);
    }
   }
  }
  while(1==1);
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Aug 11, 2013 3:54 am     Reply with quote

Muxing 7 segment displays has been done loads of times.
You could try a search on this forum and google.

I didn't think anyone was still using 74LS47's.
I'm assuming you're using common anode LEDs.
(And current limiting resistors.)

You don't tell us how you've connected the NPN devices.
(Really, I believe you should be using PNPs connected common emitter.)
With the decoders in place you should not need the lookup table at all.
The decoder does that job for you.

You're trying to run before you can walk, or even crawl.
Your delays are far too long.

You eventually need two loops:-
Inner loop to MUX display. This loop is fast. Makes both LEDs appear to be ON.
Outer loop to control counting. This slower loop goes at counting speed.

Start by getting inner loop to display say '0' on one display and '3' on the other.
This inner loop needs to go round faster than you can see.
Say 100 loops per second.

Inner loop then goes like this.

1) Turn all LEDs off.
2) Activate LED anodes for units.
3) Activate LED cathodes for units.
4) Wait 5ms.
5) Turn all LEDs off.
6) Activate LED anodes for tens.
7) Activate LED cathodes for tens.
8) Wait 5ms.
9) Loop back to 1.

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19550

View user's profile Send private message

PostPosted: Sun Aug 11, 2013 4:19 am     Reply with quote

The core 'part' of this has nothing to do with C, but vision....

Have you ever done the old 'make a animated book' as a child?.
You take a little notebook, with multiple pictures slightly different on the pages, and flick through them. Instead of seeing the individual static pictures you see the animated 'movie'.
Now, imagine you did exactly the same, but drew numbers on the pages. On the first page you drew a '1', and a space. On the second you drew a space where the '1' was, and a '2' where the space was. You duplicated these through the whole book. Flick through these. Provided you flick fasr enough, instead of seeing 1, then 2, you would see '12'. This is the 'core' of multiplexing.
The same was happening on your old TV, The picture on that was being drawn literally 'dot at a time', multiple times per second, yet display a static picture, and you don't see it flashing on and off, or the fact that only a little bit of the picture is on at any one time.
The key in both cases is _speed_.

For multiplexing, you have one set of lines saying which 'segments' you want to turn on, and a separate set of lines to say 'which digit' you want on. Then you turn on the segment pattern for (say) '1', and the digit line for the first digit. Leave this on for a moment, then switch the digit off, and turn on the segment pattern for '2', and the digit line for the second digit. Repeat. Provided each digit is 'on' at least perhaps 25* per second, your eye sees both digits as being 'on'.

Now the code you have posted, is not fast enough to multiplex.
There are a lot of problems with it.

The speed is much too slow. If the 'delay_ms(200)' was replaced with delay_us, it would get closer. However you'd then need to be counting slower.

Then, since you have an external bcd to seven segment decoder, you don't need an array lookup. This is done where you are driving the segments directly with the PIC., If you look at the numbers in your array, they are just 0 to 9. All the array is doing, is wasting time and space....
The array also has just ten entries, so how can the array lookup work when you go beyond nine?.

Now generally, you'd probably do the multiplexing with a timer interrupt, but I've shown how to do it more crudely. However timing will not then be accurate.

Code:

#include <16f684.h>
#use delay(clock=4000000)
//Er. where is your oscillator selection?. Crystal, etc... Necessary.
#fuses NOWDT

//Generally keep variables local, unless they need to be global.
//This is a 'general programming' comment

void display_digits(int8 value)
{
   int8 loop;
   int8 low,high;
   high=value/10;
   low=value-(high*10);
   //get the two BCD digits required.
   for (loop=0;loop<50;loop++)
   {
       output_c(low); //output the low digit
       //This will also set C4, and C5 low
       output_high(pin_c5); //turn on first digit only
       delay_ms(4); //display for 4mSec
       output_c(high); //output the high digit
       //Again this will also set C4, and C5 low
       output_high(pin_c4); //turn on just the second digit
       delay_ms(4); //and again display for 4mSec
    }
}
//Now this loops 50*, taking just over 8mSec each time, so gives
//just over 400mSec displaying the two digits from the 'value'.
//125Hz multiplexing.

void main(void)
{
  int8 j;
  setup_comparator(NC_NC_NC_NC);
  setup_adc(ADC_OFF);
  do
  {
      for(i=0;i<=99;i++)
      {
         display_digits(j);
      }
  }
  while(TRUE);
}

So, to display the number I loop fifty times outputting digit1,digit2 etc., fast enough that the eye should be fooled.

Best Wishes
nerdnicky



Joined: 02 Aug 2013
Posts: 13

View user's profile Send private message

PostPosted: Sun Aug 11, 2013 5:37 am     Reply with quote

thanks mike .......
thanks Ttelmah.....
Ttelmah you explained the concept in such a nice way.... i have never seen such a fluency in anybody else........you are a genius.....
thanks a lot.....
i shall work harder and try to grasp the concepts......thanking you....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group