STC89C52RC---坤坤铁山靠
一、成果展示
二、实现代码
- MatrixLED.h
#ifndef __MatrixLED__H__
#define __MatrixLED__H__
void MatrixLED_ShowColumn(unsigned char Column,Data);
void MatrixLED_Init();#endif
- MatrixLED.c
#include "MatrixLED.h"
#include <STC89C5xRC.H>
#include "Delay.h"sbit RCK=P3^5; //RCLK
sbit SCK=P3^6; //SRCLK
sbit SER=P3^4; //SER#define MATRIX_LED_PORT P0void _74HC595_WriteByte(unsigned char Byte)
{unsigned char i;//首先先放入到移位寄存器中for(i=0;i<8;i++){SER=Byte&(0x80>>i);SCK=1;SCK=0;}//然后再将数据输出RCK=1;RCK=0;}
/**@brief 点阵屏初始化*@param 无*@retval 无
*/
void MatrixLED_Init()
{SCK=0;RCK=0;
}
/*
*@brief LED点阵屏显示一列数据
*@param Column要选择列,范围:0~7 ,0为最左边
*@param Data 选择列显示的数据,高位在上,1为亮,0为灭
*@retval 无
*/
void MatrixLED_ShowColumn(unsigned char Column,Data)
{_74HC595_WriteByte(Data);MATRIX_LED_PORT=~(0x80>>Column); //相当于位选Delay(1);MATRIX_LED_PORT=0xFF;}
- Delay.h
//
// Created by Editor_Hu on 2025/10/14.
//
#ifndef __DELAY_H__
#define __DELAY_H__void Delay(unsigned char time);void LCD_Delay(unsigned int time);#endif //__DELAY_H__
- Delay.c
#include "Delay.h"
/*** @brief 延时函数,STC89C52RC + 12MHz 晶振下,延时约 time 毫秒* @param time 延时时间(单位:ms),范围 0~65535* @retval 无*/
void Delay(unsigned int time)
{unsigned int i, j;for(i = 0; i < time; i++){// 内层循环 ≈ 1ms(12MHz,12T 模式)for(j = 0; j < 114; j++); // 实测经验值,接近 1ms}
}
- main.c
#include <STC90C5xAD.H>
#include "Delay.h"
#include "MatrixLED.h"unsigned char code IKUN[]={
0x00,0x00,0x19,0x3E,0x7C,0x54,0x03,0x00,
0x00,0x00,0x01,0x02,0x1C,0x1C,0x7B,0x58,
0x00,0x00,0x19,0x3E,0x7C,0x54,0x03,0x00,
0x00,0x00,0x23,0x7C,0xF8,0xB6,0x01,0x00,
0x00,0x00,0x01,0x02,0x24,0x78,0xFF,0xB0,
0x00,0x00,0x23,0x7C,0xF8,0xB6,0x01,0x00
};void main()
{unsigned char i,offset=0,Count=0;MatrixLED_Init();while(1){for(i=0;i<8;i++){MatrixLED_ShowColumn(i,IKUN[i+offset]);}Count++;if(Count>20){Count=0;offset+=8;if(offset>40){offset=0;}}}
}