/*************************************
功能:采用ARM7--LPC2114的GPIO口控制LCD1602显示
接线:P0.0~P0.7接D0~D7
P0.8~P0.9,P0.12接RS,RW,E
作者:alexcheng1120
日期:2008-4-22
*************************************/
#include "config.h"
#define LCD_RS 0x00000100 //P0.8接RS
#define LCD_RW 0x00000200 //P0.9接RW
#define LCD_E 0x00001000 //P0.12接E
#define LCD_BUSY 0x00000080
void Delayms(uint32 count)
{
uint32 i;
for(i=0;i<count;i++);
}
void LCD_ChkBusy(void)
{
IO0DIR=0x00001300;
IO0CLR=LCD_RS;
IO0SET=LCD_RW;
IO0SET=LCD_E;
while((IO0PIN&LCD_BUSY)!=0);
Delayms(400);
IO0CLR=LCD_E;
IO0DIR=0x000013ff;
}
void LCD_WriteCommand(uint8 cmd,uint8 busyc)
{
if(busyc) LCD_ChkBusy();
IO0CLR=LCD_E;
IO0CLR=LCD_RS;
IO0CLR=LCD_RW;
IO0CLR=0x000000ff; //清零数据位D0-D7
IO0SET=cmd;
IO0SET=LCD_E; //LCD使能
Delayms(400);
IO0CLR=LCD_E;
}
void LCD_WriteData(uint8 dat)
{
LCD_ChkBusy();
IO0CLR=LCD_E;
IO0SET=LCD_RS;
IO0CLR=LCD_RW;
IO0CLR=0x000000ff;
IO0SET=dat;
IO0SET=LCD_E;
Delayms(400);
IO0CLR=LCD_E;
}
void LCD_Init()
{
Delayms(1000);
LCD_WriteCommand(0x38,0);//三次显示模式设置,不检测忙信号
Delayms(400);
LCD_WriteCommand(0x38,0);
Delayms(400);
LCD_WriteCommand(0x38,0);
Delayms(2800);
LCD_WriteCommand(0x38,1);//显示模式设置,开始要求检测忙信号:8位、2行、5X7点阵
Delayms(2800);
LCD_WriteCommand(0x08,1);//关闭显示
Delayms(2800);
LCD_WriteCommand(0x01,1);//清屏
Delayms(2800);
LCD_WriteCommand(0x06,1);//显示光标移动设置:文字不动,光标自动右移
Delayms(2800);
LCD_WriteCommand(0x0C,1);//显示开及光标设置:光标关、光标不闪烁
}
void LCD_SetPointion(uint8 x)
{
LCD_WriteCommand(x|0x80,0);
}
void LCD_PrintChar(uint8 lcd_data) //输出一个字符到LCD
{
LCD_WriteData(lcd_data);
}
void LCD_PrintString(uint8 *lcd_string) //输出一个字符串到LCD
{
uint8 i="0";
while(lcd_string!=0x00)
{
LCD_WriteData(lcd_string);
i++;
}
}
void main()
{
uint8 Text1[]="Nice to See You!";
uint8 Text2[]=" QQ: 52626392 ";
PINSEL0=0x00000000;
IO0DIR =0x000013ff;
LCD_Init();
while(1)
{
LCD_SetPointion(0);
LCD_PrintString(Text1);
LCD_SetPointion(0x40);
LCD_PrintString(Text2);
}
}
用户311892 2011-3-9 17:00
用户311892 2011-3-9 16:59
用户177080 2008-10-18 20:32
用户177080 2008-10-18 20:31
用户140537 2008-4-23 13:46