Make the 51 single-chip eight-segment digital tube light up

Publisher:梅花居士Latest update time:2021-10-29 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Basic part of eight-segment digital tube

1. Common cathode and common anode of eight-segment digital tube

An eight-segment digital tube is composed of eight segments of diodes, namely a, b, c, d, e, f, g, dop (dots), with a total of eight segments. There are two types of digital tubes, common cathode and common anode (common anode: the anodes of the digital tube are all connected together, and a low level lights it up. If it is a common anode, a low level lights it up.)

2. Bit code and segment code of eight-segment digital tube

Generally, a four-digit digital tube has four pins to control which digital tube is selected (bit selection), and the 8-bit segment selection is common, that is, when the bit selection is the first bit, the segment selection code is only related to the segments that light up the first bit. Similarly, when the second bit is selected, the segment code is only valid for the second bit, and so on. . . . Generally, after the hardware structure is determined, the term segment code and bit code will appear. For example, the four bit selection pins are connected to the microcontroller p2.2 2.3 2.4 (these three ports are the 74HC138 decoder ports), and the light-emitting tube is a common cathode, then the bit code of the first bit is xxxx1110; the second bit is xxxx1101; the third bit is xxxx1011; the fourth bit is xxxx0111; so when I display, if the first bit of data is displayed, xxxx1110 is sent to the p2 port, and then the segment code of the first bit is sent.


2. Eight-segment digital tube dynamic display

The so-called static display means that each segment code of the digital tube must occupy an output port with a latch function. The CPU sends the character code to be displayed to the output port, and the digital tube can display the corresponding character. The displayed content will not disappear until the next time another character code is sent. Dynamic display has the advantages of stable display, high brightness, and saving CPU time, but it occupies more I/O ports and has high hardware costs.


1. Eight eight-segment digital tubes dynamically scan 0 to 7 for a running display

#include

#define uchar unsigned char

#define uint unsigned int

sbit LSA=P2^2; //74HC138 decoder port

sbit LSB=P2^3;

sbit LSC=P2^4;


//Common anode digital tube coding table

uchar code table1[] ={0xc0,0xf9,0xa4,0xb0,

                      0x99,0x92,0x82,0xf8,

                      0x80,0x90,0x88,0x83,

                      0xc6,0xa1,0x86,0x8e};


//Common cathode digital tube coding table

uchar code table2[] ={0x3f,0x06,0x5b,0x4f,

                      0x66,0x6d,0x7d,0x07,

                      0x7f,0x6f,0x77,0x7c,

                      0x39,0x5e,0x79,0x71};

//Delay

void DelayMS(uint x)

{

  uchar t;

  while(x--) 

    for(t=0;t<120;t++);

}

//Main program

void main()

{

  uchar i;

  while(1)

  {

    for(i=0;i<8;i++)

    {

  P0=0xff;

  LSA=0;LSB=0;LSC=0;

  P0=table2[0];

  DelayMS(100);

  LSA=1;LSB=0;LSC=0;

  P0=table2[1];

  DelayMS(100);

  LSA=0;LSB=1;LSC=0;

  P0=table2[2];

  DelayMS(100);

  LSA=1;LSB=1;LSC=0;

  P0=table2[3];

  DelayMS(100);

  LSA=0;LSB=0;LSC=1;

  P0=table2[4];

  DelayMS(100);

  LSA=1;LSB=0;LSC=1;

  P0=table2[5];

  DelayMS(100);

  LSA=0;LSB=1;LSC=1;

  P0=table2[6];

  DelayMS(100);

  LSA=1;LSB=1;LSC=1;

  P0=table2[7];

  DelayMS(100);

    }

  }

}


2. Eight eight-segment digital tubes dynamically scan 0 to 7 and display them constantly

#include

typedef unsigned int uint;

typedef unsigned char uchar;

sbit LSA=P2^2; //74HC138 decoder port

sbit LSB=P2^3;

sbit LSC=P2^4;

uchar out[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};

 

void delay(uint num)

{

while(num--);

}

 

void display()

{

uint i;

for(i=0;i<8;i++)

{

switch(i) //bit selection, select the digital tube to light up,

{

case(0):

LSA=0;LSB=0;LSC=0; break;//display bit 0

case(1):

LSA=1;LSB=0;LSC=0; break;//display the first bit

case(2):

LSA=0;LSB=1;LSC=0; break;//display the second digit

case(3):

LSA=1;LSB=1;LSC=0; break;//display the third bit

case(4):

LSA=0;LSB=0;LSC=1; break;//display the 4th bit

case(5):

LSA=1;LSB=0;LSC=1; break;//display the 5th bit

case(6):

LSA=0;LSB=1;LSC=1; break;//display the 6th bit

case(7):

LSA=1;LSB=1;LSC=1; break;//display the 7th bit

}

P0=out[i]; //Send segment code

delay(100); //Scan after a certain period of time

P0=0x00; //Blanking

}

}

 

void main()

{

while(1)

{

display(); 

}

}


3. Eight-segment digital tube static display

Dynamic display is to connect the same segments of A-dp in the 8 segment codes of all displays together and connect them to a common output port, while the bit ends of the digital tubes are connected to other output ports respectively, and the display effect is produced through the interaction of the two groups of signals of these two output ports. That is, let each digital tube display in turn in a certain order. As long as the scanning frequency is high enough, due to the "visual persistence" phenomenon of the human eye, it can be displayed continuously and stably. Dynamic display can significantly reduce the cost of the display part and greatly reduce the wiring structure of the display interface.


1. A digital tube static display 0 to 9

#include

#define uchar unsigned char

#define uint unsigned int


//Common anode digital tube coding table

uchar code table1[] ={0xc0,0xf9,0xa4,0xb0,

                      0x99,0x92,0x82,0xf8,

                      0x80,0x90,0x88,0x83,

                      0xc6,0xa1,0x86,0x8e};


//Common cathode digital tube coding table

uchar code table2[] ={0x3f,0x06,0x5b,0x4f,

                      0x66,0x6d,0x7d,0x07,

                      0x7f,0x6f,0x77,0x7c,

                      0x39,0x5e,0x79,0x71};


//Delay

void DelayMS(uint x)

{

uchar t;

while(x--) 

  for(t=0;t<120;t++);

}


//Main program

void main()

{

uchar i=0;

P0=0x3f;

for(; i < 10; ++i)

    {


      P0 = table2[i];

      if(i == 9)

      i = 0;

  DelayMS(300);

    }

    while(1);

}

Reference address:Make the 51 single-chip eight-segment digital tube light up

Previous article:Study Notes: 51 MCU Keyboard
Next article:51 single chip microcomputer uses three methods to realize the water lamp

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号