Smarthome Remote Control System Producer

KinCony Electronic —- makes our life more beautiful quality more excellent and life more intelligent

7.6. Experiment with LED Display

Posted by admin July - 27 - 2010 - Tuesday

In normal system, LED and LCD are common output interface. LED display can be found in various devices and machines. It is a cheap, high-luminance, versatile display.

This experiment discusses the basic operation on LED. It’ll show you how to display 0 to 9 in the 1st LED display.

The Fundamentals of LED Display

LED display is composed by 8 light emitting diodes, among which 7 diodes form the numerical number 8, and 1 diode represent the dot (decimal point).

According to the driving mode, LED can be divided to 2 types, common-anode and common-cathode. A common-anode LED display is that the one with 8 LEDs’ anodes connecting together. A common-cathode LED display is that the one with 8 LEDs’ cathodes connecting together. See the below diagram.

To make a LED display show the numerical number, we need to light on and off certain segments (diodes). For example, to display number 5, segment A, C, D, F, G should be light on. Thus expect for P0.1, P0.4, P0.7, the rest P0.0, P0.2, P0.3, P0.5, P0.6 should all be set to 1, high level.

Segment DP G F E D C B A code
Pin P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0
“5” 0 1 1 0 1 1 0 1 0x6d

Likewise, we can list the table of display code for 0 to 9. Below is the table for common-anode and common-cathode.

Numeric number 0 1 2 3 4 5 6 7 8 9
common-cathode 0x3F 0×06 0x5B 0x4F 0×66 0x6D 0x7D 0×07 0x7F 0x6F
common-anode 0xC0 0xF9 0xA4 0xB0 0×99 0×92 0×82 0xF8 0×80 0×90

Circuit Design

Software Design

01 #include <reg51.h>

02

03 unsigned char code Tab[]={ 0xC0,0xF9,0xA4,0xB0,0×99,0×92,0×82,0xF8,

04 0×80,0×90,0×88,0×83,0xC6,0xA1,0×86,0x8E};

05 sbit S1 = P2^0;

06

07 void Delay()

08 {

09 unsigned char i,j;

10 for(i=0;i<255;i++)

11    for(j=0;j<255;j++);

12 }

13

14 void main()

15 {

16 unsigned char i = 0;

17 S1 = 0;

18  while(1)

19  {

20    P0= Tab[i];

21    Delay();

22    i++;

23    if(i>9) i =0;

24  }

25 }

Program Notes

Line 1: include the 8051 register definition header file

Line 3-4: define common-anode display code table

Line 5: sbit define common control S1

Line 7-12: delay function

Line 14: main function

Line 16: define local variable i for counting

Line 17: give power to LED S1

Line 18: loop

Line 20: output display code to P0

Line 21: invoke delay function

Line 22: increment i

Line 23: limit i to be in the range from 0 to 9

Program for Multiple LED displays

The above experiment shows you how to display a single LED, but how do we make multiple LEDs display? Time sharing is a technique people often used to display more than 1 LED display. See the below codes.

01 #include <reg51.h>

02

03 unsigned char code Tab[]={ 0xC0,0xF9,0xA4,0xB0,0×99,0×92,0×82,0xF8,

04 0×80,0×90,0×88,0×83,0xC6,0xA1,0×86,0x8E};

05 sbit S1 = P2^0;

06 sbit S2 = P2^1;

07 sbit S3 = P2^2;

08 sbit S4 = P2^3;

09

10 void Delay()

11 {

12 unsigned char i;

13 for(i=0;i<255;i++);

14 }

15

16 void main()

17 {

18  while(1)

19  {

20    P0= Tab[1];

21 S1 = 0; //turn on S1

22    Delay();

23 S1 = 1; //turn off S1

24

25    P0= Tab[2];

26 S2 = 0; //turn on S2

27    Delay();

28 S2 = 1; //turn off S2

29

30    P0= Tab[3];

31 S3 = 0; //turn on S3

32    Delay();

33 S3 = 1; //turn off S3

34

35    P0= Tab[4];

36 S4 = 0; //turn on S4

37    Delay();

38 S4 = 1; //turn off S4

39  }

40 }

From line 20 to 38, we can see the whole time sharing procedure. Firstly, display code is output on data bus P0, then turn on a LED, delay a certain time, and then turn off it. Repeat this until 4 LED is all turn on for once. Then restart the procedure again. To make the most of human-being’s retentivity of vision, care should be taken with these points. To avoid the LED flashing, delay time should not be too long. To have equal luminance, each delay time must be the same. To increase the luminance, delay time can be shortened. If there are double images on LED, LED should be turn on and then turn off.

Leave a Reply

Universal Programmer | Gang Programmer | Device Programmer | ISP Programmer | Eeprom Programmer | IC Programmer
Copyright © 2003-2012 Programmerkit.com All Rights Reserved.
Add:Rm 852,4F,Zhejiang Shidai Electronics Market,Dengyun Rd 428, Hangzhou, Zhejiang, China. P.C.:310011