# The dynamic display method and timer of the nixie tube

Keywords: github

The previous blog blog mainly recorded some simple external interrupts and timer usage. At that time, we would only let the designated nixie tube display the same number. In this blog, we will record several ways to let different nixie tubes display different numbers (also called dynamic display).

# 1, The sprout of dynamic display thinking

Let's imagine: because now we can only display a certain number at a time. Then, if we achieve this effect: (the following description stipulates that only one nixie tube can be lit at a certain time) the first nixie tube lights "1" in the first second, the second nixie tube lights "2", "6" in the second, and then repeat the above cycle.

If the interval time is not 1s, but a few milliseconds or even microseconds, then the human eye will not be able to distinguish, it looks like the effect of six nixie tubes displaying "123456" at the same time.

How can we achieve these ideas? ——By timer! We can let the timer time, every time we reach the specified time, we can move back one bit. Let's look at the code section:

## 1.1 code and experiment

The code is as follows:

```#include<reg52.h>
#define uchar unsigned char   //Macro definition
#define uint unsigned int

sbit WELA = P2^7;   //Define bit selection
sbit DULA = P2^6;   //Define segment selection

uchar number,position,t;
//Number indicates the number to be displayed, position indicates the position of the number display, and t indicates the timer timing time

uchar code table_DUAN[] = {0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};  //Define segment selection signal coding table (starting from 1)

uchar code table_WEI[] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf}; //Define bit selection signal coding table

void init();   //Initialization function, complete a series of operations such as starting timer, assigning initial value, etc

void main()
{
init();
while(1)
{
if(t == 1)
{
t = 0;
if(number == 6)     //Because we're up to six
{
number = 0;
}
if(position == 6)
{
position = 0;
}

DULA = 1;
P0 = table_DUAN[number];
DULA = 0;
number++;

P0 = 0xff;   //In order to prevent the previous segment selection signal from affecting the following bit selection signal in a moment

WELA = 1;
P0 = table_WEI[position];
WELA = 0;
position++;
}
}
}

void init()
{
t = 0;
number = position = 0;

TH0 = (65536-1000)/256;
TL0 = (65536-1000)%256;

TMOD = 0x01;

EA = 1;
ET0 = 1;

TR0 = 1;
}

void timer0() interrupt 1
{
TH0 = (65536-1000)/256;
TL0 = (65536-1000)%256;
t++;
}

```

# 2, Display of any number with delay() function

However, did you notice that with the above code, if you want to display any given number, it seems to be a bit troublesome. Let's introduce a general method:

If a number is given (assuming that it is a two digit number), then we can directly separate each bit of it (such as a bit, a ten bit,,,) and then display the ten bit number in a while(1) big cycle, delay for a short period of time, and then display another bit, and then delay for a period of time. In such an infinite cycle, what we can see with our naked eyes is the two digits of "static".

Note: if you want to display three digits, the uchar type is no longer applicable, because the maximum value of the uchar is 256. You need to use int

## 2.1 code and experiment

```#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int

sbit WELA = P2^7;
sbit DULA = P2^6;

uchar t,temp,shi,ge;

uchar code table_DUAN[] = {0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};

void delay(uint);

void main()
{
temp = 45;
shi = temp/10;
ge = temp%10;

while(1)
{
DULA = 1;
P0 = table_DUAN[shi-1];
DULA = 0;

P0 = 0xff;

WELA = 1;
P0 = 0xfe;
WELA = 0;

delay(5);

DULA = 1;
P0 = table_DUAN[ge-1];
DULA = 0;

P0 = 0xff;

WELA = 1;
P0 = 0xfd;
WELA = 0;

delay(5);
}
}

void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=100;y>0;y--);
}

```

If you think it's not enough to simply display a number, let's take an interesting example: let's give a number and reduce the number every second. When we reduce it to 100, we will keep the number of digital tubes at 100

In this case, we can use delay() to display any number and timer timing for 1s to control decrement

```#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int

sbit WELA = P2^7;
sbit DULA = P2^6;

uchar t,bai,shi,ge;
uint temp;

uchar code table_DUAN[] = {0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};

void init();
void delay(uint);
void display(uint temp);

void main()
{
init();
temp = 145;
while(1)
{
if(t == 20)     //Every 1s, the number is decremented
{
t = 0;
temp--;
if(temp == 100)
{
TR0 = 0;   //When we reduce it to 100, we turn off the counter, and it will not decrease
}
}
display(temp);   //Ordinary dynamic display is similar to the second section, but we now encapsulate it in functions
}
}

void init()
{
WELA = 0;
DULA = 0;

t = 0;
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;

TMOD = 0x01;

EA = 1;
ET0 = 1;

TR0 = 1;
}

void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=100;y>0;y--);
}

void display(uint temp)
{
bai = temp/100;
shi = (temp-100*bai)/10;
ge = temp%10;

DULA = 1;
P0 = table_DUAN[bai];
DULA = 0;

P0 = 0xff;

WELA = 1;
P0 = 0xfe;
WELA = 0;

delay(1);

DULA = 1;
P0 = table_DUAN[shi];
DULA = 0;

P0 = 0xff;

WELA = 1;
P0 = 0xfd;
WELA = 0;

delay(1);

DULA = 1;
P0 = table_DUAN[ge];
DULA = 0;

P0 = 0xff;

WELA = 1;
P0 = 0xfb;
WELA = 0;

dealy(1);

void timer0() interrupt 1
{
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
t++;
}```

[Supplement 2]: now we want to realize the following functions: at the beginning of the nixie tube display 765410, use the timer T0 to control, decrease once every 1s, and at the same time, t0 controls the LED to control the flow light at the speed of 0.5s. When 765410 decreases to 765398, let the nixie tube keep the current value, and the running water lamp stops, and all flashes. When the flashing lasts for 3s, the nixie tube displays "HELLO"

I will upload the code of this topic to github later, and it will be a little longer if I continue to post it.

Well, this is the whole content of this blog! We have learned the dynamic operation of the nixie tube and deepened the use of the timer. We hope to help you!  127 original articles published, 370 praised, 30000 visitors+

Posted by MadDawgX on Fri, 13 Mar 2020 20:39:06 -0700