简介:
因为proteus没有16*16的点阵,本文将4块8*8LED点阵显示器组成1块16*16点阵显示器,并分别由1块74HC595驱动,通过独立按键控制显示屏静态/动态显示。
学习链接:
点阵显示屏:
51单片机教程:8*8 点阵显示字符、数字、简单汉字_8*8点阵-CSDN博客
74HC595 :
按键控制:
原理图:
代码:
#include <reg51.h>
#include<intrins.h>
typedef unsigned char u8; //0—255
typedef unsigned int u16; //0—65535
void send_data_H(u16 dat); // 发送行数据端数据函数
void send_data_L(u16 dat); // 发送列选通端数据函数
void display(u16 a); //每一次显示什么东西
void delay(u16 m); //延时函数
//数据端接口定义
sbit LSH = P2^0; //列数时钟
sbit LDS = P2^1; //输入
sbit LST = P2^2; //列寄存器
sbit HSH = P2^3; //行数时钟
sbit HDS = P2^4; //输入
sbit HST = P2^5; //行寄存器时钟
//独立按键
sbit key1 = P3^0;
sbit key2 = P3^1;
sbit key3 = P3^2;
unsigned int sel[17]={0x7fff,0xbfff,0xdfff,0xefff,0xf7ff,0xfbff,0xfdff,0xfeff,0xff7f,0xffbf,0xffdf,0xffef,0xfff7,0xfffb,0xfffd,0xfffe,0xffff,};
char code hanzi[] =
{
0x10,0x00,0x10,0x00,0x1F,0xFC,0x20,0x80,0x20,0x80,0x40,0x80,0x1F,0xF8,0x10,0x80,
0x10,0x80,0x10,0x80,0xFF,0xFE,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,/*"年",0*/
0x01,0x00,0x21,0x08,0x21,0x08,0x3F,0xF8,0x00,0x20,0x22,0x20,0x22,0x3E,0xFF,0x42,
0x22,0x94,0x22,0x10,0x3E,0x10,0x22,0x10,0x22,0x28,0x3E,0x28,0x22,0x44,0x00,0x82,/*"嵌",0*/
0x04,0x00,0x02,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x02,0x80,0x02,0x80,0x02,0x80,
0x04,0x40,0x04,0x40,0x08,0x20,0x08,0x20,0x10,0x10,0x20,0x10,0x40,0x08,0x80,0x06,/*"入",1*/
0x00,0x48,0x00,0x44,0x00,0x44,0x00,0x40,0xFF,0xFE,0x00,0x40,0x00,0x40,0x3E,0x40,
0x08,0x40,0x08,0x40,0x08,0x20,0x08,0x22,0x0F,0x12,0x78,0x0A,0x20,0x06,0x00,0x02,/*"式",2*/
0x22,0x08,0x11,0x08,0x11,0x10,0x00,0x20,0x7F,0xFE,0x40,0x02,0x80,0x04,0x1F,0xE0,
0x00,0x40,0x01,0x80,0xFF,0xFE,0x01,0x00,0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00,/*"学",3*/
0x00,0x00,0x7F,0xF8,0x00,0x08,0x00,0x08,0x08,0x08,0x04,0x08,0x02,0x08,0x02,0x08,
0x00,0x68,0x01,0x88,0x0E,0x08,0x70,0x08,0x20,0x08,0x00,0x08,0x00,0x50,0x00,0x20,/*"习",4*/
0x02,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00,0x10,0x10,0x10,0x08,0x20,0x24,
0x48,0x24,0x04,0x40,0x02,0x80,0x01,0x00,0x02,0x80,0x0C,0x40,0x30,0x30,0xC0,0x0E,/*"交",5*/
0x00,0x80,0x20,0x40,0x17,0xFE,0x10,0x80,0x81,0x10,0x42,0x08,0x47,0xFC,0x10,0x04,
0x10,0x00,0x22,0x48,0xE2,0x48,0x22,0x48,0x22,0x48,0x22,0x4A,0x24,0x4A,0x08,0x46,/*"流",6*/
};
void main()
{
u16 j=0,num=0,n=0;
while(1)
{
num=6;
while(num--)
{
if(key1==0)
{
if(key2==0)
{
delay(200); //消除抖动
if(key2==0) //再次判断按键是否按下
{
n=n+32; //指向下一个字
}
while(!key2); //检测按键是否松开
j=0;
}
display(n);
delay(10);
}
else
{
display(j);
delay(10);
}
}
j=j+2;
}
}
void send_data_L(u16 dat)
{
u8 i;
for(i=0;i<8;i++)
{
LSH = 0;
LDS = dat&0x80; //temp<<=1;
dat = dat<<1; //ds = CY;
LSH = 1;
}
LST = 0;
LST = 1;
}
void send_data_H(u16 dat)
{
u8 i;
for(i=0;i<16;i++)
{
HSH = 0;
HDS = dat&0x8000;
dat =dat<<1;
HSH = 1;
}
HST = 0;
HST = 1;
}
void delay(u16 m)
{
u16 i;
for(;m>0;m--)
{
for(i=0;i<124;i++)
{}
}
}
void display( u16 a)
{
u8 i;
u16 x;
for(i=0;i<16;i++)
{
send_data_H(sel[i]);
x=a+2*i;//展示第几个字符
if(a+2*i>256)
{
x=(a+2*i)%256;
}
send_data_L(hanzi[x]);
send_data_L(hanzi[x+1]);
delay(1);
}
}
Proteus仿真:
KEY1控制显示屏的显示方式(静态/动态)
KEY2切换显示内容
暂时还没搞懂平台如何放置视频内容,读者可到主页下载工程文件,自行阅读。
点阵显示