#include<delay.h>//1MS延时
#define uchar unsigned char
#define uint unsigned int
#define hang P1 //行扫描接在P1口
sbit ds=P0^0
sbit clk=P0^1
sbit mr=P0^2
sbit g1=P0^3
sbit stcp=P0^4
uint counter
uchar flag
uchar code display[][32]={
/*-- 文字: 好 --*/
/*-- 宋体12此字体下对应的点阵为:宽x高=16x16 --*/
0x10,0x00,0x11,0xFC,0x10,0x08,0x10,0x10,0xFC,0x20,0x24,0x20,0x24,0x20,0x27,0xFE,
0x44,0x20,0x64,0x20,0x18,0x20,0x08,0x20,0x14,0x20,0x26,0x20,0x44,0xA0,0x80,0x40,
/*-- 文字: 好 --*/
/*-- 宋缺并缓体12此字体下对应的点阵为:宽x高=16x16 --*/
0x10,0x00,0x11,0xFC,0x10,0x08,0x10,0x10,0xFC,0x20,0x24,0x20,0x24,0x20,0x27,0xFE,
0x44,0x20,0x64,0x20,0x18,0x20,0x08,0x20,0x14,0x20,0x26,0x20,0x44,0xA0,0x80,0x40,
/*-- 文字: 学 --*/
/*-- 宋体12此字体下对应的点阵为:宽x高=16x16 --*/
0x01,0x08,0x10,0x8C,0x0C,0xC8,0x08,0x90,0x7F,0xFE,0x40,0x04,0x8F,0xE8,0x00,0x40,
0x00,0x80,0x7F,0xFE,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x02,0x80,0x01,0x00,
/*-- 文字: 习 --*/
/*-- 宋体12此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x3F,0xFC,0x00,0x04,0x08,0x04,0x04,0x04,0x03,0x04,0x01,0x14,0x00,0x64,
0x01,0x84,0x06,0x04,0x38,0x04,0x10,0x04,0x00,0x04,0x00,0x24,0x00,0x14,0x00,0x00,
/*-- 文字: 天 --*/
/*-- 宋体12此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x08,0x7F,0xFC,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x04,0xFF,0xFE,0x01,0x00,
0x02,0x80,0x02,0x80,0x04,0x40,0x04,0x40,0x08,0x20,0x10,0x10,0x20,0x0E,0xC0,0x04,
/*-- 文字: 天 --*/
/*-- 宋体12此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x08,0x7F,0xFC,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x04,0xFF,0xFE,0x01,0x00,
0x02,0x80,0x02,0x80,0x04,0x40,0x04,0x40,0x08,0x20,0x10,0x10,0x20,0x0E,0xC0,0x04,
/*-- 文字: 向 --*/
/伏模*-- 宋体12此字体下对应的点阵为蔽激:宽x高=16x16 --*/
0x02,0x00,0x04,0x00,0x08,0x04,0x7F,0xFE,0x40,0x04,0x40,0x24,0x4F,0xF4,0x48,0x24,
0x48,0x24,0x48,0x24,0x48,0x24,0x4F,0xE4,0x48,0x24,0x40,0x04,0x40,0x14,0x40,0x08,
/*-- 文字: 上 --*/
/*-- 宋体12此字体下对应的点阵为:宽x高=16x16 --*/
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x10,0x01,0xF8,0x01,0x00,0x01,0x00,
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x04,0xFF,0xFE,0x00,0x00}
void write_595(uchar shuju) //向595写一个字节的数据
{
uchar i
for(i=0i<8i++)
{
ds=(~shuju)&0x01
clk=1
clk=0
shuju=shuju>>1
}
}
void main() //主函数
{
uchar i,j,k
g1=0//154使能
EA=1//开总中断
TMOD=0x01//定时器0工作方式0
ET0=1//定时器0使能
TH0=(65535-50000)/256//定时器0设置初值
TL0=(65536-50000)%256
while(1)
{
for(i=0i<16i++) //字从下往上滚动出现
{
k=1
for(j=i+1j>0j--)
{
write_595(display[7][k])
write_595(display[7][k-1])
write_595(display[6][k])
write_595(display[6][k-1])
write_595(display[5][k])
write_595(display[5][k-1])
write_595(display[4][k])
write_595(display[4][k-1])
k+=2
hang=16-j
stcp=1stcp=0
}
delay_ms(20)
}
TR0=1flag=1
while(flag) //停留一秒
{
uchar j
for(j=0j<16j++)
{
write_595(display[7][j*2+1])
write_595(display[7][j*2])
write_595(display[6][j*2+1])
write_595(display[6][j*2])
write_595(display[5][j*2+1])
write_595(display[5][j*2])
write_595(display[4][j*2+1])
write_595(display[4][j*2])
hang=j
stcp=1stcp=0
}
}
TR0=0
for(i=16i>0i--) //字滚动出显示区
{
k=31
for(j=i-1j>0j--)
{
write_595(display[7][k])
write_595(display[7][k-1])
write_595(display[6][k])
write_595(display[6][k-1])
write_595(display[5][k])
write_595(display[5][k-1])
write_595(display[4][k])
write_595(display[4][k-1])
k-=2
hang=j
stcp=1stcp=0
}
delay_ms(20)
}
for(i=0i<16i++) //下四个字滚动出现在显示区
{
k=1
for(j=i+1j>0j--)
{
write_595(display[3][k])
write_595(display[3][k-1])
write_595(display[2][k])
write_595(display[2][k-1])
write_595(display[1][k])
write_595(display[1][k-1])
write_595(display[0][k])
write_595(display[0][k-1])
k+=2
hang=16-j
stcp=1stcp=0
}
delay_ms(20)
}
TR0=1flag=1
while(flag) //停留一秒
{
uchar j
for(j=0j<16j++)
{
write_595(display[3][j*2+1])
write_595(display[3][j*2])
write_595(display[2][j*2+1])
write_595(display[2][j*2])
write_595(display[1][j*2+1])
write_595(display[1][j*2])
write_595(display[0][j*2+1])
write_595(display[0][j*2])
hang=j
stcp=1stcp=0
}
}
TR0=0
for(i=16i>0i--) //滚出显示区
{
k=31
for(j=i-1j>0j--)
{
write_595(display[3][k])
write_595(display[3][k-1])
write_595(display[2][k])
write_595(display[2][k-1])
write_595(display[1][k])
write_595(display[1][k-1])
write_595(display[0][k])
write_595(display[0][k-1])
k-=2
hang=j
stcp=1stcp=0
}
delay_ms(20)
}
}
void timer0() interrupt 1 //中断函数
{
counter++
if(counter==20) //1秒设置
{
counter=0
flag=0
}
TH0=(65535-50000)/256
TL0=(65536-50000)%256
}
以简单的8X8点阵为例,它共由64个发光二极管组成,且每个发光二极管是放置在行线和列线的交叉点上,当对应悄段的某一行置1电平码运液,某一列置0电平,则相应的二极管就亮如要将第一个点点亮,则9脚接高电平13脚接低电平,则迟物第一个点就亮了如果要将第一行点亮,则第9脚要接高电平,而(13、3、4、10、6、11、15、16)这些引脚接低电平,那么第一行就会点亮如要将第一列点亮,则第13脚接低电平,而(9、14、8、12、1、7、2、5)接高电平,那么第一列就会点亮.
/*--------16*16点阵屏的移动显示------------*/#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned char
#define DATE_OUT P1 //指定P1口做为输出
sbit DATA=DATE_OUT^0 //列数据输出位
sbit SCLH=DATE_OUT^1 //列扫描时钟位
sbit SCLT=DATE_OUT^2 //列数据锁存位
sbit AB =DATE_OUT^3 //行数据输帆高出位
sbit SCK =DATE_OUT^4 //行扫描时钟位
sbit kong=DATE_OUT^5
unsigned char xxx=0,upcount=0
unsigned char ccc,time1time=0,s=0
//段前缀李轿辩{
//段哪缺后缀};
//注释前缀、/*"
//注释后缀",
//数据前缀 0x
//数据后缀,
//行前缀
//行后缀},
//行尾缀*/
code unsigned char dong[16][32]={
{0x00,0x80,0x00,0x80,0xFC,0x80,0x04,0xFC,0x05,0x04,0x49,0x08,0x2A,0x40,0x14,0x40,
0x10,0x40,0x28,0xA0,0x24,0xA0,0x45,0x10,0x81,0x10,0x02,0x08,0x04,0x04,0x08,0x02},/*"欢",0*/
{0x00,0x00,0x20,0x80,0x13,0x3C,0x12,0x24,0x02,0x24,0x02,0x24,0xF2,0x24,0x12,0x24,
0x12,0x24,0x12,0xB4,0x13,0x28,0x12,0x20,0x10,0x20,0x28,0x20,0x47,0xFE,0x00,0x00},/*"迎",1*/
{0x01,0x00,0x01,0x00,0x01,0x00,0x7F,0xFC,0x01,0x00,0x11,0x10,0x09,0x10,0x09,0x20,
0xFF,0xFE,0x03,0x80,0x05,0x40,0x09,0x20,0x31,0x18,0xC1,0x06,0x01,0x00,0x01,0x00},/*"来",2*/
{0x00,0x04,0xFF,0x84,0x08,0x04,0x10,0x24,0x22,0x24,0x41,0x24,0xFF,0xA4,0x08,0xA4,
0x08,0x24,0x08,0x24,0x7F,0x24,0x08,0x24,0x08,0x04,0x0F,0x84,0xF8,0x14,0x40,0x08},/*"到",3*/
{0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xF8,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,
0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x0A,0x01,0x02,0x01,0x02,0x00,0xFE},/*"电",4*/
{0x00,0x00,0x7F,0xF8,0x00,0x10,0x00,0x20,0x00,0x40,0x01,0x80,0x01,0x00,0xFF,0xFE,
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00},/*"子",5*/
{0x00,0x00,0x00,0x00,0x7F,0xFC,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00,0x00,0x00},/*"工",6*/
{0x08,0x00,0x1D,0xFC,0xF1,0x04,0x11,0x04,0x11,0x04,0xFD,0xFC,0x10,0x00,0x30,0x00,
0x39,0xFE,0x54,0x20,0x54,0x20,0x91,0xFC,0x10,0x20,0x10,0x20,0x13,0xFE,0x10,0x00},/*"程",7*/
{0x00,0xF8,0x3F,0x00,0x04,0x00,0x08,0x20,0x10,0x40,0x3F,0x80,0x01,0x00,0x06,0x10,
0x18,0x08,0x7F,0xFC,0x01,0x04,0x09,0x20,0x11,0x10,0x21,0x08,0x45,0x04,0x02,0x00},/*"系",8*/
{0x00,0x00,0x00,0x00,0x7F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xF8,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,0x00,0x00,0x00,0x00},/*"三",9*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"一",10*/
{0x02,0x00,0x01,0x00,0x00,0x80,0x00,0x80,0x00,0x00,0xFF,0xFE,0x00,0x00,0x00,0x00,
0x04,0x40,0x04,0x20,0x08,0x10,0x08,0x08,0x10,0x08,0x20,0x04,0x40,0x04,0x00,0x00},/*"六",11*/
{0x02,0x00,0x01,0x00,0x7F,0xFE,0x40,0x02,0x88,0x84,0x04,0x80,0x04,0x80,0x10,0x80,
0x08,0x80,0x08,0x80,0xFF,0xFE,0x01,0x40,0x02,0x20,0x04,0x10,0x18,0x08,0x60,0x04},/*"实",12*/
{0x00,0x20,0xF8,0x20,0x08,0x50,0x48,0x50,0x48,0x88,0x49,0x04,0x4A,0xFA,0x7C,0x00,
0x04,0x44,0x04,0x24,0x1D,0x24,0xE4,0xA8,0x44,0x88,0x04,0x10,0x2B,0xFE,0x10,0x00},/*"验",13*/
{0x02,0x00,0x01,0x00,0x7F,0xFE,0x40,0x02,0x80,0x04,0x3F,0xF8,0x04,0x00,0x08,0x20,
0x1F,0xF0,0x01,0x10,0x01,0x00,0x3F,0xF8,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00},/*"室",14*/
}
idata unsigned char date[3][32]
idata uchar i=0,displayflag=0
uchar k=0
void displaymoveup(unsigned char count,unsigned char time)
void display(unsigned char dis)//做为点阵扫描函数,将显示缓存的数据输出到点阵屏
void displaymove(unsigned char count,unsigned char timer)//显示汉字内容的移动效果,LP指向要显示第一个字的首地址,C表示显示字的个数,
//非常好用的字摸软件PCtoLCD2002完美版 字模选项:阴码、逐行式、顺向
void main(void) //主入口函数
{
display(0)
while(1)
{
displaymove(16,10)
}
}
void display(unsigned char dis)//显示
{
unsigned char i,ia,j,tmp,x //定义变量
DATE_OUT=0XFF //置位高电平做准备
AB=0 //将列数据位清0,准备移位
for(i=0i<16i++)
{ //循环输出16行数据
SCK=0 //为列移位做准备
SCLT=0 //为行锁存做准备
for(x=3x>0x--)
{
for(ia=2ia>0)
{ //每行16个点,循环位移两个字节
ia-- //循环两次
if(dis==1)
{
tmp=~date[x-1][i*2+ia] //读取点阵数据做输出,这里用到ia目的是先读取点阵数据的第二位字节,因一行16个点由两个字节组成, //电路中的移位寄存器最后一位对应最后一列,所以要先输出一行中的第二个字节数据
}
if(dis==0)
tmp=0xff
for(j=0j<8j++)
{ //循环两次,每次移一个字节,
SCLH=0 //为列移位做准备
DATA=tmp&0x01 //将数据低位做输出,由电路图可知,移位寄存器的最后一位对应最后一列,因此先移最后一位
tmp>>=1 //将数据缓冲右移一位,为下次输出做准备
SCLH=1 //将DATA上的数据移入寄存器
} //移入单字节结束
} //移入两个字节结束
}
SCK=1 //SCK拉高,列数据移位,相应行拉低,三极管导通输出电量到相应行点阵管阳极(共阳)
SCLT=1 //SCLT拉高,将数据锁存输出到相应行的点阵发光管显示,显示一行后将保持到下一行显示开始
AB=1 //列数据位只在第一行时为0,其它时候都为1,当将这个0移入寄存器后,从第一位开始一直移位最后一位,
//移位的过程,AB就必需是1,这是因为不能同时有两个及两个以上0的出现,否则显示出乱
}
j=20
while(j--) //每一行的显示,保持16个移位时间,因此,最后一行的显示,也要加入保持时间,补尝显示的亮度
SCK=0 //
SCK=1 //将最后一行数据移出
}
void displaymove(unsigned char count,unsigned char timer)//显示汉字内容的移动效果,
//LP指向要显示第一个字的首地址,C表示显示字的个数, //timer是移动的速度
{
unsigned char c=8,i=0,ia=0,num=0
unsigned char timerc=0
unsigned char tmp2[16]
for(i=0i<16i++)
{
tmp2[i]=dong[xxx/2][i*2+ccc%2] //取半个汉字点阵数据,16字节
}
xxx++
if(xxx==(count*2))
xxx=0
ccc++
while(c)
{ //循环处理
ia=0 //做为点阵数组的元素
for(i=0i<16i++)
{//移动是16行同时移,因此要处理16个字节
// if(date[num][ia]&0x80)
date[num][ia]<<=1 //移当前显示缓冲的前半行字节
if(date[num][ia+1]&0x80) //判断后半行字节的高位是否为1,是移入前半行字节低位,否则不处理
date[num][ia]++
ia++
date[num][ia]<<=1 //移当前显示缓冲的前半行字节
if(date[num+1][ia-1]&0x80) //判断后半行字节的高位是否为1,是移入前半行字节低位,否则不处理
date[num][ia]++
ia--
date[num+1][ia]<<=1 //移当前显示缓冲的前半行字节
if(date[num+1][ia+1]&0x80) //判断后半行字节的高位是否为1,是移入前半行字节低位,否则不处理
date[num+1][ia]++
ia++
date[num+1][ia]<<=1 //移当前显示缓冲的前半行字节
if(date[num+2][ia-1]&0x80) //判断后半行字节的高位是否为1,是移入前半行字节低位,否则不处理
date[num+1][ia]++
ia--
date[num+2][ia]<<=1 //移当前显示缓冲的前半行字节
if(date[num+2][ia+1]&0x80) //判断后半行字节的高位是否为1,是移入前半行字节低位,否则不处理
date[num+2][ia]++
ia++
date[num+2][ia]<<=1
if(tmp2[i]&0x80) //判断下一个要显示汉字的前半行字节的高位是否为1,是移入,否则不处理
date[num+2][ia]++
ia++
tmp2[i]<<=1 //下一个要显示汉字的半行字节向高位移一位,准备下一次取位
}
timerc=timer //处理完16行,调用显示函数更新点阵
while(timerc--) //循环做为处理的速度,即移动的速度
display(1)
//----------
c-- //移完一半,进入下一半或下一个汉字,直到结束
}
}
void displaymoveup(unsigned char count,unsigned char time)
{
unsigned char k,i,j,tim=0
for(i=0i<3i++)
{
for(j=0j<32j++)
{
date[i][j]=xin[upcount][j]
}
upcount++
}
if(upcount==count)
upcount=0
for(k=0k<16k++)
{
for(i=0i<3i++)
{
for(j=0j<32j++)
{
if(j<30)
date[i][j]=date[i][j+2]
if(j>=30)
date[i][j]=0x00
}
}
tim=time
while(tim--)
display(1)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)