Xiaobai self-study c51 notes digital tube 2

Publisher:温柔的爱情Latest update time:2022-04-19 Source: eefocusKeywords:C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Dynamic digital tube principle:

First, a schematic diagram:

insert image description here

The digital tube is actually composed of multiple LEDs (the decimal point is also one), as shown in the picture above, an 8 plus a decimal point is a digital tube, a total of eight LEDs, and the picture above shows eight digital tubes.

Digital tubes can be divided into common cathode and common anode digital tubes according to different connection methods. Literally, common cathode means the cathodes of the eight segments of a digital tube are connected together, and common anode means the anodes of the eight segments of a digital tube are connected together.

I would like to state that my digital tube is common cathode.

Below are two static digital tubes (I think the dynamic digital tube is to remove the GND and VCC in the two pictures below and connect them to other tube ports):

Common cathode:

insert image description here

Common Anode:

The upper right corner is 5v, which is VCC high voltage. The picture shows a static digital tube.

The upper right corner is 5v, which is the VCC high voltage

As long as the voltage of a~g and dp is controlled, the brightness of the LED can be controlled.


The dynamic digital tube is different. For example, there are eight digital tubes in the first picture. If they are all like static digital tubes, 8×8=64 tube ports will be needed to control them. Therefore, the dynamic digital tube uses the dynamic scanning principle to achieve the purpose of lighting different numbers (or letters: A, b, C, d, E, F) on different digital tubes.


Dynamic scanning, as the name suggests, means scanning, which means that one digital tube lights up one at a time, but because the human eye has persistence of vision, as long as the lighting period is short enough through appropriate delay so that the previous digital tube is still bright in our eyes when the next digital tube lights up, our goal can be achieved - they light up together.


In this way, we can use eight ports to control which digital tube is lit, and use eight ports to control which LED segments of the digital tube are lit. A total of 16 ports are used, which greatly reduces the number of ports required. In addition, with a 38 decoder, 3 channels of input, and 8 channels of output, only 3+8=11 ports are needed to control eight digital tubes.


There are two concepts here, segment selection and bit selection.


Position selection: "Position", as the name suggests, selects which position of the digital tube to light up.


Segment selection: "Segment", select which "segments" of the selected digital tube will light up.


From the schematic diagram given at the beginning, we can see that the eight ports of P0 control the segment selection (it is easy to see which port controls which LED segment from the diagram). The purpose of passing through D74HC245 first is to increase the drive. If the current of the microcontroller is not enough, the digital tube will be very dim (some people say that the current of the common cathode will not be enough, and the common anode can be driven directly. I don't understand it. I need to check it out). If you want to know which port of the microcontroller controls the bit selection, there is another picture:

insert image description here

Based on the previously known functions of this chip, we can control the input values ​​of P2^2, P2^3, and P2^4 to control which of Y0 (upper horizontal line) to Y7 (upper horizontal line) outputs low voltage. The digital tube connected to the port that outputs low voltage is selected.


If you want the digital tube to light up, you must input a high voltage on the segment selector to determine the value of the P0 port.


2. Dynamic digital tube programming:


#include

sbit LSA=P2^2;

sbit LSB=P2^3;

sbit LSC=P2^4;

unsigned int code smgduan[16]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; // Common cathode digital tube table, corresponding to the digital tube display 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, d, E, F; This is the array definition and initialization in C language


void delay(unsigned int i)    //custom function delay

{

    while(i--);

}

void bigdisplay()     //Custom function bigdisplay

{

  unsigned int i;

for(i=0;i<8;i++)     //for statement in C language

{

switch(i)     //C language switch statement , here is to deal with the problem of which digital tube is lit - bit selection

  {

   case 0:LSA=0,LSB=0,LSC=0;break;     //The value of i is the same as that of the case, which statement will be executed, and then the output state of the 38 decoder can be known from the truth table, and finally which digital tube will be lit (the thinking direction is opposite to this when programming)

   case 1:LSA=1,LSB=0,LSC=0;break;

   case 2:LSA=0,LSB=1,LSC=0;break;

   case 3:LSA=1,LSB=1,LSC=0;break;

   case 4:LSA=0,LSB=0,LSC=1;break;

   case 5:LSA=1,LSB=0,LSC=1;break;

   case 6:LSA=0,LSB=1,LSC=1;break;

   case 7:LSA=1,LSB=1,LSC=1;break;

  }

  P0=smgduan[i];     //Assign a value to P0, the value is the i-th number in the smgduan array above, note: start counting from 0; usage of arrays in C language; if i in this statement is replaced with i+8, the final effect diagram is as follows.

  delay(100);     //Call the delay function to delay, the delay should not be too short or too long

  P0=0x00;     //P0 is reset to zero, otherwise there will be interference when lighting the second digital tube, resulting in ghosting

}

}


void main()     //Main function

{

  while(1) // 1 always meets the loop condition and keeps looping the statements in {}    

{

bigdisplay(); //Call the function bigdisplay compiled above. If you do not customize the function bigdisplay, you can also write the program directly in the main function main

}

}


Effect:

1. Original code:

insert image description here

2. After replacing the i specified in the above code: Remember to read from right to left

Keywords:C51 Reference address:Xiaobai self-study c51 notes digital tube 2

Previous article:Independent keys of Xiaobai's self-study C51 notes
Next article:Xiaobai's self-study notes on C51 digital tube 1——D74HC245 and D74HC138

Latest Microcontroller Articles
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号