Dynamic display of serial 4-digit digital display module connected to Arduino

    We have done a dynamic display experiment in which an Arduino development board is connected to a 4-digit digital tube before. After using the clock interrupt method, our digital display can be well satisfied. The price of the 4-digit digital tube is very low, and the display effect is also good, but there is a big weakness for connecting to the Arduino, that is, it needs to occupy 12 IO digital ports of the Arduino development board, and the most commonly used arduino UNO development board has a total of only 12 IO ports. There are 14 IO digital ports from D0 to D13.

    In order to reduce the digital port occupation of Arduino, we chose a serial 4-digit digital display module this time. This display module only needs 5 wires to connect with Arduino, 3 of which are data wires and 2 are power wires, so actually only 3 digital ports are occupied.

    The serial 4-digit digital display module controls the 4-digit digital tube through two 74HC595 chips. We don’t need to pay too much attention to the internal working principle of the chip. We only need to connect the display module to the digital port of Arduino correctly, and then display the numbers to It can be on the designated digital tube.

    The display module has 5 pins, namely: VCC, SCLK, RCLK, DIO, GND, where VCC is connected to 5V power supply, GND is grounded, SCLK is used to receive synchronous clock, RCLK is used to control data output, and DIO is used to receive Input of serial data. However, we only need to understand SCLK as receiving the segment code of the 7-segment digital tube, and RCLK as receiving the number or bit code of the digital tube (that is, the number of the digital tube). As shown below:

    The serial 4-digit digital display module is the same as the previous display principle of directly connecting 4-digit digital tubes, and it also adopts the method of "dynamic scanning display" to display, that is, the first digital tube, the second digital tube, and the third digital tube are displayed in sequence. Nixie tube, the 4th nixie tube, this method is to use the visual residue of the human eye, when the scanning display frequency is greater than 25 frames per second, what we see is that each nixie tube is displayed at the same time. Also in order to solve the display processing in the main loop, which may cause abnormal display, we still use the clock interrupt of Arduino to perform "dynamic scanning display", and the clock interrupt interval is set at 5ms.

    This experiment uses the Arduino UNO development board, and the SCLK, RCLK, and DIO pins of the display module are connected to the D2, D3, and D4 of the Arduino in turn.

    The program accumulates the static variable num at intervals of 0.1 seconds in the main loop, and then displays the value of num on the serial 4-digit digital display module. The full program (which was tested) is as follows:

#define SCLK 2 //Serial clock pin definition

#define RCLK 3 //Receive clock pin definition

#define DIO 4 //Data pin definition

#include<MsTimer2.h> //call the library file of timer T2

/*

  Using the clock interrupt method, the serial 4-digit digital module dynamically displays the 0-9999 program

  Advantage: the delay function can be used arbitrarily in the main loop

*/

int segCount=4;//4 digital tube

//Define the segment code, here is the common Yang segment code, you can use the digital tube segment code software to change the array value or display any shape

const unsigned char dofly_DuanMa[]={// 0   1    2    3  4  5    6    7  8    9    A    b  C    d    E    F    -

  0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x98,0x8C,0xBF,0xC6,0xA1,0x86,0x8E,0xbf};

// bitcode

int segPins[] = {

  0x08,0x04,0x02,0x01}; //The number corresponding to the digital tube is the bit code, from left to right is the first digital tube, the second digital tube, the third digital tube, and the fourth digital tube  

unsigned char displayTemp[4];//display buffer, store the 4-bit segment code to be displayed

void setup() {

// Set the corresponding ports as output

  pinMode(SCLK,OUTPUT);

  pinMode(RCLK,OUTPUT);

  pinMode(DIO,OUTPUT);

  MsTimer2::set(5, Timedisp); //Define Timedisp as a subroutine called by the clock interrupt, and trigger the clock interrupt every 5ms to enter the Timedisp function

  MsTimer2::start(); //The clock interrupt starts

}

// Data processing, write the byte data (segment code) to be processed to the corresponding port SCLK.

void deal(unsigned char value){

  for(int i=7;i>=0;i--){

    digitalWrite(DIO,bitRead(value,i));//use the bitWrite function, very simple

    // !bitRead(value,i), add in front here! (non-operating symbol), depending on whether the common cathode or common anode digital tube is used.

    digitalWrite(SCLK,LOW);

    digitalWrite(SCLK,HIGH);

  }

}

// The display program called by the clock interrupt

//Every interrupt, display one of displayTemp[0]—displayTemp[3] (that is, the static variable i) segment code value once

void Timedisp() {

  static int i;

  deal(displayTemp[i]);//Write the corresponding segment code value to the corresponding digital tube

  deal(segPins[i]);//Write the segment code value of the corresponding digital tube number (bit code) to the DIO port

  digitalWrite(RCLK,LOW);//reset RCLK

  digitalWrite(RCLK,HIGH);//Trigger RCLK, that is, select the corresponding digital tube with code number i

  i++;

  if(i==segCount) //Recycle after 4 digits

    i=0;

}

//Display program, display num in 4 digits, num is less than 10000

void disp(unsigned long num) {

  num=num%10000;//modulo operation to prevent num from exceeding 9999

  displayTemp[0]=dofly_DuanMa[num/1000]; //Send the one-digit segment code value of num to display buffer displayTemp[0]

  displayTemp[1]=dofly_DuanMa[(num%1000)/100]; //Send the ten-digit segment code value of num to display buffer displayTemp[1]

  displayTemp[2]=dofly_DuanMa[((num%1000)%100)/10]; //Send the hundreds digit segment code value of num to display buffer displayTemp[2]

  displayTemp[3]=dofly_DuanMa[((num%1000)%100)%10]; //Send the thousands-digit segment code value of num to display buffer displayTemp[3]

}

// main loop

void loop() {

    static unsigned int num;//Define a data

    disp(num);//Display the accumulated value num

    num++;

    delay(100); //Delay 100ms

}

Guess you like

Origin blog.csdn.net/m0_61543203/article/details/126144689