|
发表于 2012-5-7 23:28:25
|
显示全部楼层
楼主,你好!我现在做一个16*16的点阵汉字显示,但我的程序出了点问题,就是有些字显示正常,而一些字就会有一两横出现乱码,不知道这是怎么回事呀?急要请楼主帮忙解惑。谢谢!!!
以下是程序的代码:
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit shcp=P0^0; //移位时钟脉冲
//串行数据输入
sbit ds2=P0^3;
sbit ds3=P0^4;
sbit stcp=P0^2; //输出锁存器
uchar temp[];
uchar temp[4]={0,0,0,0};
const uchar tab2[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
uchar code tab0[]={/*-- 文字: 众 --*/
/*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x80,0x00,0x80,0x00,0x40,0x01,0x20,0x02,0x10,0x04,0x08,0x08,0x14,0x14,0x13,0x64,
0x10,0x04,0x10,0x04,0x10,0x04,0x28,0x0A,0x48,0x0A,0x44,0x11,0x82,0x20,0x41,0x40,
};
void delay1(int ms)
{
int k;
while(ms--)
{
for(k=0; k<20; k++)
{
_nop_();
}
}
}
oid wr_5951(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
dat=dat<<1;
ds2=CY;
shcp=1;
_nop_();
_nop_();
shcp=0;
}
}
void wr_5952(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
dat=dat>>1;
ds3=CY;
shcp=1;
_nop_();
_nop_();
shcp=0;
}
}
void OUT_595()//将移位寄存器内的数据锁存到输出寄存器并显示
{
stcp=0;
_nop_();
_nop_();
stcp=1; //上升沿将数据送到输出锁存器
_nop_();
_nop_();
stcp=0;
delay1(3);
}
void main()
{
uchar i,j,t=0,p,q,m=0,k=0;
while(1)
{
for(j=0;j<15;j++)
for(i=0;i<32;i++)
{
P1=tab2[t];
temp[1]=tab0[i];
wr_5951(temp[1]);
OUT_595();
delay1(1);
i++;
temp[0]=tab0[i];
wr_5952(temp[0]);
OUT_595();
delay1(1);
t++;
if(t==16) t=0;
P1=0xff;
}
}
}
|
|