Show a number on a 7-segment LED display using an LED driver chip

back to main tutorial page

Dr Nathan Scott & Dr Hiroyuki Kagawa · July 2002

In the previous tutorial you will have set up a single 7-segment LED display using the "direct drive" approach.

In this section I will show you how to connect a 7-segment LED display to the AVR using a special purpose "LED driver" chip, which uses fewer of the available data pins on the AVR.

LED表示専用ICを使った7セグLEDによる数字表示

戻る

ネーサン・スコット(訳:香川博之)  · 20027

前章では7セグLEDを直接接続する方法について学習した。ここではAVRの数本の端子を利用するだけですむLED表示専用ICを使う方法について説明する。


BCD-to-7-segment driver ICs

The IC we will use is the DM7447A. However the data sheet for that model is not as useful as the data sheet for a similar device, the CA3161. In Figure 1 I have combined data from each of these sheets.

  • Implement the circuit shown in Figure 1 on your breadboard. (you will definitely need the 220 ohm resistors if using the 7447 driver. If you have a CA3161 then you should leave them off).


BCD-to-7-seg 専用IC

DM7447AというICを使う。しかし,そのデータシートは同様の専用ICであるCA3161ほど役に立たない。. 図1には両方のデータシートを組み合わせて示す。

  • ブレッドボード上で図1のような配線をする。 (you will definitely need the 220 ohm resistors if using the 7447 driver. If you have a CA3161 then you should leave them off).

Figure 1 Using the DM7447A to drive a 7-segment LED display such as the Agilent HDSP-5501

  • Now open the project "seven_seg_drv.prj" using ICCAVRIDE. The source file "seven_seg_drv.c" contains the following code:
  • ICCAVRIDE で「seven_seg_drv.prj」ファイルを開く。「seven_seg_drv.c」というソースファイルは以下のように記述されている。

 

/*
Code for a crash course in AVR programming
Example "seven_seg_drv.c"
Dr Nathan Scott, July 2002
 
This program drives an external 7-segment common-anode LED display
using a BCD-to-7-segment driver IC such as the DM7447A
*/
 
 
#include "environment.h"
#include "delay.h"
 
 
void Idle()
// ignore this for now, it is used by the UART code in a later example
{
}
 
void main()
{
    char i;
 
    // set up control over PORTC
    PORTC = 0; // put a definite start value into the register for PORTC
    // - it's best not to leave this to chance
 
    DDRC = 0x0F; // set the direction of some of the pins of PORTC to "output".
    // note that we do not take control of the high 4 pins of PORTC, they
    // can be used for some other function.
 
    while (1) // endless loop, will run forever
    {
        for (i = 0; i < 0x0F; i++) // 16 possible combinations
        {
            PORTC = (PORTC & 0b11110000) | i ;
            DelayMs(100); // human beings need time to read
        }
    }
}

Figure 2 Example program to count through the 16 possible symbols

  • Compile the project and download the hex file to the AVR.
  • As soon as the project is downloaded, your 7-segment display should start running rapidly. Most of the symbols displayed should look like numbers; some may not be numbers.
  • プロジェクトをコンパイルし,HEXファイルをAVRに転送する。
  • データがAVRに転送されるとすぐに,7セグ表示器が速く動作する。ほとんどのパターンが数字を表示するが,数字以外もある。

Exercises

  • Explain why some of the displayed symbols are not numbers.
  • Modify the program so that it only counts from 0 to 9, and make the numbers change at the rate of about one per second.
  • Modify the program and the hardware wiring diagram so that the decimal point on the display is turned on but only for the ODD numbers (1, 3, 5, 7 and 9). (Hint - you will need to use another pin on the AVR, very much as you did in the "direct connection" tutorial.
  • Add another "digit" to the left of your first digit on the board. Connect up a second 7447 to drive it.
  • Modify the software so that it counts from 0 to 99.
  • Can you make the decimal point on the most significant digit (the left one) turn on for only the EVEN numbers?
  • Advanced exercise: modify the software so it counts from -9 to 99.

The CA3161 driver is good because

  1. It has a constant current output stage, no resistors are needed;
  2. It can drive at higher current than the AVR can do directly, it could drive a large LED panel if necessary.
  3. It greatly simplifies the software because the detail of which LEDs are turned on is now hidden inside the external IC;
  4. It means we only need 5 pins on the AVR to take full control of the LED. The AVR has up to 32 pins for general I/O so in theory we could drive 6 LED segments and have 2 pins left over.

The disadvantages of the 7447 are

  1. It does NOT have a constant current output stage, 220 ohm resistors are needed.
  2. It is an external component which costs a (small) amount of money;
  3. It can only drive the LED to show certain symbols. In an unusual application you might wish to show some of the other combinations of the segments.

In later tutorials we will explore other ways to further extend the usefulness of the available IO pins, and thus make the AVR do more complex tasks.

Return to the main tutorial page

演 習

  • どうして数字以外のパターンも表示されるのかを説明する。
  • プログラムを修正し,1秒ごとに0から9までの数字をカウントするようにする。
  • プログラムと配線を修正し,奇数(13579)のときに小数点が点灯するようにする。(ヒント:AVRの他の端子を利用し, 直接接続による方法と同様にする。)
  • ブレッドボードにある表示器の左側に桁を増やし,7447を追加してそれを駆動する。
  • プログラムを修正して0から99までカウントするようにする。
  • 偶数のときに最大桁数字の小数点を点灯させることができるか。
  • 応用演習:プログラムを修正し-9から99までカウントするようにする。

CA3161専用ICの長所

  1. 定電流出力であるため抵抗器が不必要である。
  2. AVRで直接駆動するよりも大電流を流せるので,必要に応じて大きなLED表示器を駆動できる。
  3. LED表示パターン生成はICが受け持つのでプログラムが非常に簡単になる。
  4. AVRの5つの端子を使うだけで全てのLEDを制御することができる。AVRIOとして32端子まで利用できるので6桁のLED表示器に接続でき,さらに2個端子が余る。.

7447専用ICの短所

  1. It does NOT have a constant current output stage, 220 ohm resistors are needed.
  2. 外部部品になるために少しお金がかかる。
  3. LED表示器に限られたパターンしか表示させることができない。特殊なアプリケーションではいくつかの他のパターンが必要になるかもしれない。

後章では,便利なIOの使い方を調査して,AVRにもっと複雑な作業をさせる。

メインページに戻る


Dr Nathan Scott · nscott@mech.uwa.edu.au