Static and dynamic display of digital tube on 51 single chip microcomputer

Publisher:VelvetDreamerLatest update time:2022-05-24 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Introduction of TX1C digital tube

Common cathode and common anode digital tubes. The experimental board has a common cathode digital tube, a 6-bit digital tube.

insert image description here

The connection principle diagram is as follows: the segment lines (segment selection lines, i.e. abcdefgh) connected together control which digital tube lights up, and the independent common end (bit selection line, i.e. common cathode or common anode) controls which digital tube lights up. Because the segment lines are connected together, the displayed numbers are the same, and the common cathode end is an independent common end, so the lower six bits control which digital tube lights up. Using two latches, any digital tube can be controlled to display any number.

insert image description here
insert image description here

1. Static display of digital tube

Static display means that the numbers displayed on the digital tubes with the bit selection turned on are the same because the segment selections are connected together.

1. The first three digits of the digital tube display 666


#include

sbit temperature=P2^7;

sbit dula=P2^6;

void main()

{

wela=1; //The bit selection is turned on, that is, the latch end is set high, and the output of the latch changes with the input

P0=0xf8; //1111 1000, the first three digits are lit

wela=0; //bit selection is off, that is, the latch end is set low, the latch maintains the previous state, that is, the first three digital tubes are lit


game=1;

P0=0x7d; //Display 6 digits on the digital tube, 0111 1101

game=0;

while(1)

{

}

}

2. The 6-digit digital tube displays 996ICU at 500 millisecond intervals


#include

sbit dula=P2^6;

sbit temperature=P2^7;

unsigned char code table[]={0x3f,0x06,0x5b,0x4f,

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

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

0x39,0x5e,0x79,0x71,0x3e}; //0 to F encoding, the last one is U, 0011 1110

void delayms(unsigned int xms)

{

unsigned int i,j;

for(i=xms;i>0;i--)

for(j=110;j>0;j--);

}

void main()

{

temperature=1;

P0=0xc0; //1100 0000, six digital tubes light up

temperature=0;

while(1)

{

game=1;

P0=table[9]; //The array starts from 0 and displays 9

game=0;

delayms(500);


game=1;

P0=0;

game=0;

delayms(300); //Due to two consecutive 9s, the middle is off for 300 milliseconds


game=1;

P0=table[9];

game=0;

delayms(500);

game=1;

P0=table[6]; //display 6

game=0;

delayms(500);


game=1;

P0=table[1]; //Since I cannot be displayed, use 1 instead

game=0;

delayms(500);


game=1;

P0=table[12]; //Display C

game=0;

delayms(500);


game=1;

P0=table[16]; //Display U

game=0;

delayms(300);

}

}


Because of the two 9s in the middle, the display effect is not very good.

insert image description here

2. Dynamic display of digital tube

The so-called dynamic display is to display numbers from the first digital tube to the last digital tube in sequence, and delay the display of numbers so that each digital tube displays them in sequence, and then shorten the time very short. The digital tubes display them in turn at high speed, which cannot be seen by the human eye, giving the feeling that they are displayed simultaneously.

The following code shows the words 996ICU


#include

#define uint unsigned int //macro definition, rename unsigned int to uint for easy use

sbit dula=P2^6;

sbit temperature=P2^7;

unsigned char code table[]={0x3f,0x06,0x5b,0x4f,

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

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

0x39,0x5e,0x79,0x71,0x3e}; //0 to F encoding, the last one is U, 0011 1110

void delayms(uint xms);

void main()

{

game=0;

wela=0;/*Turn off the bit selection. Otherwise, when the segment selection is just turned on, the digital tubes lit by ox6f will display 9, but it will be too fast to be seen by the eyes.

If you add a delay statement, you can see it. You can add while(1) after the first dula=0 statement below to test it*/

while(1)

{

game=1;

P0=table[9]; //The first digital tube displays 9

game=0;

P0=0xff; //Eliminate. If not added, before turning on the first digital tube, first turn on the bit select P0 with 9, which is 0x6f.

wela=1; //If the sequence runs too fast, it cannot be seen. If it runs slowly, the digital tubes will be confused.

P0=0xfe; //Turn on the first digital tube

temperature=0;

delayms(1);

wela=1; //If you do not add these three statements, you will see that the unlit part of the digital tube will have a weak brightness

P0=0xff; //The reason is that when executing downward, the bit selected fe is first selected for the following segment, and the first digital tube quickly displays fe

wela=0;/*Then the following table[9] is displayed on the first digital tube, because both numbers are 9, change the number

It is obvious, so there will be a weak brightness under high-speed display without delay. If it is slower, confusion may occur. All the displayed numbers

The reason why it is brighter is because of the delay, so just turning off the first digital tube will solve the problem. Because of the high-speed display, you won't see the first digital tube go out*/

  game=1;

P0=table[9];

game=0;

P0=0xff;

temperature=1;

P0=0xfd; //Turn on the second digital tube

temperature=0;

delayms(1);

temperature=1;

P0=0xff;

temperature=0;


game=1;

P0=table[6]; //display 6

game=0;

P0=0xff;

temperature=1;

P0=0xfb; //Turn on the third digital tube

temperature=0;

delayms(1);

temperature=1;

P0=0xff;

temperature=0;


game=1;

P0=table[1]; //Display I, replace with 1

game=0;

P0=0xff;

temperature=1;

P0=0xf7; //Turn on the fourth digital tube

temperature=0;

delayms(1);

temperature=1;

P0=0xff;

temperature=0;


game=1;

P0=table[12]; //Display C

game=0;

P0=0xff;

temperature=1;

P0=0xef; //Turn on the fifth digital tube

temperature=0;

delayms(1);

temperature=1;

P0=0xff;

temperature=0;


game=1;

P0=table[16]; //Display U

game=0;

P0=0xff;

temperature=1;

P0=0xdf; //Turn on the sixth digital tube

temperature=0;

delayms(1);

temperature=1;

P0=0xff;

temperature=0;

}

}


void delayms(uint xms)

{

uint i,j;

for(i=xms;i>0;i--)

for(j=110;j>0;j--);

}


At the beginning, set the delayms function to a longer time, delayms(500), so that it displays the content one by one at a speed of 0.5 seconds. Then slowly reduce the time to delayms(1) 1 millisecond to gain a deeper understanding.

insert image description here

Conclusion

1. Encoding method

The common cathode digital tube encoding on this experimental board is as follows: unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,

0x39,0x5e,0x79,0x71}; This code is 0 to F, that is, 0 is 0011 1111, 1 is 0000 0110. Different circuits may have different codes. You can code by knowing the principle of digital tube display. There is an additional code keyword after the array type. Note: Defining an array in a microcontroller occupies memory space, while defining a code is directly allocated to the program space. After compilation, the code occupies the program storage space, not the memory space.


2. It is very important to eliminate the shadow, otherwise the digital tube will be confused or there will be afterglow in the parts other than the numbers. In the second code, the closed bit selection is invisible to the human eye. The reason for the simultaneous display is the high-speed display and the afterglow effect after the diode is lit.

Reference address:Static and dynamic display of digital tube on 51 single chip microcomputer

Previous article:Keyboard detection principle of 51 single chip microcomputer
Next article:51 single chip microcomputer realizes the operation of running 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号