原创 lpc2131 lcd1602_test

2008-8-5 01:13 1946 1 5 分类: MCU/ 嵌入式

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
********************************************************************************************************/

广告

文章评论 4条评论)

登录后参与讨论

412922521_325344472 2009-7-30 08:55

乱码 的地方 都是注释 不影响阅读.

lingshiying_632391066 2009-7-26 22:52

源码有乱码,而且没有注释!!!很难看懂

xnwxq_987443221 2008-8-5 23:17

可能是我的网速的问题,现在好多了!!!

xnwxq_987443221 2008-8-5 23:14

楼主的背景不是很号! 一片绿色地!!! 我建议修改一下!!!
相关推荐阅读
412922521_325344472 2009-11-15 00:44
通用按键消抖函数 -- 数据与过程分离
AUTO:  nicksean 不务正业          项目里经常处理按键消抖, 本来这个消抖的过程是与具体按下的键无关的, 可以前的代码总是在消抖的同时处理具体的按键值, 再加上长按 短按 组合...
412922521_325344472 2009-11-13 13:16
液晶ST7920串行显示
液晶显示128*64以7920为主控制器,采用3线制,比较经济简单。代码如下.....
412922521_325344472 2009-11-13 13:11
DS18B20 C51完整版
使用WINBOND W78C516单片机,11.0592MHZ晶振,用共阳LED数码管P0口输出段码,P1口扫描/*******************************************...
412922521_325344472 2009-11-12 13:19
74HC164驱动数码管
          74HC164是串行输入,并行输出接口器件,可用在单向的并行输出/并行地址锁存等. 74HC164因为价格便宜,容易使用特别适合使用在在需要用到数码管显示IO口又比较紧张的电子产品...
412922521_325344472 2009-11-10 20:13
at24c512多字节读写函数 欢迎测试
刚写的at24c512多字节读写函数,欢迎测试。/********************************************************************函数功能:EE...
412922521_325344472 2009-11-10 19:59
旋转编码器
    很好的旋转编码器的读码程序,设旋转编码器的输出波形如下                 ______        ______        ______        ______正转时:...
广告
我要评论
4
1
广告
关闭 热点推荐上一条 /2 下一条