实验6.LED点阵显示汉字
//该板子上的点阵为8*8,只能显示简单的一些汉子,如果要显示真正的汉字
//通过取模软件取的可以选择16*16点阵的板子
#include<reg51.h>
#include<intrins.h>
sbit SRCLK=P3^6;
sbit RCLK=P3^5;
sbit SER=P3^4;
//--定义要使用的IO口--//
#define COMMONPORTS P0
//--列选通控制--//
unsigned char code TAB[8] = {0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
//--点阵字码--//
unsigned char code CHARCODE[4][8]=
{
0x00,0x12,0x14,0x78,0x14,0x12,0x00,0x00, //大
0x00,0x08,0x12,0x01,0xFF,0x00,0x10,0x08, //小
0x7F,0x41,0x5D,0x55,0x5D,0x41,0x7F,0x00, //回
{0x7C,0x48,0x48,0xFF,0x48,0x48,0x7C,0x00} //中
};
void delay(unsigned int time)
{
unsigned int i,j;
for(i=0;i<time;i++)
for(j=0;j<121;j++);
}
/*******************************************************************************
* 函数名 : Hc595SendByte(unsigned char dat)
* 函数功能 : 想74H595发送一个字节的数据
* 输入 : 无
* 输出 : 无
*******************************************************************************/
void Hc595SendByte(unsigned char dat)
{
unsigned char a;
SRCLK=0;
RCLK=0;
for(a=0;a<8;a++)
{
SER=dat>>7;
dat<<=1;
SRCLK=1;
_nop_();
_nop_();
SRCLK=0;
}
RCLK=1;
_nop_();
_nop_();
RCLK=0;
}
/*******************************************************************************
* 函数名 : main
* 函数功能 : 主函数
* 输入 : 无
* 输出 : 无
*******************************************************************************/
void main()
{
unsigned char tab, j;
unsigned int i;
while(1)
{
for(i= 0; i<50; i++ ) //两个字之间的扫描间隔时间
{
for(tab=0;tab<8;tab++)
{
Hc595SendByte(0x00); //消隐
COMMONPORTS = TAB[tab]; //输出字码
Hc595SendByte(CHARCODE[j][tab]);
delay(2);
}
}
j++;
if(j == 4)
{
j = 0;
}
}
}