微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 单片机 12864lcd 滚动显示

单片机 12864lcd 滚动显示

时间:11-22 来源:互联网 点击:
44,0x44,0x44,0xFC,0x42,0x42,0x42,0x43,0x42,0x60,0x40,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x24,0x24,0xE4,0xFC,0xA2,0x22,0x22,0x80,0x70,0x00,0xFF,0x40,0x20,0x18,0x00,0x00,
0x02,0x01,0x00,0xFF,0x00,0x83,0x40,0x20,0x18,0x07,0x01,0x06,0x18,0xE0,0x40,0x00,

0x00,0x18,0x0A,0xAA,0xAA,0xAA,0x0A,0xFE,0x0A,0xAA,0xAA,0xAA,0x0A,0x18,0x08,0x00,
0x00,0x00,0x42,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0xFE,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x58,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0xF8,0x01,0x06,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0xFE,0x00,0x00,
0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,

0x08,0x31,0x06,0xC0,0x30,0x00,0xF8,0x08,0x0C,0x0B,0x08,0x08,0x08,0xF8,0x00,0x00,
0x02,0x02,0xFF,0x00,0x00,0x00,0xFF,0x41,0x41,0x41,0x41,0x41,0x41,0xFF,0x00,0x00,

0x00,0x04,0x04,0xC4,0xB4,0x8C,0x87,0x84,0xF4,0x84,0x84,0x84,0x84,0x04,0x00,0x00,
0x00,0x00,0x20,0x18,0x0E,0x04,0x20,0x40,0xFF,0x00,0x02,0x04,0x18,0x30,0x00,0x00,

0x00,0x00,0x80,0xBE,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xBE,0x80,0x00,0x00,0x00,
0x84,0x84,0x44,0x44,0x24,0x14,0x0C,0x07,0x0C,0x14,0x24,0x64,0xC4,0x44,0x04,0x00,

0x00,0x02,0x02,0x02,0x02,0x82,0x7E,0x22,0x22,0x22,0x22,0xF2,0x22,0x02,0x02,0x00,
0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x20,0x60,0x20,0x1F,0x00,0x00,0x00,0x00,

0x00,0x00,0xFF,0x91,0x91,0x91,0x91,0xFF,0x91,0x91,0x91,0x91,0xFF,0x00,0x00,0x00,
0x40,0x40,0x44,0x44,0x44,0x44,0x44,0x7F,0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00,

0x80,0x80,0xFC,0x96,0xA5,0xFC,0x80,0x40,0x3E,0x02,0x02,0x02,0x7E,0x40,0x40,0x00,
0x80,0x60,0x1F,0x42,0x84,0x7F,0x00,0x00,0x7E,0x22,0x22,0x22,0x22,0x7E,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x18,0x24,0x24,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

};

//延时函数
void delay(unsigned int t)
{
unsigned int i,j;
for(i=0;ifor(j=0;j<10;j++);
}

//写命令
void write_com(unsigned char cmdcode)
{
RS=0;//写命令
RW=0;
P0=cmdcode;
Enable=1;//当E由H到L时数据写入
Enable=0;

}

//写数据
void write_data(unsigned char Dispdata)
{
RS=1;
RW=0;
P0=Dispdata;
Enable=1;
Enable=0;
}

//清屏
void Clr_Scr()
{
unsigned char j,k;
cs1=1;cs2=1;//左右都不选中
write_com(Page_Add);
write_com(Col_Add);
for(k=0;k<8;k++) //lcd分8页,每页64行
{
write_com(Page_Add+k);
for(j=0;j<64;j++)
write_data(0x00);
}
cs1=0;cs2=0;
}

//显示汉字.汉字的显示是先显示第一页,再显示第二页.
void hz_disp16(unsigned char pag,unsigned char col, unsigned char code *hzk)
{
unsigned char j=0,i=0;
for(j=0;j<2;j++)
{
write_com(Page_Add+pag+j);
delay(3);
write_com(Col_Add+col);
delay(3);
for(i=0;i<16;i++)
{
write_data(hzk[16*j+i]);
delay(3);
}
}
}

//显示字母
void hz_disp8(unsigned char pag,unsigned char col,unsigned char code *hzk)
{
unsigned char j=0,i=0;
for(j=0;j<2;j++)
{
write_com(Page_Add+pag+j);
delay(3);
write_com(Col_Add+col);
delay(3);
for(i=0;i<8;i++)
write_data(hzk[8*j+i]);
delay(3);
}
}

//初始化
void init_lcd()
{
delay(10);
cs1=1;
cs2=1;
delay(10);
write_com(Disp_Off);
write_com(Page_Add+0);
write_com(st_line+0);
write_com(Col_Add+0);
write_com(Disp_On);
}

void main()
{
int pag=0,col=0,zishu=0; //zishu用来统计显示的字数

init_lcd();
Clr_Scr();
cs1=1;cs2=1;
delay(10);
cs1=1;cs2=0;

while(1)
{

hz_disp16(pag,col,dat[zishu]);
delay(delaytime);
zishu++;

col=col+16;//显示一个汉字后列数加16,当超过64,回0
if(col==64)
col=0;

if(!(zishu%4)) //当显示的字数为4,12,28时在左半屏
{cs1=0;cs2=1;}

if(!(zishu%8)) //当显示的字数为8,16,32时在右半屏,并且右半屏显示完之后,页数加2。因为汉字占用的空间为16*16,8行为一页
{cs1=1;cs2=0;pag+=2;}

if(!(zishu%32))
{
st_line+=3; //当显示完32个字的时候,起始行加一,达到滚动效果

if(st_line>=0xff) //如果起始行超过最尾部,则重新置数
st_line=Start_Line;

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top