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

实验名称:12864LCD实验一

实验目的:在12864第一行显示"今天的日期是",第二行

 显示"2015年",第三行显示"1月30日",第四行

 显示"星期五"

实验备注:

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

#include


#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 LCDRW = P3^6;

sbit LCDPSB = P3^7;


uchar code line_0[]=

"今天的日期是";

uchar code line_1[]=

"2015年";

uchar code line_2[]=

"01月30日";

uchar code line_3[]=

"星期五";


void delay_1ms(uchar);

void lcd_init();

void lcd_pos(uchar, uchar);

void lcd_com(uchar);

void lcd_dat(uchar);


void main()

{

uchar i;

lcd_init();

lcd_pos(0,0);

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

{

lcd_dat(line_0[i]);

}

lcd_pos(1,0);

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

{

lcd_dat(line_1[i]);

}

lcd_pos(2,0);

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

{

lcd_dat(line_2[i]);

}

lcd_pos(3,0);

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

{

lcd_dat(line_3[i]);

}

while(1);

}


void delay_1ms(uchar x)

{

uchar i, j;

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

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

}


void lcd_init()

{

DUAN = 0;

WEI = 0;

LCDPSB = 1;

LCDRW = 0;

LCDEN = 0;

lcd_com(0x30);

lcd_com(0x0e);

lcd_com(0x02);

lcd_com(0x01);

}


void lcd_pos(uchar i, uchar j)

{

uchar temp;

switch(i)

{

case 0:

temp = 0x80 + j;

break;

case 1:

temp = 0x90 + j;

break;

case 2:

temp = 0x88 + j;

break;

case 3:

temp = 0x98 + j;

}

lcd_com(temp);

}


void lcd_com(uchar x)

{

LCDEN = 0;

LCDRS = 0;

P0 = x;

delay_1ms(5);

LCDEN = 1;

delay_1ms(5);

LCDEN = 0;

}


void lcd_dat(uchar x)

{

LCDEN = 0;

LCDRS = 1;

P0 = x;

delay_1ms(5);

LCDEN = 1;

delay_1ms(5);

LCDEN = 0;

}