Practical analysis of 8051 microcontroller (taking STC89C52RC as an example) | 09 - LED dot matrix display of numbers

Publisher:温馨阳光Latest update time:2022-05-12 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 LED dot matrix

LED dot matrix is ​​a display device composed of light-emitting diodes. It can be seen everywhere in our daily electrical appliances and is widely used in bus station announcers, advertising screens, etc. The 8*8 dot matrix is ​​usually used more often, and then multiple 8*8 dot matrices can be used to form LED dot matrix display screens with different resolutions. For example, 16*16 dot matrix can be composed of 4 8*8 dot matrices. Therefore, if you understand the working principle of 8*8LED dot matrix, other resolution LED dot matrix display screens are the same. Here we will introduce 8*8LED dot matrix.

working principle:

The 8*8 dot matrix is ​​composed of 64 light-emitting diodes, and each light-emitting diode is placed at the intersection of the row and column lines. When the corresponding row is set to 1 level (the row is connected to the anode of the diode, so it is a high level) and the column is set to 0 level (the column is connected to the cathode of the diode, so it is a low level), the corresponding diode will light up; if you want to light up the first diode, connect the A1 pin to a high level and the K1 pin to a low level, then the first point will light up; if you want to light up the first row, connect the A1 pin to a high level, and (K1, K2, K3, K4, K5, K6, K7, K8) these pins to a low level, then the first row will light up; if you want to light up the first column, connect the K1 pin to a low level, and (K1, K2, K3, K4, K5, K6, K7, K8) to a high level, then the first column will light up.


Next, we will understand its use in depth by displaying a dot and a number on the LED dot matrix.


2 Schematic diagram

① 8*8 LED dot matrix schematic diagram:

74HC595 schematic diagram (connect OE to GND at the JOE pin header):

③ MCU schematic diagram:

3 Procedure

① Light up the first point in the upper left corner:


#include "reg51.h" //This file defines some special function registers of the microcontroller

#include


typedef unsigned int u16;   //declare and define the data type

typedef unsigned char u8;


sbit SRCLK=P3^6; //Storage register clock pin (data input clock line)

sbit RCLK=P3^5; //Shift register clock pin (output memory latch clock line)

sbit SER=P3^4; //Serial data input pin



/***********************************************************************************

* Function name: Hc595SendByte(u8 dat)

* Function : Send one byte of data to 74HC595

* Input : None

* Output          : None

***********************************************************************************/

void Hc595SendByte(u8 dat)

{

u8 i;

SRCLK=0; // Initialize the data input clock line

RCLK=0; // Initialize the output memory latch clock line

for(i=0;i<8;i++)

{

SER=dat>>7; //Send from the highest bit Example: 1111 0000, the highest bit is 1, shift right 7 bits, and finally become 1, so the highest bit is saved

dat<<=1; // Shift left to become the second highest bit, continue with the previous example, shift left to become the second highest bit, shift right 7 bits to become the second highest bit


SRCLK=1; // From 0 to 1, that is, from low level to high level, the shift register rises, and the data is stored in the shift register

_nop_();

_nop_();

SRCLK=0; // Reset pin

}


RCLK=1; // shift register clock pin plus rising edge, data parallel output

_nop_();

_nop_();

RCLK=0; // Reset pin

}


/***********************************************************************************

* Function name: main

* Function : Main function

* Input: None

* Output    : None

***********************************************************************************/

void main()

{

Hc595SendByte(0x80); // Write 0b10000000 to make the D7 pin output high level

P0=0x7f; // Write 0b01111111 to make the P07 pin output low level

while(1);

}


② Display the number 0 on the dot matrix:


#include "reg51.h" //This file defines some special function registers of the microcontroller

#include


typedef unsigned int u16;   //declare and define the data type

typedef unsigned char u8;


sbit SRCLK=P3^6; //Storage register clock pin (data input clock line)

sbit RCLK=P3^5; //Shift register clock pin (output memory latch clock line)

sbit SER=P3^4; //Serial data input pin


// Define the display position of number 0

u8 LedSeg[]={0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00};

u8 LedPos[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};

/***********************************************************************************

* Function name: delay

* Function    : Delay function, when i=1, the delay is about 10us

***********************************************************************************/

void delay(u16 i)

{

while(i--);

}


/***********************************************************************************

* Function name: Hc595SendByte(u8 dat)

* Function : Send one byte of data to 74HC595

* Input : None

* Output          : None

***********************************************************************************/

void Hc595SendByte(u8 dat)

{

u8 i;

SRCLK=0; // Initialize the data input clock line

RCLK=0; // Initialize the output memory latch clock line

for(i=0;i<8;i++)

{

SER=dat>>7; //Send from the highest bit Example: 1111 0000, the highest bit is 1, shift right 7 bits, and finally become 1, so the highest bit is saved

dat<<=1; // Shift left to become the second highest bit, continue with the previous example, shift left to become the second highest bit, shift right 7 bits to become the second highest bit


SRCLK=1; // From 0 to 1, that is, from low level to high level, the shift register rises, and the data is stored in the shift register

_nop_();

_nop_();

SRCLK=0; // Reset pin

}


RCLK=1; // shift register clock pin plus rising edge, data parallel output

_nop_();

_nop_();

RCLK=0; // Reset pin

}


/***********************************************************************************

* Function name: main

* Function : Main function

* Input: None

* Output    : None

***********************************************************************************/

void main()

{

u8 i;

while(1)

{

P0=0x7f; // Initialize port P0

for(i=0;i<8;i++) //8 rows and 8 columns, bit selection is performed while scanning rows, so there are 8 loops in total

{

P0=LedPos[i];   //Send bit selection data to control P0 port

Hc595SendByte(LedSeg[i]); //Send segment selection data to control 74HC595

delay(100);    //delay, the speed cannot be observed by naked eyes

Hc595SendByte(0x00); //Blank to prevent affecting the next scan

}

}

}

Reference address:Practical analysis of 8051 microcontroller (taking STC89C52RC as an example) | 09 - LED dot matrix display of numbers

Previous article:STC89C52RC MCU Extra Chapter | 01 - Understanding interrupts, interrupt sources and interrupt priorities
Next article:Practical Analysis of 8051 MCU (Taking STC89C52RC as an Example) | 08 - Matrix Key Driver

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号