请问一下,下面是振南老师的16*16点阵显示程序。每隔一段时间显示一个字,如何实现循环左移或右移显示汉字。望指点
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit lie=P2^1;
sbit shcp=P2^0;
sbit stcp=P2^2;
sbit hang=P2^3;
sbit en=P2^4;
unsigned char h_sel=0; //此变量取值0~15,0x8000>>h_sel 用以选中16X16的某一行
unsigned char dz_buf[16][2]; //16X16点阵的显示缓冲区,32个字节,共256个位,
//用于描述点阵上256点的亮灭状态,更改此缓冲区内
//容后,点阵显示将及时更新
unsigned char code hz_buf[4][32]= //汉字的字模数据
{
{
0x10,0x00,0x13,0xFE,0x12,0x00,0xFE,0x00,0x12,0xFC,0x16,0x00,0x1B,0xFE,0x12,0xC0,
0x32,0xA4,0xD2,0xA6,0x12,0x98,0x12,0x88,0x14,0x88,0x14,0xA6,0x58,0xC4,0x20,0x80,/*"振",0*/
},
{
0x01,0x00,0x01,0x04,0xFF,0xFE,0x01,0x00,0x02,0x00,0x3F,0xFC,0x24,0x24,0x22,0x44,
0x2F,0xF4,0x21,0x04,0x3F,0xFC,0x21,0x04,0x21,0x04,0x21,0x14,0x21,0x08,0x00,0x00,/*"南",1*/
},
{
0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xF8,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,
0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x01,0x02,0x01,0x02,0x00,0xFE,0x00,0x00,/*"电",2*/
},
{
0x00,0x00,0x3F,0xF0,0x00,0x20,0x00,0x40,0x00,0x80,0x01,0x00,0x01,0x00,0x01,0x04,
0xFF,0xFE,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00,/*"子",3*/
}
};
/******************************************************************
- 功能描述:延时函数
- 隶属模块:公开函数模块
- 函数属性:外部,用户可调用
- 参数说明:time:time值决定了延时的时间长短
- 返回说明:无
- 注:.....
******************************************************************/
void delay(unsigned int time)
{
while(time--);
}
void write4_595(uint datl,uint dath)
{
uchar i;
en=1;
dath=~dath;
for(i=0;i<16;i++)
{
lie=(datl&0x01);
hang=(dath&0x01);
shcp=0;
shcp=1;
datl>>=1;
dath>>=1;
}
stcp=0;
stcp=1;
en=0;
}
void timer_init()
{
TMOD=0x01;
EA=1;
ET0=1;
TL0=0x19; /*此处为点阵的刷新频率*/
TH0=0xff;
TR0=1;
}
void timer0() interrupt 1
{
TR0=0;
TL0=0x19; /*此处为点阵的刷新频率*/
TH0=0xff;
write4_595((uint)(dz_buf[h_sel][1])|(uint)(dz_buf[h_sel][0])<<8,0x8000>>h_sel); /*此处的(uint)是不是强制转换的意思,为什么换成(uchar)也没有问题*/
h_sel++;h_sel%=16; //h_sel自增,在0~15循环变化
TR0=1;
}
/******************************************************************
- 功能描述:更新显示缓冲数组的数据
- 隶属模块:16X16点阵模块
- 函数属性:外部,供用户使用
- 参数说明:pbuf:指向新数据的指针
- 返回说明:无
- 注:无
******************************************************************/
void DZ_UpdateBuffer(unsigned char *pbuf)
{
unsigned char i=0;
TR0=0; //停止点阵的扫描
for(i=0;i<32;i++)
{
((unsigned char*)dz_buf)[i]=pbuf[i]; //将新数据放入到显示缓冲数组中 为什么不能直接用dz_but[i]=pbuf[i]
}
TR0=1; //再次启动点阵的扫描
}
void main()
{
unsigned char i=0;
timer_init(); //初始化点阵,启动点阵动态扫描
while(1)
{
DZ_UpdateBuffer(hz_buf[i++]); //将汉字的字模数据更新到显示缓冲数组中 定义的二维数组用1维数组怎么也可以赋值
i%=4; //对i取4的余,使其在0~3变化
delay(60000);//delay(60000);//delay(60000);delay(60000); //延时
}
while(1);
} |