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

单片机LCD显示屏

时间:11-21 来源:互联网 点击:
电路图:

代码如下:

#include

#include

sbit RS=0xA0;

sbit RW=0xA1;

sbit E=0xA2;

void lcd_w_cmd(unsigned char com);

void lcd_w_dat(unsigned char dat);

unsigned char lcd_r_start();

void init();

void delay(unsigned char t);

void delay1();

void GONG_ZI()

{

lcd_w_cmd(0x40);

lcd_w_dat(0x1f);

lcd_w_cmd(0x41);

lcd_w_dat(0x1f);

lcd_w_cmd(0x42);

lcd_w_dat(0x04);

lcd_w_cmd(0x43);

lcd_w_dat(0x04);

lcd_w_cmd(0x44);

lcd_w_dat(0x04);

lcd_w_cmd(0x45);

lcd_w_dat(0x1f);

lcd_w_cmd(0x46);

lcd_w_dat(0x1f);

lcd_w_cmd(0x47);

lcd_w_dat(0x00);

}

void main()

{

unsigned char lcd[]="cgyl2010!!";

unsigned char lcd1[]="linux kernel!!";

unsigned char i;

P0=0xff;

init();

delay(255);

delay(255);

lcd_w_cmd(0x83);

delay(255);

for(i=0;i<10;i++)

{

lcd_w_dat(lcd[i]);

delay(200);

}

lcd_w_cmd(0xc1);

delay(255);

for(i=0;i<14;i++)

{

lcd_w_dat(lcd1[i]);

delay(200);

}

while(1);

}

void delay(unsigned char t)

{

unsigned char j,i;

for(i=0;i

for(j=0;j<50;j++);

}

void delay1()

{

_nop_();

_nop_();

_nop_();

}

void init()

{

lcd_w_cmd(0x3c);

lcd_w_cmd(0x0e);

lcd_w_cmd(0x01);

lcd_w_cmd(0x06);

lcd_w_cmd(0x80);

}

unsigned char lcd_r_start()

{

unsigned char s;

RW=1;

delay1();

RS=0;

delay1();

E=1;

s=P0;

delay1();

E=0;

delay1();

RW=0;

delay1();

return s;

}

void lcd_w_cmd(unsigned char com)

{

unsigned char i;

do{

i=lcd_r_start();

i=i&0x80;

delay(2);

}while(i!=0);

RW=0;

delay1();

RS=0;

delay1();

E=1;

delay1();

P0=com;

delay1();

E=0;

delay1();

RW=1;

delay(255);

}

void lcd_w_dat(unsigned char dat)

{

unsigned char i;

do{

i=lcd_r_start();

i=i&0x80;

delay(2);

}while(i!=0);

RW=0;

delay1();

RS=1;

delay1();

E=1;

delay1();

P0=dat;

delay1();

E=0;

delay1();

RW=1;

delay(255);

}


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

网站地图

Top