Based on the STC series microcontroller, the timer 0 scans the digital tube to display the timer/counter 1 as the counter 1 frequency generation function.

#define uchar unsigned char//Customized unsigned character type is uchar
#define uint unsigned int//Customized unsigned integer type is uint
#define NixieTubeSegmentCode P0//Customized digital tube segment code is the P0 group pin of the microcontroller
#define NixieTubeBitCode P2//Customized digital tube bit code is the P2 group pin of the microcontroller
sbit LED P1^0;//The bit defines the LED light as the P1.0 pin of the microcontroller
uchar Code NixieTubeBitCodeArray = [0xfe,0xfd,0xfb,0xf7];//Define the digital tube bit code array variable
uchar NixieTubeDisplayDataArray[0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40,0x00];//Define the digital tube to display 0~F data and the symbol "-" and extinguish the array variable
uchar NixieTubeCacheDataArray[] = [16,16,16,16];//Define the nixie tube cache data array variable
//uchar NixieTubeBootTimerFlag = 1;//Define the digital tube boot time flag variable
uint KeyPressNumber;//Declare the key press numerical variable
//uint NixieTubeBootTimer = 0;//Define the digital tube boot time variable
uint Timer0TimeCount;//Declare timer 0 timing count variable
//void NixieTubeBootDisplay();//Nixie tube boot display function
void NixieTubeDisplayDataSplit();//Nixie tube display data decomposition function
void NixieTubeDisplayData();//Nixie tube display data function
void Timer0Init(void);//Timer 0 initialization function
void Timer1Init(void);//Timer 1 initialization function
  void main(void)//main function
{<!-- -->
   Timer0Init();//Timer 0 initialization function
   Timer1Init();//Timer 1 initialization function
   //NixieTubeBootDisplay();//Nixie Tube boot display function
   while(1)//main loop
  {<!-- -->
    NixieTubeDisplayDataSplit();//Nixie tube display data decomposition function
   }
  }
  /*****void NixieTubeBootDisplay();//Nixie tube boot display function
 {
   do
  {
    if(NixieTubeBootTimer = 1000)//If the digital tube boot time is equal to 1s
    LED = ~ LED;//Update when the LED light turns on and off
   }while(NixieTubeBootTimer < 5000);//When the nixie tube is powered on for less than 5s
   NixieTubeBootTimerFlag = 0;//The digital tube boot time flag is cleared to 0
   LED = 1; //LED light goes off
  }*****/
  void NixieTubeDisplayDataSplit()//Nixie tube display data decomposition function
 {<!-- -->
   NixieTubeCacheDataArray[0] = KeyPressNumber / 1000;//Nixie tube thousand digit data display
   NixieTubeCacheDataArray[1] = KeyPressNumber / 100 % 10;//Nigital tube hundred digit data display
   NixieTubeCacheDataArray[2] = KeyPressNumber / 10 % 10;//Nigital tube ten-digit data display
   NixieTubeCacheDataArray[3] = KeyPressNumber % 10;//Nigital tube single digit data display
  }
  void NixieTubeDisplayData()//Nixie tube display data function
 {<!-- -->
   static uchar i = 0;//Define the static digital tube bit change variable
   switch(i)//Filtering of digital tube position changes
  {<!-- -->
    case 0 ://Nigital tube thousand digit display
            NixieTubeSegmentCode = 0x00; //Nixie Tube segment code disappears
            NixieTubeSegmentCode = NixieTubeDisplayDataArray[NixieTubeCacheDataArray[0]];//Segment code display of thousands of digital tubes
            NixieTubeBitCode = NixieTubeBitCodeArray[0];//Nigital tube thousand digit code display
            i + + ;//The digital tube bit changes and increases by 1
            break;//jump out
    case 1 ://Nigital tube hundreds digit display
            NixieTubeSegmentCode = 0x00; //Nixie Tube segment code disappears
            NixieTubeSegmentCode = NixieTubeDisplayDataArray[NixieTubeCacheDataArray[1]];//The segment code display of the hundreds digit of the digital tube
            NixieTubeBitCode = NixieTubeBitCodeArray[1];//Hundred-digit code display on the digital tube
            i + + ;//The digital tube bit changes and increases by 1
            break;//jump out
    case 2 ://Nigital tube tens digit display
            NixieTubeSegmentCode = 0x00; //Nixie Tube segment code disappears
            NixieTubeSegmentCode = NixieTubeDisplayDataArray[NixieTubeCacheDataArray[2]];//The ten-digit segment code display of the digital tube
            NixieTubeBitCode = NixieTubeBitCodeArray[2];//Nigital tube ten-digit code display
            i + + ;//The digital tube bit changes and increases by 1
            break;//jump out
    case 3 ://digital tube ones digit display
            NixieTubeSegmentCode = 0x00; //Nixie Tube segment code disappears
            NixieTubeSegmentCode = NixieTubeDisplayDataArray[NixieTubeCacheDataArray[3]];//The segment code display of the digital tube's units digit
            NixieTubeBitCode = NixieTubeBitCodeArray[3];//Nixie tube unit code display
            i = 0;//Clear 0 when digital tube bit changes
            break;//jump out
    default:break;//jump out
   }
  }
  /*****Knowledge points about setting the timer/counter mode to 1T or 12T mode through the special function register AUXR without requiring frequency division or needing 12 frequency division to calculate the initial value of the timer (initial value of timing count) of the 8051 series microcontroller *****/
  /****
  Clock cycle (also called oscillation cycle): the reciprocal of the crystal oscillator frequency of the microcontroller. For example: the crystal oscillator frequency of the microcontroller is 12MHz, then the clock cycle = [1/(12*10^6)Hz]s=0.000000083s=0.000083ms=0.083us
  Machine cycle: The time required for the microcontroller to complete a basic operation (such as basic operations such as instruction fetching, decoding, and execution) when executing an instruction. A machine cycle of the 8051 series microcontroller is composed of 6 S cycles (status cycles). The clock cycle is defined as one beat (represented by P) and two beats are defined as one state cycle (represented by S). Then the machine cycle of the 8051 microcontroller consists of 6 state cycles, that is to say, one machine cycle = 6 state cycles = 12 Clock period=[12x[1/(12*10^6)Hz]s]s=0.000001s=0.001ms=1us
  Instruction cycle: the time it takes for a microcontroller to fetch an instruction and execute it.
  The relationship between the above three: instruction cycle > machine cycle > clock cycle
  1. The following is a calculation formula for the 8051 microcontroller timer to calculate the initial value of the timer by dividing it by 12 (the crystal oscillator frequency of the microcontroller is 12MHz, the working mode of timer 0 is 16-bit timing mode 1, and a timing of 1ms is required to calculate):
   0. The formula for calculating the machine cycle T of nT microcontroller: T=n*(1/crystal oscillator frequency)=how many us
   1. One machine cycle = 12 clock cycles = 12 times the reciprocal of the crystal oscillator frequency of the microcontroller = 12*[1/(12*10^6)Hz]s=0.000001s=0.001ms=1us
   2. Timing time = Timing count * one machine cycle 1ms = Timing count * 1us Timing count = 1ms/1us = 1000us/1us = 1000 times
   3. The initial value of the timer (initial value of the timer count) = 2^n - How many timers are there in the timer count n? Here n = 16, then the initial value of the timer (initial value of the timer count) = 2^16-1000 = 65536- 1000=64536 Convert 64536 into hexadecimal and split it into high eight bits and low eight bits. Put the high eight bits into TH0=0xfc or (65536-64536)/256 and put the low eight bits into TL0=0x18 or (65536-64536)%. 6
  2. The following is another calculation formula for calculating the initial value of the timer for the 8051 microcontroller timer using 12 frequency division or no frequency division (calculation is based on the crystal oscillator frequency of the microcontroller being 12MHz and the working mode of timer 0 being 16-bit timing mode 1, which requires timing of 1ms) :
   1. Comprehensive formula: initial value of timer (initial value of timing count) = 2^n-(crystal oscillator frequency/number of divisions/timing frequency) n is the number of timers. This formula is often used in pulse width modulation operations. For example: using 8051 The 16-bit timing mode 1 of timer 0 with a crystal oscillator frequency of 12MHz in the series of microcontrollers is used to generate a 1KHz square wave pulse. It can be seen from this: timing time = 1/timing frequency = 1/1000Hz = 0.001s = 1ms = 1000us, and then we can get: timer Initial value (initial value of timing count)=2^n-(crystal oscillator frequency/frequency/timing frequency)=2^16-(12MHz/12/1KHz)=2^16-(12*10^6)Hz/ 12/1000Hz)=65536-1000=64536 Convert 64536 into hexadecimal and split it into high eight bits and low eight bits. Put the high eight bits into TH0=0xfc or (65536-64536)/256 or Value >> 8 low eight bits. Bit put TL0=0x18 or (65536-64536)%6 or =Value
   2. TH0 = Value >> 8; TL0 = Value; The two codes are explained as follows:
  (1), TH0 = Value >> 8 is equivalent to TH0 = (65536-10000)/256=55536/256=216.9375 Analysis: 65536-10000=55536 is converted into binary to 11011000 11110000 55536/256=216.9375 is converted into binary to 1101 1000 It can be seen from this that the binary number 11011000 with Value of (65536-10000) = 55536 11110000 can be obtained by shifting 8 bits to the right to obtain the binary number 11011000 with 55536/256 = 216.9375
  (2), TL0 = Value is equivalent to TL0 = (65536-Another calculation formula for the initial value of the timer (calculation is based on the crystal oscillator frequency of the microcontroller being 12MHz, the working mode of timer 0 being 16-bit timing mode 1, and a timing of 1ms required):
 (1) The following is the 8051 microcontroller timer's initial value calculated by dividing it by 12:
     The initial value of the timer (initial value of the timing count) = 2^n-(crystal oscillator frequency/number of divisions/timing frequency) n is the number of timers. This formula is often used in pulse width modulation operations. For example: using the 8051 series microcontroller, the crystal oscillator frequency is The 16-bit timing mode 1 of 12MHz timer 0 is used to generate a 1KHz square wave pulse (equivalent to timing 1ms). It can be seen that: timing time = 1 / timing frequency = 1/1000Hz = 0.001s = 1ms = 1000us, and then we can get: timing Initial value of the device (initial value of timing count)=2^n-(crystal oscillator frequency/frequency/timing frequency)=2^16-(12MHz/12/1KHz)=2^16-(12*10^6)Hz /12/1000Hz)=65536-1000=64536 Convert 64536 into hexadecimal and split it into high eight bits and low eight bits. Put the high eight bits into TH0=0xfc or (65536-64536)/256 or Value >> 8 low Put eight bits in TL0=0x18 or (65536-64536)%6 or =Value
 (2) The following is the initial value of the 8051 microcontroller timer without frequency division:
     The initial value of the timer (initial value of the timing count) = 2^n-(crystal oscillator frequency/number of divisions/timing frequency) n is the number of timers. This formula is often used in pulse width modulation operations. For example: using the 8051 series microcontroller, the crystal oscillator frequency is The 16-bit timing mode 1 of 12MHz timer 0 is used to generate a 1KHz square wave pulse (equivalent to timing 1ms). It can be seen that: timing time = 1 / timing frequency = 1/1000Hz = 0.001s = 1ms = 1000us, and then we can get: timing Initial value of the device (initial value of timing count)=2^n-(crystal oscillator frequency/frequency/timing frequency)=2^16-(12MHz/1/1KHz)=2^16-(12*10^6)Hz /1/1000Hz)=65536-12000=53536 Convert 53536 into hexadecimal and split it into high eight bits and low eight bits. Put the high eight bits into TH0=0xd1 or (65536-53536)/256 or Value >> 8 low Put eight bits in TL0=0x20 or (65536-53536)%6 or =Value
 (3), TH0 = Value >> 8; TL0 = Value; the two codes are explained as follows:
     1. TH0 = Value >> 8 is equivalent to TH0 = (65536-10000)/256=55536/256=216.9375 Analysis: 65536-10000=55536 is converted into binary to 11011000 11110000 55536/256=216.9375 is converted into binary to 11011 000 from this It can be seen that the binary number 11011000 with Value of (65536-10000) = 55536 11110000 can be obtained by shifting 8 bits to the right to get the binary number 11011000 with 55536/256 = 216.9375
     2. TL0 = Value is equivalent to TL0 = (65536-10000)%6=55536%6=240 Analysis: 65536-10000=55536 is converted into binary to 11011000 11110000 55536%6=240 is converted into binary to 11110000 It can be seen from this The binary number 11011000 with value (65536-10000)=55536. Take the lower 8 bits of 11110000 to get the binary number 11110000 with 55536%6=240.
 (4) The steps to derive the timer timing time from the initial value of the timer (initial value of the timing count) are as follows:
     1. If the initial value of the timer (initial value of the timer count) is split into the high eight bits and the low eight bits, such as: TH0=0xfc TL0=0x18, first assign the high eight bits and the low eight bits to form a sixteen bit value. Data 0xfc18 is converted into decimal data 64536. Use 2^n-64536 to calculate the number of pulses generated per second, where n is the number of timers, and then calculate the timing time according to the formula. For example: From the formula: number of pulses generated per second = crystal oscillator frequency/minutes Frequency/timing frequency is converted into: Number of pulses generated per second = Crystal oscillator frequency =1/timing frequency=1/[(number of pulses generated per second x frequency divided by frequency)/crystal oscillator frequency] converted into: crystal frequency/(number of pulses generated per second x frequency divided by frequency) = timing time
     2. If the initial value of the timer (initial value of the timer count) is decimal data such as: 64536, directly use 2^n-64536 to calculate the number of pulses generated per second, where n is the number of timers, and then calculate the timing time according to the formula, such as: Formula: The number of pulses generated per second = crystal oscillator frequency / frequency divided by / timing frequency is converted into: number of pulses generated per second = crystal oscillator frequency x timing frequency / frequency divided by frequency can be found: timing frequency = (number of pulses generated per second x frequency divided by)/crystal oscillator frequency and then find out: timing time = 1/timing frequency = 1/[(number of pulses generated per second Number of pulses x divided frequency) = timing time
  ****/
  void Timer0Init(void)//The 16-bit timing mode 1 of timer 0 uses a divide-by-12 timing 1ms initialization function. The crystal oscillator is 12MHz.
 {<!-- -->
   AUXR & amp;= 0x7f;//Set the timer/counter mode to 12T
   TMOD & amp;= 0xf0;//Set timer/counter operating mode and clear to 0
   TMOD |= 0x01;//Set the timer/counter as a timer and the working mode is 16-bit timer 0 mode 1
   TH0 = 0xfc;//Set the high 8-bit initial value of timer 0
   TL0 = 0x18; //Set the low 8-bit initial value of timer 0
   TF0 = 0; //Timer 0 overflow interrupt flag bit cleared to 0
   ET0 = 1;//Turn on the timer interrupt switch
   EA = 1;//Turn on the timer interrupt master switch
   TR0 = 1//Turn on the timer 0 switch
  }
  void Timer1Init()//Timer 1 count initialization function The crystal oscillator is 12MHz
 {<!-- -->
   TMOD & amp;= 0x0f;//Set timer/counter operating mode and clear to 0
   TMOD |= 0x50;//Set the timer/counter as a counter and the working mode is 16-bit counter 1 mode 1
   TH1 = 0;//Set the high 8-bit initial value of timer 1 count
   TL1 = 0; //Set the low 8-bit initial value of timer 1 count
   TF1 = 0; //Timer 1 overflow interrupt flag bit cleared to 0
   ET1 = 1;//Turn on the timer 1 interrupt switch
   EA = 1;//Turn on the timer interrupt master switch
   TR1 = 1//Turn on timer 1 switch
  }
  void Timer0() interrupt 1//The 16-bit timing mode 1 of timer 0 uses a frequency divider of 12 to time a 1ms interrupt function. The crystal oscillator is 12MHz.
 {<!-- -->
   TR0 = 0;//Turn off timer 0 switch
   Timer0TimeCount + + ;//Timer 0 timing count increases automatically
   if(Timer0TimeCount >= 1000)//1s time is up
  {<!-- -->
    TR1 = 0;//Turn off timer 1 switch
    Timer0TimeCount = 0;//Timer 0 timing count is cleared to 0
    KeyPressNumber = TH1 * 256 + TL1; //Assign the total number of pulses generated by the microcontroller timer 1 pin P3.5 to the key press value variable
    TH1 = 0; // Clear the high 8 bits of timer 1 count to 0
    TL1 = 0; // Clear the low 8 bits of timer 1 count to 0
    TR1 = 1;//Turn on timer 1 switch
   }
   /*****if(NixieTubeBootTimerFlag == 1)//Nixie tube boot time mark position 1
  {
    NixieTubeBootTimer + + ;//Nixie tube boot time increases automatically
   }*****/
   NixieTubeDisplayData();//Nixie tube display data function
   TH0 = 0xfc;//Set the high 8-bit initial value of timer 0
   TL0 = 0x18; //Set the low 8-bit initial value of timer 0
   TR0 = 1; //Turn on timer 0 switch
  }