Pages: 1 [2]   Go Down
Author Topic: A simple single digit seven segment display  (Read 2413 times)
0 Members and 1 Guest are viewing this topic.
Beijing
Offline Offline
Full Member
***
Karma: 3
Posts: 193
Skype name habib.derbyshire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you very much. I might have a little trouble figuring it out, but I'll try. Thanks again
Logged

What is man's best friend? The breadboard!

Beijing
Offline Offline
Full Member
***
Karma: 3
Posts: 193
Skype name habib.derbyshire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you very much!. I may have a little trouble with it but I'll figure it out. Thanks again! smiley smiley smiley
Logged

What is man's best friend? The breadboard!

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What you really want to do, in order to benefit from your efforts in writing this piece of code, is to make it flexible and modular enough so that you can re-use it sometime down the road.

The issue with typical LED displays, and the benefits of using chips like max72xx, is that they have to be constantly updated in a multiplexing environment. That means you cannot put them into a loop yet be assured of the performance in any given projection.

The purpose of my proposal is to make the LED display look like a controller-based LCD display: all you need to be concerned about is the buffer and the actual display related activities are handled behind the scenes, completely transparent to you.
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To get you started, think of the segment led displays as a dot matrix display. Your display routines are simply transmitting the buffer data to the segment pins / digit pins. Your user application can load up whatever segment information they want into the buffer and it will be displayed there.

Let's say that you are dealing with a 8-digit 7-segment display, common cathod (aka max7219 clone).

You need to figure out a flexible way to define the segment pins
Code:
#define SEG_A  2 //led's segment A connected to pin 2
#define SEG_B  5 //led's segment B connected to pin 5
...
#define SEG_DP 10 //led's segment DP connected to pin 10

//macros to turn on / off a pin, common cathod
#define SEG_ON(pin)  pinWrite(pin, HIGH)
#define SEG_OFF(pin) pinWrite(pin, LOW)

Similarly, you can define the digital pins
Code:
#define DIG0  11  //digit0 on pin 11
..
#define DIG7  13  //digit7 on pin 13

//macros to turn on / off a digit pin, common cathod
#define DIG_ON(pin)  pinWrite(pin, LOW)
#define DIG_OFF(pin) pinWrite(pin, HIGH)

Now, those routines are for common cathode displays. But by changing them quickly, you can reuse the same macro names in a common anode display, or to use a npn switch / pnp switch. The rest of your code remains unchanged.

Using pin names helps repurpose the code in different project, or to facilitate layout / wiring.
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

With that out of the way, you can write a fairly simple display routine:

Code:
volatile unsigned char led_buffer[DIGS_MAX]; //display buffer. DIGS_MAX defines the max number of led digits allowed

void led_display(void) {
  static unsigned char dig=0; //digital counter

  dig += 1; //increment the digit
  if (dig == DIGS_MAX) dig = 0; //reset dig if max digit has been reached

  //turn off all digits
  DIG_OFF(DIG0); DIG_OFF(DIG1); ...

  SEGs_OUT(led_buffer[dig]); //send out segment information

  //turn on the digit
  //can be implemented more cleanly with an array
  switch (dig) {
    case 0: DIG_ON(DIG0); break;
    case 1: DIG_ON(DIG1); break;
  ...
  }
}


So each time, led_display() is called, it displays a number on the led.
Logged

Pages: 1 [2]   Go Up
Jump to: