lpc2131的lcd1602显示,基于easyarm2131完成,如下为代码部分:
/*******************************************************************
** File name: lcd1602_test
** Last modified Date: 2007-09-16
** Last Version: 0.9
*******************************************************************/
#include "config.h"
unsigned char LCM_Data = 0xFF;
#define LCM_RS 1<<8
#define LCM_RW 1<<9
#define LCM_E 1<<10
#define LED 1<<20
void WriteDataLCM(unsigned char WDLCM);
void WriteCommandLCM(unsigned char WCLCM, unsigned char BuysC);
unsigned char ReadDataLCM(void);
unsigned char ReadStatusLCM(void);
void LCMInit(void);
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData);
void DisplayListChar(unsigned char X, unsigned char Y, unsigned char *DData);
void Delay5Ms(void);
void Delay400Ms(void);
void IOInit(void);
unsigned char dle_net[] = {"**Easy_ARM2131**"};
unsigned char mail[] = {"www.mcu123.com"};
int main (void)
{
IOInit();
LCMInit(); //LCM3?ê??ˉ
while(1)
{
DisplayListChar(0,0,dle_net);
DisplayListChar(0,1,mail);
}
}
//D′êy?Y
void WriteDataLCM(unsigned char WDLCM)
{
ReadStatusLCM(); //?ì2a?|
IO0SET=LCM_RS ;
IO0CLR=LCM_RW ;
IO0CLR=LCM_Data;
IO0SET=WDLCM;
Delay5Ms();
IO0CLR=LCM_E ; //è??§???ù?èì????éò??ú?aoó?óD?μ??óê±
Delay5Ms();
IO0SET=LCM_E ;
}
//D′??á?
void WriteCommandLCM(unsigned char WCLCM, unsigned char BuysC)
{
if (BuysC) ReadStatusLCM(); //?ù?YDèòa?ì2a?|
IO0CLR=LCM_RS ;
IO0CLR=LCM_RW ;
IO0CLR=LCM_Data;
IO0SET=WCLCM;
Delay5Ms();
IO0CLR=LCM_E ;
Delay5Ms();
IO0SET=LCM_E ;
}
//?áêy?Y
unsigned char ReadDataLCM(void)
{
IO0SET=LCM_RS ;
IO0SET=LCM_RW ;
IO0CLR=LCM_E ;
Delay5Ms();
IO0SET=LCM_E ;
return(IO0SET&0XFF);
}
//?á×′ì?
unsigned char ReadStatusLCM(void)
{
IO0SET=LCM_Data;
IO0CLR=LCM_RS ;
IO0SET=LCM_RW ;
IO0CLR=LCM_E ;
Delay5Ms();
IO0SET|=LCM_E ;
return(IO0SET&0XFF);
}
//LCM3?ê??ˉ
void LCMInit(void)
{
IO0CLR=LCM_Data ;
WriteCommandLCM(0x38,0); //èy′???ê??£ê?éè??£?2??ì2a?|D?o?
WriteCommandLCM(0x38,0);
WriteCommandLCM(0x38,0);
WriteCommandLCM(0x38,1); //??ê??£ê?éè??,?aê?òa?ó??′??ì2a?|D?o?
WriteCommandLCM(0x08,1); //1?±???ê?
WriteCommandLCM(0x01,1); //??ê????á
WriteCommandLCM(0x06,1); // ??ê?1a±êò??ˉéè??
WriteCommandLCM(0x0C,1); // ??ê??a?°1a±êéè??
}
//IO3?ê??ˉ
void IOInit(void)
{
PINSEL0=0X00000000;
IO0DIR=(LCM_Data|LCM_Data|LCM_RS|LCM_RW|LCM_E|LED) ;
IO0CLR=LED ;
}
//°′???¨??????ê?ò???×?·?
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
{
Y&= 0x1;
X&= 0xF; //?T??X2??ü′óóú15£?Y2??ü′óóú1
if(Y) X|=0x40;//μ±òa??ê?μú?tDDê±μ??·??+0x40;
X|= 0x80; //??3???á???
WriteCommandLCM(X, 0); //?aà?2??ì2a?|D?o?£?·¢?íμ??·??
WriteDataLCM(DData);
}
//°′???¨??????ê?ò?′?×?·?
void DisplayListChar(unsigned char X, unsigned char Y, unsigned char *DData)
{
unsigned char ListLength;
ListLength = 0;
Y&=0x1;
X&=0xF; //?T??X2??ü′óóú15£?Y2??ü′óóú1
while (DData[ListLength]>0x20) //è?μ?′?×?′??2?òí?3?
{
if (X<= 0xF) //X×?±êó|D?óú0xF
{
DisplayOneChar(X, Y, DData[ListLength]); //??ê?μ¥??×?·?
ListLength++;
X++;
}
}
}
//5ms?óê±
void Delay5Ms(void)
{
unsigned int TempCyc = 5552;
while(TempCyc--);
}
//400ms?óê±
void Delay400Ms(void)
{
unsigned char TempCycA = 5;
unsigned int TempCycB;
while(TempCycA--)
{
TempCycB=7269;
while(TempCycB--);
}
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
用户925035 2009-7-30 08:55
用户491040 2009-7-26 22:52
用户461316 2008-8-5 23:17
用户461316 2008-8-5 23:14