The use of blue bridge cup single chip microcomputer digital tube

1. Experimental tasks

(1), light up a digital tube,
the digital tube realizes the number you want
, combine the previous independent button knowledge, realize the combination of the digital tube and the key
(2), light up multiple digital tubes, the
digital tube realizes the combination you want,
combine the previous knowledge of the matrix key, realize the combination of the digital tube and the key

2. Principle analysis

insert image description here
How does the digital tube light up?
We can regard the digital tube as a combination of 8 LED lights, and different combinations of 8 LED lights form numbers or letters. Nixie tubes are divided into common cathode and common anode like LED lights, as shown in the figure above.
If the common anode digital tube, when the corresponding I/O port is 0, the corresponding segment lights up.
For example: we want to display the number 0 on the common anode digital tube, corresponding to the image on the left of the above picture, abcdef should be on, and others should be off.
The nixie tubes are respectively dp, g, f, e, d, c, b, a from high to low. The result is 1100 0000, which is 0xc0.

It is cumbersome to calculate once every time you use it, so we write all the digital tube displays in an array, and you can just copy and paste it next time you use it. Through the one-to-one correspondence between the array content and the array subscript, you can find the value we want to send to the digital tube by searching the subscript value.

In books, we will see a code identifier, which is used to store the constant array in ROM. The on-chip resources are limited, so some data that will not change, are called infrequently, and occupy a large amount of memory are stored in ROM.

Common anode digital tube segment selection table:
uchar code tab[]={0XC0, 0XF9, 0XA4, 0XB0, 0X99, 0X92, 0X82, 0XF8, 0X80, 0X90, 0XBF, 0XFF, 0XC6};
common cathode digital tube, expand the value in the above common anode digital tube array into binary, and just invert it.
For example: the value of 0 is 0xC0, the expansion is 1100 0000, and the inversion is 0011 1111, and the conversion to hexadecimal is 0x3F. The same goes for the rest.

One digital tube will occupy 8 I/O ports. When there are multiple digital tubes, it will occupy a large number of I/O ports. However, the number of I/O ports of the single-chip microcomputer itself is not very large, so when there are multiple digital tubes, through the dynamic scanning method, the digital tubes will be displayed one at a time, and the delay will be for a period of time. Using the visual residue of the human eye, people can see all the digital tube values ​​normally. This is the dynamic digital tube . What was explained before is the static digital tube .
During the operation of the dynamic digital tube, from a microscopic point of view, only one digital tube is on.
The single-chip microcomputer uses a 3-8 decoder to realize the dynamic digital tube. The number of I/O of the single-chip microcomputer is limited, and there are many functions that need to be realized on the board of the Blue Bridge Cup, so a latch is added to latch the current data and expand the function through the application of the latch.
For example: Let the second digital tube display the number 0.

P2=0xc0//打开数码管位选573锁存器
P0=0x02; //选中第二个数码管	
P2=0xe0//打开数码管段选573锁存器
P0=tab[0];//使数码管显示0

We will introduce the latch later, and now we only need to know how to use it.

3. Experimental process

(1), light up a digital tube
1, let the last digital tube display the number 1

#include<STC15F2K60S2.H>

void main(void)
{
    
    
	P2=0XA0;P0=0X00;P2=0X80;P0=0XFF;   //初始化程序  关闭蜂鸣器继电器,LED全部熄灭
	P2=0XC0;P0=0X01;P2=0XFF;P0=0XFF;   //数码管初始化程序,打开第一个数码管
	P0=0XF9;//P0=1111 1001 (b、c段亮,显示1)等同于 P00=1;P01=0;P02=0;P03=1;P04=1;P05=1;P06=1;P07=1;
	while(1);
}

2. Combined with independent buttons, each button is pressed to display different values

#include<STC15F2K60S2.H>
#define uchar unsigned char		
#define uint unsigned int		
uchar code tab[]={
    
    0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90,0XBF,0XFF,0XC6};

