新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī) 12864lcd 滾動(dòng)顯示

單片機(jī) 12864lcd 滾動(dòng)顯示

作者: 時(shí)間:2016-11-22 來(lái)源:網(wǎng)絡(luò) 收藏

#include

本文引用地址:http://butianyuan.cn/article/201611/319672.htm

#define Disp_On 0x3f
#define Disp_Off 0x3e
#define Col_Add0x40


#define Page_Add 0xb8
#define Start_Line 0xc0
#define delaytime 10 //設(shè)定字與字間延時(shí),會(huì)影響到滾動(dòng)的快慢

int st_line=Start_Line; //設(shè)定開(kāi)始顯示行


sbit cs1=P2^0;
sbit cs2=P2^1;
sbit Enable=P2^2;
sbit RW=P2^3;
sbit RS=P2^4;


//將要顯示的文字放在32*32的數(shù)組中,一行里面則對(duì)應(yīng)一個(gè)漢字
unsigned char code dat[32][32]=
{


0x02,0xF2,0x12,0x12,0x12,0xFE,0x92,0x12,0x12,0xFE,0x12,0x12,0x12,0xFB,0x12,0x00,
0x00,0x7F,0x08,0x04,0x03,0x00,0x10,0x09,0x06,0x01,0x01,0x26,0x40,0x3F,0x00,0x00,



0x00,0x80,0x80,0x40,0x20,0x10,0x0C,0xE3,0x04,0x08,0x10,0x20,0x60,0xC0,0x40,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,



0x20,0x24,0x24,0xA4,0xA4,0xBF,0xA4,0xE4,0xA4,0xBF,0xA4,0xA4,0x24,0x24,0x20,0x00,
0x00,0x80,0x80,0x5F,0x32,0x12,0x12,0x1F,0x12,0x12,0x32,0x5F,0xC0,0x00,0x00,0x00,



0xFA,0x8A,0xFA,0x02,0xFA,0x8A,0x0A,0xFA,0x00,0xFC,0x0E,0x35,0x44,0x7C,0x00,0x00,
0x7F,0x41,0x7F,0x00,0x7F,0x20,0x41,0x3F,0x08,0x09,0x09,0x09,0x29,0x41,0x3F,0x00,




0x00,0xFC,0x04,0x04,0xFC,0x00,0xFC,0x04,0x16,0x65,0x04,0x84,0xFC,0x00,0x00,0x00,
0x00,0x03,0x02,0x0A,0x0B,0x08,0x0B,0x0A,0x0A,0x0A,0x0A,0x4A,0x82,0x7E,0x00,0x00,



0x00,0x41,0x63,0x55,0x49,0xC1,0x5F,0x50,0x61,0x53,0xCD,0x41,0x5F,0x40,0x00,0x00,
0x00,0x08,0x08,0x0C,0x0A,0x09,0x0A,0xFC,0x08,0x0A,0x09,0x0A,0x0C,0x08,0x08,0x00,



0x08,0x88,0x68,0xFF,0x28,0x48,0xFC,0x04,0x02,0xF2,0x00,0xFC,0x04,0x04,0xFC,0x00,
0x02,0x01,0x00,0xFF,0x00,0x40,0x47,0x22,0x19,0x07,0x00,0xFF,0x02,0x04,0x03,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,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,



0x10,0x08,0x84,0xC6,0x73,0x22,0x40,0x44,0x44,0x44,0xC4,0x44,0x44,0x44,0x40,0x00,
0x02,0x01,0x00,0xFF,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,



0x00,0x00,0xF8,0x08,0x08,0x0C,0x0B,0x08,0x08,0x08,0x08,0x08,0xF8,0x00,0x00,0x00,
0x00,0x00,0x7F,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x7F,0x00,0x00,0x00,



0x80,0xF7,0x85,0x7D,0x55,0xD7,0x40,0x14,0xF7,0xAA,0xAA,0xB6,0xF2,0x10,0x00,0x00,
0x40,0x40,0x40,0x5F,0x51,0x53,0x55,0x51,0x51,0x55,0x17,0x50,0x90,0x70,0x00,0x00,



0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x00,
0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x60,0x40,0x00,



0x40,0x40,0x44,0x54,0x54,0x54,0x54,0x7F,0x54,0x54,0x54,0x54,0x44,0x40,0x40,0x00,
0x00,0x00,0x00,0xFF,0x15,0x15,0x15,0x15,0x15,0x55,0x95,0x7F,0x00,0x00,0x00,0x00,



0x00,0x40,0x42,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x40,0x00,
0x00,0x80,0x40,0x20,0x10,0x08,0x06,0x01,0x02,0x04,0x08,0x10,0x30,0x60,0x20,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,



0x00,0x4C,0x44,0xE4,0x54,0x44,0x64,0xD5,0x46,0x44,0x4C,0x54,0xD4,0x24,0x2C,0x00,
0x00,0x00,0x00,0xFF,0x44,0x62,0x55,0x49,0x55,0x43,0x41,0x40,0xFF,0x00,0x00,0x00,



0x08,0x08,0xE8,0xA8,0xA9,0xAE,0xEA,0x08,0x08,0xC8,0x0C,0x0B,0xEA,0x08,0x08,0x00,
0x00,0x00,0x7F,0x04,0x24,0x44,0x3F,0x00,0x00,0x1F,0x40,0x80,0x7F,0x00,0x00,0x00,



0x02,0xF2,0x12,0x12,0x12,0xFE,0x12,0x12,0x12,0xFE,0x12,0x12,0x12,0xF2,0x02,0x00,
0x00,0x7F,0x28,0x24,0x22,0x21,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x7F,0x00,0x00,



0x00,0xF0,0x00,0xFF,0x00,0xF0,0x40,0x20,0x10,0x2C,0x43,0x04,0x08,0x70,0x20,0x00,
0x08,0x1F,0x08,0x07,0x04,0x07,0x01,0x05,0x09,0x11,0x29,0x65,0x03,0x01,0x00,0x00,



0x40,0x40,0x44,0x44,0x44,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

};

