新聞中心

LCD12864測(cè)試程序

作者: 時(shí)間:2016-11-13 來(lái)源:網(wǎng)絡(luò) 收藏
LCD12864的控制器為ST7920,帶中文字庫(kù)與圖形庫(kù),并口驅(qū)動(dòng)。

#include
#include

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

#define uint unsigned int
#define uchar unsigned char
#define P0 P0

uchar code table1[]={"Wallacer"};
uchar code table2[]={"我喜歡單片機(jī)!"};
uchar code table3[]={"I Like MCU!"};
uchar code table4[]={"河北科技師范學(xué)院"};

sbit lcd_rs=P1^0;
sbit lcd_rw=P1^1;
sbit lcd_en=P1^2;
sbit lcd_psb=P2^4;
sbit lcd_rst=P2^3;

void delay(uint z) //延時(shí)
{
uint x,y;
for(x=110;x>0;x--);
for(y=z;y>0;y--);
}

void lcd_w_com(uchar com)//寫(xiě)命令
{
lcd_rs=0;
lcd_rw=0;
lcd_en=0;
P0=com;
delay(5);
lcd_en=1;
delay(5);
lcd_en=0;
}

void lcd_w_data(uchar date)// 寫(xiě)數(shù)據(jù)
{
lcd_rs=1;
lcd_rw=0;
lcd_en=0;
P0=date;
delay(5);
lcd_en=1;
delay(5);
lcd_en=0;
}

void lcd_init()//液晶初始化
{
lcd_rst=0;
delay(10);
lcd_rst=1;
delay(10);
lcd_psb=1;

lcd_w_com(0x30);
lcd_w_com(0x0c);
lcd_w_com(0x14);
lcd_w_com(0x01);
}

void lcd_pos(uchar x,uchar y)//選擇寫(xiě)入位置
{
uchar pos;
if(x==0)
{x=0x80;}
else if(x==1)
{x=0x90;}
else if(x==2)
{x=0x88;}
else if(x==3)
{x=0x98;}
pos=x+y;
lcd_w_com(pos);
}

void main()
{
uchar i;
lcd_init();

lcd_pos(0,2);
i=0;
while(table1[i]!=