void DelayMs(uint ms)
{
    
    
	uint i,j;
	for(i=0;i<ms;i++)
		for(j=845;j>0;j--);
}
void keyscan()
{
    
    
if(P30==0)                     
	{
    
    
		DelayMs(10);   			//延时10ms,消除抖动
		if(P30==0)					
		{
    
    
			P0=tab[0];			
		}								
	while(!P30);		//松手检测
	}
	
	if(P31==0)                       //当检测到按键S6(对应P31口)按下时
	{
    
    
		DelayMs(10);   			//延时10ms,消除抖动
		if(P31==0)					
		{
    
    
			P0=tab[1];
		}
		while(!P31);
	}

	if(P32==0)                       //当检测到按键S5(对应P32口)按下时
	{
    
    
		DelayMs(10);   			//延时10ms,消除抖动
		if(P32==0)					
		{
    
    
			P0=tab[2];
		}
		while(!P32);
	}
	if(P33==0)                       //当检测到按键S5(对应P32口)按下时
	{
    
    
		DelayMs(10);   			//延时10ms,消除抖动
		if(P33==0)					
		{
    
    
			P0=tab[3];
		}
		while(!P33);
	}
}		
void main(void)
{
    
    
	P2=0XA0;P0=0X00;P2=0X80;P0=0XFF;   //初始化程序  
	P2=0XC0;P0=0X01;P2=0XFF;P0=0XFF;   //数码管初始化

	while(1)
	{
    
    
		keyscan();
	}
}

(2) Light up all the digital tubes
1. The digital tubes display 12345678

#include<STC15F2K60S2.H>
unsigned char tab[]={
    
    0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90,0XBF,0XFF,0XC6};
unsigned char num=99;
unsigned int i;
unsigned char yi,er,san,si,wu,liu,qi,ba;

void Delayms(int ms);
void display(unsigned char yi,unsigned char er,unsigned char san,unsigned char si,unsigned char wu,unsigned char liu,unsigned char qi,unsigned char ba);

void main(void)
{
    
    
	P2=0XA0;P0=0X00;P2=0X80;P0=0XFF; 
	yi=1;er=2;san=3;si=4;wu=5;liu=6;qi=7;ba=8;//将需要显示的下标值改为变量,这样改变变量即可改变显示字符,更具有灵活性
	display(yi,er,san,si,wu,liu,qi,ba);
	while(1);
}

void display(unsigned char yi,unsigned char er,unsigned char san,unsigned char si,unsigned char wu,unsigned char liu,unsigned char qi,unsigned char ba)
{
    
    
	P2=0XC0;				//打开数码管位选573锁存器
	P0=0X01;				//选中第一个数码管
	P2=0XE0;				//打开数码管段选573锁存器
	P0=tab[yi];				
	Delayms(1);
	
	P2=0XC0;				//打开数码管位选573锁存器
	P0=0X02;				//选中第二个数码管					
	P2=0XE0;				//打开数码管段选573锁存器
	P0=tab[er];				
	Delayms(1);	
	
	P2=0XC0;				//打开数码管位选573锁存器
	P0=0X04;				//选中第一个数码管
	P2=0XE0;				//打开数码管段选573锁存器
	P0=tab[san];			
	Delayms(1);
	
	P2=0XC0;				//打开数码管位选573锁存器
	P0=0X08;				//选中第二个数码管					
	P2=0XE0;				//打开数码管段选573锁存器
	P0=tab[si];				
	Delayms(1);	
	
	P2=0XC0;				//打开数码管位选573锁存器
	P0=0X10;				//选中第一个数码管				
	P2=0XE0;				//打开数码管段选573锁存器
	P0=tab[wu];				
	Delayms(1);
	
	P2=0XC0;				//打开数码管位选573锁存器
	P0=0X20;				//选中第二个数码管					
	P2=0XE0;				//打开数码管段选573锁存器
	P0=tab[liu];				
	Delayms(1);	

	P2=0XC0;				//打开数码管位选573锁存器
	P0=0X40;				//选中第一个数码管
	P2=0XE0;				//打开数码管段选573锁存器
	P0=tab[qi];	
	Delays(1);			
	
	P2=0XC0;				//打开数码管位选573锁存器
	P0=0X80;				//选中第二个数码管					
	P2=0XE0;				//打开数码管段选573锁存器
	P0=tab[ba];				
	Delayms(1);	
}

void Delayms(int ms)
{
    
    
	int i,j;
	for(i=0;i<ms;i++)
		for(j=845;j>0;j--);
}

2. Combined with the matrix buttons, each button is pressed to display different values
​​Similar to the previous use, only one step is required to separate the ones and tens.
yi=num/10;
er=num%10;

Summary
In this article, we have learned about static and dynamic digital tubes, combined with buttons, and reviewed the use of buttons by the way. During the introduction of the digital tube, we also mentioned the latch. For the use of the latch, at the current stage, we only need to remember how to use it, and there are no more requirements.

—————————————————————————————————————————
This article is purely original, if there is any infringement, please contact to delete, if there is any error, please criticize and correct, thank you all.

Guess you like

Origin blog.csdn.net/G_Shengn/article/details/112708886