STC89C52 microcontroller digital tube dynamic display

Publisher:technology78Latest update time:2022-10-20 Source: csdnKeywords:STC89C52 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Digital tube dynamic display

Static and dynamic display

dynamic display

The characteristic of dynamic display is that the segment selection lines of all digital tubes are connected in parallel, and the bit selection lines control which digital tube is effective. The selected digital tube adopts dynamic scanning display. The so-called dynamic scanning display is to send glyph codes and corresponding bit selections to each digital tube in turn. It uses the afterglow of the luminescent tube and the persistence of human vision to make people feel as if all the digital tubes are displaying at the same time.


Array definition and reference

An array is a collection of ordered data, and each data in the array is of the same data type. Elements in an array can be uniquely identified by the array name and subscript.


The general format of an array is defined as follows:


Data type array name [constant expression] = {element list};


For example:

unsigned char tabel[3] = [0x3F, 0x06, 0x5B,];

P0 = tabel[0]; //The value of P0 at this time is 0x3F


Digital tube dynamically displays the number 123

#include

#include


#define uint unsigned int

#define uchar unsigned char


sbit DU = P2^6;//digital tube segment selection

sbit WE = P2^7;//Nigital tube segment selection


// Millisecond delay function definition

void delay(uint z){ // Millisecond delay function definition

uint x, y;

for (x = z; x > 0; x--){

for (y = 114; y > 0; y--){

}

}

}


void main(){ // The main function itself will loop

while(1){

/*The first digit displayed is 1*/

    P0 = 0XFF; // Clear the broken code.   If the value 0XFF is not initialized for P0, then the value of P0 will be the value assigned in the previous process of opening the segment selection latch. When executed here, the segment selection value will be assigned to P0 in the latch. , causing the digital tube to display errors.

WE = 1; //Open bit select latch

P0 = 0XFE; // 1111 1110 strobe the first digital tube

// P0 = 0X00; // 0000 0000 means strobing all digital tubes

WE = 0; //Latch bit selection data

DU = 1; //Open segment selection latch

P0 = 0X06; // 0000 0110 displays "1"

DU = 0; //Latch segment selection data

delay(5); // Perform a 5 millisecond delay operation for each digital tube switching



/*The second digit displays number 2*/

  P0 = 0XFF; // Clear break code

WE = 1; //Open bit select latch

P0 = 0XFD; // 1111 1101 strobe the second digital tube

// P0 = 0X00; // 0000 0000 means strobing all digital tubes

WE = 0; //Latch bit selection data

DU = 1; //Open segment selection latch

P0 = 0X5B; // 0101 1011 displays "2"

DU = 0; //Latch segment selection data

delay(5);



/*The third digit displays the number 3*/

P0 = 0XFF; // Clear break code

WE = 1; //Open bit select latch

P0 = 0XFB; // 1111 1011 strobe the third digital tube

// P0 = 0X00; // 0000 0000 means strobing all digital tubes

WE = 0; //Latch bit selection data

DU = 1; //Open segment selection latch

P0 = 0X4F; // 0100 1111 displays "3"

DU = 0; //Latch segment selection data

delay(5);


}

}


Digital tube dynamically displays the number 123 (code optimization)

#include //Includes 51 header file

#include //Includes the shift standard library function header file


#define uint unsigned int

#define uchar unsigned char


sbit DU = P2^6;//digital tube segment selection

sbit WE = P2^7;//Nigital tube segment selection


//Common cathode digital tube segment selection table 0-9

uchar code tabel[]= {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F,};


/*====================================

Function : delay(uint z)

Parameter : z delay millisecond setting, value range 0-65535

Return value : None

Description : 12T/Fosc11.0592M millisecond delay

====================================*/

void delay(uint z)

