/**************************************************

实验名称:1602LCD实验一

实验目的:打开LCD,在第一个空格显示闪烁的光标

实验备注:

**************************************************/

#include<reg52.h>


#define uchar unsigned char

#define uint unsigned int


sbit DUAN = P2^6;

sbit WEI = P2^7;

sbit LCDEN = P3^4;

sbit LCDRS = P3^5;

sbit LCDWR = P3^6;


void delay1ms(uchar);

void lcd_init();

void lcd_com(uchar);

//void lcd_dat(uchar);


void main()

{

lcd_init();

lcd_com(0x80);

while(1);

}


void delay1ms(uchar x)

{

uchar i, j;

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

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

}


void lcd_init()

{

DUAN = 0;

WEI = 0;

LCDWR = 0;

LCDEN = 0;

lcd_com(0x38);

lcd_com(0x0f);

lcd_com(0x06);

lcd_com(0x01);

}


void lcd_com(uchar x)

{

LCDRS = 0;

P0 = x;

delay1ms(5);

LCDEN = 1;

delay1ms(5);

LCDEN = 0;

}


/*void lcd_dat(uchar x)

{

LCDRS = 1;

P0 = x;

delay1ms(5);

LCDEN = 1;

delay1ms(5);

LCDEN = 0;

}*/


/**************************************************

实验名称:1602LCD实验二

实验目的:在1602LCD上第一行显示"I LOVE MCU!",在第

 二行显示"F*CK YOU!"然后实现把字符整屏左

 移进显示屏内。

实验备注:

**************************************************/

#include<reg52.h>


#define uchar unsigned char

#define uint unsigned int


uchar code table_1[] = 

"I LOVE MCU!";

uchar code table_2[] = 

"F*CK YOU!";


sbit DUAN = P2^6;

sbit WEI = P2^7;

sbit LCDEN = P3^4;

sbit LCDRS = P3^5;

sbit LCDRW = P3^6;


void delay1ms(uchar);

void lcd_init();

void lcd_com(uchar);

void lcd_dat(uchar);


void main()

{

uchar i;

lcd_init();

lcd_com(0x80 + 16);

for(i = 0; table_1[i] != '\0'; i++)

{

lcd_dat(table_1[i]);

}

lcd_com(0x80+0x40 + 16 + 5);//第二行+0x40

for(i = 0; table_2[i] != '\0'; i++)

{

lcd_dat(table_2[i]);

}

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

{

lcd_com(0x18);

delay1ms(200);

}

while(1);

}


void delay1ms(uchar x)

{

uchar i, j;

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

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

}


void lcd_init()

{

DUAN = 0;

WEI = 0;

LCDRW = 0;

LCDEN = 0;

lcd_com(0x38);

lcd_com(0x0f);

lcd_com(0x06);

lcd_com(0x01);

}


void lcd_com(uchar x)

{

LCDRS = 0;

P0 = x;

delay1ms(5);

LCDEN = 1;

delay1ms(5);

LCDEN = 0;

}


void lcd_dat(uchar x)

{

LCDRS = 1;

P0 = x;

delay1ms(5);

LCDEN = 1;

delay1ms(5);

LCDEN = 0;

}