生成一个STC12C2052AD的8*8矩阵图的代码,使其显示1
时间: 2023-04-06 08:03:12 浏览: 115
我可以回答这个问题。以下是一个示例代码:
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit LATCH = P1^0; //锁存信号
sbit SCLK = P1^1; //时钟信号
sbit SDI = P1^2; //串行数据信号
uchar code LED_Matrix[10][8] = { //数字0-9的点阵数据
{0x3C, 0x42, 0x81, 0x81, 0x81, 0x81, 0x42, 0x3C},
{0x00, 0x21, 0x7F, 0x01, 0x01, 0x01, 0x01, 0x00},
{0x21, 0x43, 0x45, 0x49, 0x51, 0x61, 0x41, 0x00},
{0x22, 0x41, 0x49, 0x49, 0x49, 0x49, 0x36, 0x00},
{0x0C, 0x14, 0x24, 0x44, 0x7F, 0x04, 0x04, 0x00},
{0x72, 0x51, 0x51, 0x51, 0x51, 0x51, 0x4E, 0x00},
{0x3C, 0x42, 0x81, 0x81, 0x89, 0x89, 0x72, 0x00},
{0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x7F, 0x00},
{0x36, 0x49, 0x49, 0x49, 0x49, 0x49, 0x36, 0x00},
{0x06, 0x09, 0x09, 0x09, 0x09, 0x09, 0x7F, 0x00}
};
void delay(uint xms) //延时函数
{
uint i, j;
for(i = xms; i > 0; i--)
for(j = 110; j > 0; j--);
}
void Write_Byte(uchar dat) //写入一个字节的数据
{
uchar i;
for(i = 0; i < 8; i++)
{
SCLK = 0;
SDI = dat & 0x80;
dat <<= 1;
SCLK = 1;
}
}
void Write_Row(uchar row, uchar dat) //写入一行数据
{
LATCH = 0;
Write_Byte(1 << row);
Write_Byte(dat);
LATCH = 1;
}
void Display_Matrix(uchar matrix[8]) //显示一个矩阵
{
uchar i;
for(i = 0; i < 8; i++)
Write_Row(i, matrix[i]);
}
void main()
{
uchar i;
while(1)
{
for(i = 0; i < 8; i++)
Display_Matrix(LED_Matrix[1][i]); //显示数字1的点阵数据
delay(1000); //延时1秒
}
}
阅读全文