Show a number on a 7-segment LED displayDr Nathan Scott & Dr Hiroyuki Kagawa · July 2002 You should now have an AVR set up on a breadboard. In this section I will show you how to connect a 7-segment LED display to the AVR so that the AVR can show human users a decimal number. I will show you two ways to do this, first by directly connecting the AVR to the LED unit; and then (in the next tutorial) using a special purpose "LED driver" chip, which uses fewer of the available data pins on the AVR. |
7セグLEDによる数字表示ネーサン・スコット(訳:香川博之) · 2002年7月 これまでの作業でAVRをブレッドボードに取り付けることができた。ここでは,7セグLEDをAVRにどのように接続するかを示す。これにより10進数を表示することができるようになる。まず,そのLEDをAVRに直接接続する方法について説明する。次章ではAVRの数本の端子を利用するだけですむLED表示専用ICを使う方法について説明する。 |
|
|
|

Figure 1 Direct connection between the AVR and a common-anode 7-segment LED display such as the Agilent HDSP-5501
|
|
/*
Code for a crash course in AVR programming
Example "seven_seg.c"
Dr Nathan Scott, July 2002
This program drives an external 7-segment common-anode LED display
directly using PORTC
*/
#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 = 0xFF; // set the direction of all the pins of PORTC to "output".
while (1) // endless loop, will run forever
{
for (i = 0; i < 0xFF; i++)
{
PORTC = i; // this will turn on a unique combination
// of the 8 LEDs in the display! However only a few such
// combinations will be recognisable as numbers!
DelayMs(100); // human beings need time to read
}
}
}
|
Figure 2 Example program to make a confusing display
|
|
Exercises
|
演 習
|