51 microcontroller learning: LED dot matrix experiment (light up a point)

Publisher:达文西happyLatest update time:2023-02-06 Source: zhihu Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Experiment name: LED dot matrix experiment (light up one point)
Wiring instructions:
Experimental phenomenon: After downloading the program, the 8*8 LED dot matrix lights up the first point in the upper left corner.
Note: The J24 yellow jumper cap next to the LED dot matrix is ​​short. Connect to the GND end
************************************************ *****************************************/
#include "reg51.h"

typedef unsigned int u16; //Redefine the system default data type
typedef unsigned char u8;

//Define 74HC595 control pin
sbit SRCLK=P3^6; //Shift register clock input
sbit RCLK=P3^5; //Storage register clock input
sbit SER=P3^4; //Serial data input

#define LEDDZ_COL_PORT P0 //Point array control port


/****************************************************** ****************************
* Function name: delay_10us
* Function function: Delay function, when ten_us=1, the delay is approximately 10us
* Input: ten_us
* Output: None
**************************************** ***************************************/
void delay_10us(u16 ten_us)
{
while(ten_us --);
}

/****************************************************** ******************************
* Function name: hc595_write_data(u8 dat)
* Function function: Write one byte to 74HC595 data
* input: dat:data
* output: none
****************************************** *****************************************/
void hc595_write_data(u8 dat)
{
u8 i=0;

for(i=0;i<8;i++)//Loop 8 times to write a byte into the register
{ SER=dat>>7;//Transmit the high-order dat
of a byte first
<<=1;//Move the low bit to the high bit
SRCLK=0;
delay_10us(1);
SRCLK=1;
delay_10us(1);//The rising edge of the shift register clock sends the port data into the register
}
RCLK=0;
delay_10us(1);
RCLK=1;//The rising edge of the storage register clock will output the data previously written to the register
}


/****************************************************** ******************************
* Function name: main
* Function function: main function
* Input: None
* Output: None
* *************************************************** ****************************/
void main()
{
u8 i=0;

LEDDZ_COL_PORT=0x7f;//Set the first column on the left side of the LED dot matrix to 0, that is, the LED cathode is low level, and the remaining columns are 1, that is, high level
while(1)
{
hc595_write_data(0x80);//Set the LED dot The first row on the array is set to 1, that is, the LED anode is high level, and the remaining rows are 0, that is, low level
}
}



Reference address:51 microcontroller learning: LED dot matrix experiment (light up a point)

Previous article:51 microcontroller learning: LED dot matrix experiment (display numbers)
Next article:51 microcontroller learning: IO expansion (serial to parallel) experiment-74HC595

Latest Microcontroller Articles
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号