[STC MCU learning] Lesson 7: Single-chip microcomputer control static/dynamic digital tube

[Mr. Zhu's course summary intrusion]


The first part, chapter list

1.7.1. What is a digital tube

1.7.2. Preliminary drive of static digital tube

1.7.3. Static digital tube display numbers

1.7.4. Let the digital tube display 0 to f in sequence

1.7.5. Dynamic digital tube

1.7.6.38 Decoder Introduction

1.7.7. Dynamic digital tube display programming actual combat 1

1.7.8. Dynamic digital tube display programming combat 2


Part Two, Classroom Record


1.7.1. What is a digital tube


1.7.1.1. Look at the
appearance of the digital tube (1) in several aspects

Digital tube image results


(2) Function: The nixie tube is a display device, used to display numbers: more used in industrial occasions!
(3) Classification: single (1 digit), row (2 digits, 4 digits, 8 digits)


1.7.1.2. Working principle
(1) Principle of light-off (actually the internal lighting LED)

There are 8 LEDs in a digital tube.


(2) The principle of displaying numbers (or even text): Use the on and off of the internal LED to display or not display the external strokes that make up the numbers. What people see are different numbers. It's very similar to lighting! For example, the following: display 2, 8

Digital tube image results

1.7.1.3, common anode and common cathode digital tube
(1) the difference in driving methods

It must be clear that the 8 LEDs inside a nixie tube are independently driven . If the positive poles of 8 LEDs are connected together to VCC (the negative poles are connected to different pins of the microcontroller), this connection is called common anode (LED lights in the previous lesson). On the contrary, if the negative poles of 8 LEDs are connected together and then connected to GND (the positive poles are respectively connected to different pins of the microcontroller), it is called a common cathode. Both connection methods can drive the digital tube display, but the MCU program used for display is different (the single-chip microcomputer 0 is bright when the anode is common, and the single-chip 1 is bright when the cathode is common ).


(2) Difference in drive current demand

If the digital tube (actually LED) is connected according to the common anode, the microcontroller can directly drive the display. If the common cathode is connected, the microcontroller cannot be directly driven because the current provided by the IO port of the microcontroller is not enough to drive the LED display inside the digital tube. Circuit to provide a high-current drive chip to solve. ( See the old version schematic 74HC573).


1.7.1.4. Static and dynamic digital tubes: in fact, they are all the same, they are all digital tubes! The display method is different!
(1) Use difference 

Static face separate digital tube, dynamic row!
(2) Difference in circuit connection


1.7.2. Preliminary drive of static digital tube


1.7.2.1. Schematic diagram analysis
1.7.2.2. Wiring
(1) Conclusion: The P0 port of the microcontroller is directly connected to the cathode of the common anode digital tube . Therefore, when the microcontroller outputs 0, the nixie tube is on , and when it outputs 1, the nixie tube is off . The experimental verification result is ok.


1.7.2.3. Programming lighting is the same as the small light
(1) P0 = 0x0; 8 segments are all on
(2) P0 = 0xff; 8 segments are all off
(3) P0 = 0x0f; 4 segments are on and 4 segments are off
(4) P0 = 0xfe ;

1.7.2.4. Verify that the segment number of the digital tube in the schematic diagram is correct
(1) The 8 segments of the digital tube are actually 8 LEDs, corresponding to the 8 pins of the IO port P0 (P0.0, P0.1····P0 .7) So who corresponds to whom?
  Look at the picture
(2) Theoretically, you can analyze the schematic diagram and the wiring method to guess the corresponding relationship (the segment code of the digital tube) . Error-prone
(3) In actual combat, you usually write your own code to test.
    P0 = 0xfe; // 11111110 P0.0 output 0 actual measurement corresponds to the nixie tube a segment
    P0 = 0xfd; // 11111101 P0.1 output 0 actual measurement corresponds to the b segment
    P0 = 0xfb; // 11111011 P0.2 output 0 actual measurement corresponds to the c segment
    P0 = 0xf7; // 11110111 P0.3 output 0 actual measurement corresponding to segment d
    P0 = 0xef; // 11101111 P0.4 output 0 actual measurement corresponding to e segment
    P0 = 0xdf; // 11011111 P0.5 output 0 actual measurement corresponding to f segment
    P0 = 0xbf; // 10111111 P0.6 output 0 actual measurement corresponds to g segment
    P0 = 0x7f; // 01111111 P0.7 output 0 actual measurement corresponds to dp segment
    
Note: Among the 8 binary bits of port P0, the high bit corresponds to P0.7, and the low bit corresponds to P0.0

1.7.2.5. Thinking: How does the digital tube display numbers?
(1) The nixie tube displays the numbers, in fact, the nixie tube lights up the corresponding segments. In fact, it is to make the corresponding pin of the IO port output 0 (other pins output 1), which actually corresponds to an 8-bit binary number.
(2) The conclusion is: P0 port outputs an appropriate number of bytes, and the digital tube will display the corresponding number. Each number will have a corresponding 8-bit binary number, the key is to get the 8-bit binary number.
For example: to get "A", as long as the d and dp segments are off, that is: 0x88 //10001000


1.7.3. Static digital tube display numbers


1.7.3.1. The acquisition of digital code (segment code)
means that if we want to display a number, we have to know which segments are needed to display the number, so the following table is the lighting of different digital tube LED lights corresponding to different numbers, and corresponding The segment code binary and hexadecimal that the IO port of the MCU connected to it should output.

要显示的数字  数码管亮的LED                段码二进制   十六进制
0               abcdef                  11000000    0xC0
1               bc                      11111001    0xf9
2               abdeg                   10100100    0xA4
3               abcdgh                  10110000    0xb0
4               bcfg                    10011001    0x99
5               acdfg                   10010010    0x92
6               acdefg                  10000010    0x82
7               abc                     11111000    0xf8
8               abcdefg                 10000000    0x80    
9               abcdfg                  10010000    0x90
A               abcefg                  10001000    0x88
b               cdefg                   10000011    0x83
C               adef                    11000110    0xc6
d               bcdeg                   10100001    0xA1
E               adefg                   10000110    0x86
F               aefg                    10001110    0x8e


1.7.3.2, programming verification

Just pick a few displays~

Use the P0 port to connect the digital tube pin (J8), create a new project, the following code can realize the static digital tube display number 0

#include <reg51.h>


void main(void)
{
    while(1)
    {
        P0 = 0xC0;
    }
}

phenomenon:

1.7.3.3. Conclusion
(1) Different digital code (segment code) tables may be completely different
(2) Different code tables may be completely different for the same digital tube wiring mode
(3) After the hardware is confirmed, the experiment can be carried out by debugging. Determine the code table

Numbers will change, methods will not change!


1.7.4. Let the digital tube display 0 to f in sequence


1.7.4.1. Stupid way: divided state
state + delay, the code is as follows:

#include<reg52.h>

void delay(void)
{
	unsigned char i = 200;
	unsigned char j = 300;
	
	while(i--)
		while(j--);
}
void main()
{
		while(1)
		{

			P0 = 0xc0;		//0
			delay();
			
			P0 = 0xf9;		//1
			delay();
			
			P0 = 0xa4;		//2
			delay();
			
			P0 = 0xb0;		//3
			delay();
			
			P0 = 0x99;		//4
			delay();
			
			P0 = 0x92;		//5
			delay();
			
			P0 = 0x82;		//6
			delay();
			
			P0 = 0xf8;		//7
			delay();
			
			P0 = 0x80;		//8
			delay();
			
			P0 = 0x90;		//9
			delay();
			
			P0 = 0x88;		//A
			delay();
			
			P0 = 0x83;		//b
			delay();
			
			P0 = 0xc6;		//C
			delay();
			
			P0 = 0xa1;		//d
			delay();
			
			P0 = 0x86;		//E
			delay();
			
			P0 = 0x8e;		//F
			delay();	
		}
}


1.7.4.2. Upgrade method: use array

#include<reg52.h>

//利用数组来显示静态数码管数字
void delay(void)
{
	unsigned char i = 200;
	unsigned char j = 300;
	
	while(i--)
		while(j--);
}

void main()
{
		unsigned char val[16] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90, 0x88, 0x83, 0xc6, 0xa1, 0x86, 0x8e};
		unsigned char i = 0;
		
		while(1)
		{
				for(i = 0;i<16;i++)
				{
						P0 = val[i];
						delay();
				}
		}
}