//延時(shí)函數(shù)
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;//當(dāng)E由H到L時(shí)數(shù)據(jù)寫入
Enable=0;

}


//寫數(shù)據(jù)
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頁(yè),每頁(yè)64行
{
write_com(Page_Add+k);
for(j=0;j<64;j++)
write_data(0x00);
}
cs1=0;cs2=0;
}

//顯示漢字.漢字的顯示是先顯示第一頁(yè),再顯示第二頁(yè).
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用來(lái)統(tǒng)計(jì)顯示的字?jǐn)?shù)

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;//顯示一個(gè)漢字后列數(shù)加16,當(dāng)超過(guò)64,回0
if(col==64)
col=0;

if(!(zishu%4)) //當(dāng)顯示的字?jǐn)?shù)為4,12,28時(shí)在左半屏
{cs1=0;cs2=1;}

if(!(zishu%8)) //當(dāng)顯示的字?jǐn)?shù)為8,16,32時(shí)在右半屏,并且右半屏顯示完之后,頁(yè)數(shù)加2。因?yàn)闈h字占用的空間為16*16,8行為一頁(yè)
{cs1=1;cs2=0;pag+=2;}

if(!(zishu%32))
{
st_line+=3; //當(dāng)顯示完32個(gè)字的時(shí)候,起始行加一,達(dá)到滾動(dòng)效果

if(st_line>=0xff) //如果起始行超過(guò)最尾部,則重新置數(shù)
st_line=Start_Line;

write_com(st_line+0); // 設(shè)置右半屏起始行

cs1=0;cs2=1;
write_com(st_line+0); //設(shè)置左半屏起始行

zishu=0;pag=0; //將字?jǐn)?shù)和頁(yè)數(shù)都清0

cs1=1;cs2=0; //選中左半屏
}


}


}



評(píng)論


技術(shù)專區(qū)

關(guān)閉