贴代码:
/*LCD Driver*/
/*port define*/
/*-LCD Port--------------G13 Port--*/
/*--DB0~DB7---------------P1-----*/
/*---RS-------------------P41----*/
/*---RW-------------------P42----*/
/*---E--------------------P43----*/
/*-------------------------------*/
/*Port define end*/
//unsigned char table1[] = "E";
//
//unsigned char num;
void delay_1us(void)
{
unsigned int i;
for(i=0; i<100; i++);
}
void delay_nus(unsigned int n)
{
unsigned int i;
for(i=0; i<n; i++)
{
delay_1us();
}
}
void delay_1ms(void)
{
unsigned int i;
for(i=0; i<1000; i++);
}
void delay_nms(unsigned int n)
{
unsigned int i;
for(i=0; i<n; i++)
{
delay_1ms();
}
}
void write_lcd_com(unsigned int com)
{
P1 = 0x00;
//RS_H;
P4_bit.no1 = 1;
//RW_H;
P4_bit.no2 = 1;
//EN_L;
P4_bit.no3 = 0;
P1 = com;
//RS_L;
P4_bit.no1 = 0;
//RW_L;
P4_bit.no2 = 0;
//EN_H;
P4_bit.no3 = 1;
//EN_L;
P4_bit.no3 = 0;
delay_nus(20);
}
void write_lcd_data(unsigned int data)
{
P1 &= 0x00;
//RS_L;
P4_bit.no1 = 0;
//RW_H;
P4_bit.no2 = 1;
//EN_L;
P4_bit.no3 = 0;
P1 = data;
//RS_H;
P4_bit.no1 = 1;
//RW_L;
P4_bit.no2 = 0;
//EN_H;
P4_bit.no3 = 1;
//EN_L;
P4_bit.no3 = 0;
delay_nus(20);
}
void init_LCD(void)
{
write_lcd_com(0x38);//设置8位格式,2行,5x7点阵字符 0011 1000
delay_nms(5);
write_lcd_com(0x08);//关闭显示 0000 1000
delay_nms(5);
write_lcd_com(0x01);//清除屏幕显示 0000 0001
delay_nms(5);
write_lcd_com(0x06);//设定输入方式,增量不移位 0000 0110
delay_nms(5);
write_lcd_com(0x02);//光标归位 0000 0010
delay_nms(5);
write_lcd_com(0x0F);//开显示,关光标,不闪烁 0000 1100
delay_nms(50);
}
void lcd_write_char(unsigned char x, unsigned char y, unsigned char data)
{
unsigned char address;
if(y==1)
{
address = 0x80 + x;
}
else
{
address = 0xc0 +x;
}
write_lcd_com(address);
write_lcd_data(data);
}
/*LCD Driver End*/
/* End user code. Do not edit comment generated here */
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function implements main function.
**
** Parameters:
** None
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
/* Start user code for adding. Do not edit comment generated here */
void main(void)
{
/* Start user code. Do not edit comment generated here */
delay_nms(5);
init_LCD();
delay_nms(5);
//RTC_Init();
lcd_write_char(0, 1, 'A');
// while(1u)
// {
// ;
// }
/* End user code. Do not edit comment generated here */
}
/* End user code. Do not edit comment generated here */