Before the next class, ask yourself to adapt the above code: let the digital tube display only even numbers (0,2,4...), not odd numbers
1.7.4.3. Summary
(1) Different features of C language are used in different places, which can be simplified Programming
(2) The C language array starts from 0, pay attention not to cross the boundary, this is very important


1.7.5. Dynamic digital tube


1.7.5.1 Defects of static nixie tube driving method
(1) The advantage is that the drive is simple and direct, and it is easy to program.
(2) The defect is that each nixie tube needs 1 port, and the port of the single-chip microcomputer is not enough.
Solution: Use dynamic mode to drive multiple Digital Tube


1.7.5.2 What is a dynamic digital tube?
(1) The digital tube or the original digital tube (both common anode or common cathode). Remember: the digital tube has 2 ends: COM (common) end and segment end, as shown in the figure below :

This is a common cathode digital tube  


(2) One side of the segment code (J6) is still connected to a MCU port


(3) COM (common pole) is connected to one IO port of the single-chip microcomputer, and the COM of multiple serial digital tubes is connected to an IO port. One COM is a common level, which is different from static and directly connected to VCC/GND.
Analysis and comparison of static and dynamic Nixie tube, found that the essential difference is: in the static digital tube, as long as the segment code is given, the digital tube must work (the display only depends on the segment code end), and the segment code end of the dynamic nixie tube needs the COM end to cooperate. Light up the digital tube .

