您的位置 首页 FPGA

LCD12864测验程序

LCD12864的控制器为ST7920,带中文字库与图形库,并口驱动。#includereg52.h>#includeintrins.h>#defineuintunsignedint#de

LCD12864的控制器为ST7920,带中文字库与图形库,并口驱动。

#include
#include

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

uchar code table1[]={“Wallacer”};
uchar code table2[]={“我喜爱单片机!”};
uchar code table3[]={“I Like MCU!”};
uchar code table4[]={“河北科技师范学院”};

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) //延时
{
uint x,y;
for(x=110;x>0;x–);
for(y=z;y>0;y–);
}

void lcd_w_com(uchar com)//写指令
{
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)// 写数据
{
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)//挑选写入方位
{
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]!=\0)
{
lcd_w_data(table1[i]);
i++;
}

lcd_pos(1,1);
i=0;
while(table2[i]!=\0)
{
lcd_w_data(table2[i]);
i++;
}

lcd_pos(2,1);
i=0;
while(table3[i]!=\0)
{
lcd_w_data(table3[i]);
i++;
}

lcd_pos(3,0);
i=0;
while(table4[i]!=\0)
{
lcd_w_data(table4[i]);
i++;
}

while(1);
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/fangan/fpga/272782.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部