{

uint x,y;

for(x = z; x > 0; x--)

for(y = 114; y > 0; y--);


/*====================================

Function : display(uchar i)

Parameter : i displays the numerical value, the value range is 0-255

Return value : None

Description : Three-digit common cathode digital tube dynamic display

====================================*/

void display(uchar i)

{

uchar bai, shi, ge;

bai = i / 100; //236 / 100 = 2

shi = i % 100 / 10; //236 % 100 / 10 = 3

ge = i % 10;//236 % 10 =6

//The first digital tube 

P0 = 0XFF;//Clear broken code

WE = 1;//Open bit selection latch

P0 = 0XFE; //1111 1110

WE = 0; //Latch bit selection data

DU = 1; //Open segment selection latch

P0 = tabel[bai];//

DU = 0; //Latch segment selection data

delay(5);


//The second digital tube

P0 = 0XFF;//Clear broken code

WE = 1;//Open bit selection latch

P0 = 0XFD; //1111 1101

WE = 0; //Latch bit selection data

DU = 1; //Open segment selection latch

P0 = tabel[shi];//

DU = 0; //Latch segment selection data

delay(5);


//The third digital tube

P0 = 0XFF;//Clear broken code

WE = 1;//Open bit selection latch

P0 = 0XFB; //1111 1011

WE = 0; //Latch bit selection data

DU = 1; //Open segment selection latch

P0 = tabel[ge];//

DU = 0; //Latch segment selection data

delay(5);

}


void main()//main function itself will loop

{

while(1)

{

display(123); //Nigital tube display function

}

}  


The digital tube dynamically displays the number 12345678 (code optimization)

#include //Includes 51 header file

#include //Includes the shift standard library function header file


#define uint unsigned int

#define uchar unsigned char


sbit DU = P2^6;//digital tube segment selection

sbit WE = P2^7;//Nigital tube segment selection


//Common cathode digital tube segment selection table 0-9

uchar code tabel[]= {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F,};


/*====================================

Function : delay(uint z)

Parameter : z delay millisecond setting, value range 0-65535

Return value : None

Description : 12T/Fosc11.0592M millisecond delay

====================================*/

void delay(uint z)

{

uint x,y;

for(x = z; x > 0; x--)

for(y = 114; y > 0; y--);


/*====================================

Description : Eight-bit common cathode digital tube dynamic display

====================================*/

void display(uchar num1, uchar num2, uchar num3, uchar num4, uchar num5, uchar num6, uchar num7, uchar num8)

{

/*Display the first position*/

P0 = 0XFF;//Clear broken code

WE = 1;//Open bit selection latch

P0 = 0XFE; //1111 1110

WE = 0; //Latch bit selection data

DU = 1; //Open segment selection latch

P0 = tabel[num1];//

DU = 0; //Latch segment selection data

delay(1);


/*The second digit is displayed*/

P0 = 0XFF;//Clear broken code

WE = 1;//Open bit selection latch

P0 = 0XFD; //1111 1101

WE = 0; //Latch bit selection data

DU = 1; //Open segment selection latch

P0 = tabel[num2];//

DU = 0; //Latch segment selection data

delay(1);


/*The third digit is displayed*/

P0 = 0XFF;//Clear broken code

WE = 1;//Open bit selection latch

P0 = 0XFB; //1111 1011

WE = 0; //Latch bit selection data

DU = 1; //Open segment selection latch

P0 = tabel[num3];//

DU = 0; //Latch segment selection data

delay(1);


/*The fourth digit is displayed*/

P0 = 0XFF; // Clear break code

WE = 1; //Open bit select latch

P0 = 0XF7; // 1111 0111 strobe the fourth digital tube

WE = 0; //Latch bit selection data

DU = 1; //Open segment selection latch

P0 = tabel[num4];//

DU = 0; //Latch segment selection data

delay(1);


/*fifth digit display*/

P0 = 0XFF; // Clear break code

WE = 1; //Open bit select latch

P0 = 0XEF; // 1110 1111 strobe the fifth digital tube

WE = 0; //Latch bit selection data

DU = 1; //Open segment selection latch

P0 = tabel[num5];//

DU = 0; //Latch segment selection data

delay(1);


/*The sixth digit is displayed*/

P0 = 0XFF; // Clear break code

WE = 1; //Open bit select latch

P0 = 0XDF; // 1101 1111 strobe the sixth digital tube

WE = 0; //Latch bit selection data

DU = 1; //Open segment selection latch

P0 = tabel[num6];//

DU = 0; //Latch segment selection data

delay(1);


/*The seventh digit is displayed*/

P0 = 0XFF; // Clear break code

WE = 1; //Open bit select latch

P0 = 0XBF; // 1011 1111 strobe the seventh digital tube

WE = 0; //Latch bit selection data

DU = 1; //Open segment selection latch

P0 = tabel[num7];//

DU = 0; //Latch segment selection data

delay(1);

/*Eighth digit display*/

P0 = 0XFF; // Clear break code

WE = 1; //Open bit select latch

P0 = 0X7F; // 0111 1111 strobes the eighth digital tube

WE = 0; //Latch bit selection data

DU = 1; //Open segment selection latch

P0 = tabel[num8];

DU = 0; //Latch segment selection data

delay(1);

}


void main()//main function itself will loop

{

while(1)

{

display(1, 2, 3, 4, 5, 6, 7, 8); //Nigital tube display function

}

}

Keywords:STC89C52 Reference address:STC89C52 microcontroller digital tube dynamic display

Previous article:STC89C52 microcontroller independent keyboard
Next article:STC89C52 microcontroller digital tube static display

Recommended ReadingLatest update time:2024-11-16 13:03

How to use STC89C52 microcontroller to make a multiple signal generator
First, paste the simulated circuit diagram below (the simulation software is Protuse, upload a larger diagram so that everyone can see it clearly): Original parts list: STC89C52 microcontroller . Simulation requires these original parts. The specific hardware design is finalized and is being produced~ Upload the C p
[Microcontroller]
How to use STC89C52 microcontroller to make a multiple signal generator
NRF24L01 sending program (the microcontroller is STC89C52)
Free microcontroller tutorials and learning help you solve the difficulties encountered in learning microcontrollers. I have seen many friends on the Internet always fail to debug the NRF24L01 program. The following sending program was tested by me personally. The program is as follows: #include reg52.h #include i
[Microcontroller]
STC89C52 MCU 12864 LCD display
///////////////////////////////////////////////////////////////////////   Function:  Display the Chinese characters you want to display on the LCD12864 on the experimental board, so as to achieve         the purpose of learning to operate 12864   Experimental board model: KBL-XYD-C52   Experiment name:  LCD12864 Ch
[Microcontroller]
51 single chip microcomputer STC89C52 lights up multiple LEDs (byte operation of IO port)
Program source code /*-----------------------Include header file area-------------------------*/ #include reg52.h   //MCU header file  /*-----------------------Main function area-----------------------------*/ void main() { P2=0x0F;  //The upper four bits of the P2 port output low level, and the lower four bits
[Microcontroller]
51 single chip microcomputer STC89C52 lights up multiple LEDs (byte operation of IO port)
STC89C52 microcontroller lights up the LED light
Light up the LED light 1. What is LED The full name of LED is semiconductor light-emitting diode. It is made of semiconductor materials and is a light-emitting device that directly converts electrical energy into light energy and electrical signal into optical signal. It is characterized by low power consumption, high
[Microcontroller]
STC89C52 microcontroller lights up the LED light
Single chip control dot matrix rectangle shrinking flashing source program
Download the schematic used in this program:  click here  , the microcontroller chip used is stc89c52; find the schematic of the dot matrix part. This is the circuit diagram of the entire microcontroller development board. Ignore the others. The following is the program source code: /** *Function: Rectangle shrink
[Microcontroller]
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号