1.7.5.3. How does the dynamic digital tube work (we are the common cathode dynamic digital tube)
(1) In a certain period of time, only one digital tube in the row of digital tubes is working, and the others are resting (not working). Note Don't doubt this, I will explain it later! !
(2) The COM terminal selects which digital tube to work , the segment terminal outputs the segment code of the digital tube to be displayed; delay; the COM terminal selects the next digital tube to work, and the segment terminal changes to output this digital tube to display The segment code of the number; delay; the COM terminal selects the next digital tube to work······
(3) Quickly switch the working digital tube, then what people see is that all the digital tubes are bright (in fact, the brightness is Lower than static drive). Persistence of vision

Find out 2 points:
First, all the digital tubes are on at the same time in the macro, so people think that all the digital tubes work at the same time, so multiple digital tubes can be combined to display (for example, display 12345678 )
. The nixie tubes light up sequentially, we can send different segment codes to different nixie tubes, so different nixie tubes can display different numbers. Therefore, the display equivalent to 8 digital tubes is independent.


1.7.6.38 Introduction to Decoder

1.7.8.1 Why introduce 38 decoder
(1) The role of 38 decoder: use 3 IO ports to control 8 outputs.

CBA     对应Yx(x:0-7) 
000        0
001        1
010        2
011        3
100        4
101        5
110        6
111        7

3位到8位的映射(编码)

What is the output, and the first pin is pulled low!
(2) Significance of driving the digital tube with 38 decoder: After using 38 decoder, we can use 3 inputs of 38 decoder to control 8 bit codes of digital tube , so that only 3+8 are needed in total =11 IO pins can drive 8 dynamic nixie tubes.

The J10 pin of 38 decoder can be directly connected to J1 of dynamic digital tube.
Schematic diagram:

Physical map:
 


1.7.8.2, 74LS138 data sheet
(1) focus on understanding the truth table

 


(2) G1, G2A and G2B are the enable pins
(3) ABC is the encoding terminal, Y0-Y7 is the output terminal


1.7.7. Dynamic digital tube display programming actual combat 1

The goal of this section: First experiment to get the segment code table of the digital tube
1.7.7.1 Wiring
(1) Wiring determination: P0 connects to J6, P2.0-P2.2 connects to the ABC terminal of the 38 decoder, and J10 connects to J1
(2) P2.2-P2.4: 000 The 0th nixie tube is on, 001 The first nixie tube is on...
(3) The segment code end gives different values ​​to test to get the segment code table

Step 1: First test P0.0-P0.7 and abcdefg. How do they correspond?
Experimental test conclusion: P2.0--P2.2: 000 is the first digital tube, 111 is the eighth digital tube!
                         P0.0 corresponds to a (P0.1 corresponds to b·····P0.7 corresponds to dp)

