/******************************************************/
/*CopyRight(C) 2010, Mr. Bean */
/*ProjectName : */
/*FileName :LCD1602Driver.C */
/*Author :Mr. Bean */
/*Date :2010.01.12 */
/*Description :
LCD1602 Driver
HardWare Connection:
MCU:MC9S08JM60
Data :PORTE
RS :PTC0 (Data:Command=H:L)
RW :PTC1 (Read:Write=H:L)
LCD1 CS :PTC2
LCD2 CS :PTC4
1602 液晶的基本的操作分为以下四种:
状态字读操作:输入 RS="低"、RW=高、EP=高; 输出:DB0~7 读出为状态字;
数据读出操作:输入 RS="高"、RW=高、EP=高; 输出:DB0~7 读出为数据;
指令写入操作:输入 RS="低"、RW=低、EP=上升沿; 输出:无;
数据写入操作:输入 RS="高"、RW=低、EP=上升沿; 输出:无。
*/
/*Version :
2010.01.11 V1.0 FirstVersion
*/
/****************************************************/
源代码:
#define RS PTCD_PTCD0
#define RW PTCD_PTCD1
#define E1 PTCD_PTCD4
#define E2 PTCD_PTCD2
#define DB0_DB7 PTED
#define BusyFlag PTED_PTED7
/******单块屏测试实验,显示“#”**************************************/
/******************************************************************/
void LCDRead1()
{
//add
E1=0;
PTEDD=0X00; //PortE Input
PTEPE=0XFF; //Pullup
do
{
RS=0;
RW=1;
SysDelay(10);
E1=1;
SysDelay(10);
}
while(BusyFlag);
}
void LCDWrite1(unsigned char Data) //COMMAND
{
//
E1=0;
PTEDD=0XFF; //PortE Output
PTEPE=0XFF; //Pullup
RS=0;
RW=0;
DB0_DB7=Data;
SysDelay(10);
E1=1;
SysDelay(20);
E1=0;
}
void LCDWrite2(unsigned char Data) //COMMAND
{
//
E1=0;
PTEDD=0XFF; //PortE Output
PTEPE=0XFF; //Pullup
RS=1;
RW=0;
DB0_DB7=Data;
SysDelay(10);
E1=1;
SysDelay(20);
E1=0;
}
void LCDConfig1()
{
//add
LCDRead1();
LCDWrite1(0X38);
LCDRead1();
LCDWrite1(0X06);
LCDRead1();
LCDWrite1(0X0F);
LCDRead1();
LCDWrite1(0X01);
SysDelay(0XFF);
LCDRead1();
LCDWrite1(0X80);
LCDRead1();
LCDWrite2(0X23);
}
显示效果可以去这里查看(双LCD):http://blog.ednchina.com/human1984/394577/message.aspx
文章评论(0条评论)
登录后参与讨论