显示      对应段           P0二进制        对应十六进制
0         abcdef           00111111         0x3f
1         bc               00000110         0x06
2         abdeg            01011011         0x5b
3         abcdg            01001111         0x4f
4         bcfg             01100110         0x66
5         acdfg            01101101         0x6d
6         acdefg           01111101         0x7d
7         abc              00000111         0x07
8         abcdefg          01111111         0x7f
9         abcdfg           01101111         0x6f
A         abcefg           01110111         0x77
b         cdefg            01111100         0x7c
C         adef             00111001         0x39
d         bcdeg            01011110         0x5e
E         adefg            01111001         0x79
F         aefg             01110001         0x71

Segment code table: 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71

1.7.7.2, sbit definition bit variables

(1) before programming are all To directly operate an IO port, you can use the port name (P0, P1) to operate the 8 pins of an IO port as a whole. But this method cannot control a single IO port.
(2) Today, programming requires a separate operation of an IO pin. For example, to operate P3.4, the C language is not recognized when writing P3.4 directly, and the sbit keyword must be used to define a pin. We also used it in the first class!
sbit SER = P3^4;

1.7.7.3, introduction of macro definition and typedef
uchar, u8

typedef unsigned char u8;

#define uchar unsigned char

 Note: #define and typedef should be written as far forward as possible!


1.7.8. Dynamic digital tube display programming actual combat 2

Goal of this section: Use 38 decoder and dynamic digital tube to realize 8 connected digital tube display 12345678
(1) Programming idea: first select the first digital tube, then send the segment code of 1 to the segment code end, and then delay for a while; Then switch to select the second nixie tube, and then send the segment code of 2 at the segment code end, and then delay for a while;...until the eighth nixie tube is displayed as a cycle; this cycle is infinite loop.
Note: The delay should be just right, not only can not be detected by the eyes, but also to ensure that all digital tubes are on at the same time!

Experimental conclusions:
1. The delay time is too long, otherwise the numbers will flash.
2. After shortening the time, there are three problems: the first is that the light is not bright enough, the second is that the dark is not dark enough, and the third is that one of the numbers (1) is obviously defective.

Reason: The segment codes of different numbers overlap!

Solution:  blank out when each digital tube is turned on and switch to the next one.
Blanking: After each light is finished, the segment code is all 0, so that all segments are not lighted! //P0=0x00;

The first improvement to the program: put the segment code in the array to check the array.
Second step improvement: use switch-case for COM option code

/**************************************************************************************
接线说明: 单片机-->动态数码管模块(具体接线图可见开发攻略对应实验的“实验现象”章节)
				J22-->J6
				P22-->J9(A)
				P23-->J9(B)
				P24-->J9(C)		
注意事项:																				  
***************************************************************************************/

#include "reg51.h"			

typedef unsigned char u8;

sbit LSA=P2^0;
sbit LSB=P2^1;
sbit LSC=P2^2;

u8 smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//显示0~F的值


void delay(unsigned char i)
{
	while(i--);	
}

/*******************************************************************************
* 函 数 名         : DigDisplay
* 函数功能		   : 数码管动态扫描函数,循环扫描8个数码管显示
*******************************************************************************/
void DigDisplay()
{
	u8 i;
	for(i=0;i<8;i++)
	{
		switch(i)	 //位选,选择点亮的数码管,
		{
			case(0):
				LSA=0;LSB=0;LSC=0; break;//显示第0位
			case(1):
				LSA=1;LSB=0;LSC=0; break;//显示第1位
			case(2):
				LSA=0;LSB=1;LSC=0; break;//显示第2位
			case(3):
				LSA=1;LSB=1;LSC=0; break;//显示第3位
			case(4):
				LSA=0;LSB=0;LSC=1; break;//显示第4位
			case(5):
				LSA=1;LSB=0;LSC=1; break;//显示第5位
			case(6):
				LSA=0;LSB=1;LSC=1; break;//显示第6位
			case(7):
				LSA=1;LSB=1;LSC=1; break;//显示第7位	
		}
		P0=smgduan[i];//发送段码
		delay(100); //间隔一段时间扫描	
		P0=0x00;//消隐
	}
}

void main()
{	
	while(1)
	{	
		DigDisplay();  //数码管显示函数	
	}		
}

Program download link for this lesson: digital tube

This lesson is over!
 

Guess you like

Origin blog.csdn.net/qq_27148893/article/details/109441396