---------------------------------------------------------------------------
lcd.c
------------------------------------------
#include <LPC214X.H>
#include "lcd.h"
void lowDelay()
{
int i=0,j=0;
for(i=0;i<3000;i++)
for(j=0;j<1000;j++);
}
void lowDelay1()
{
int i=0,j=0;
for(i=0;i<3000;i++)
for(j=0;j<10;j++);
}
void delay(int count)
{
int j=0,i=0;
for(j=0;j<count;j++)
{
/* At 60Mhz, the below loop introduces
delay of 1000 us */
for(i=0;i<350;i++);
}
}
void lowBeep()
{
IO1CLR |= (1<<25);
lowDelay1();
IO1SET |= (1<<25);
lowDelay();
}
void wait()
{
IO1CLR |= LCD_RS;
IO1SET |= LCD_RW|LCD_EN;
delay(1000);
while(IO0PIN & (1<<13));
IO1CLR |= LCD_EN;
}
void lcdWriteCmd(unsigned char cmd)
{
unsigned int tmp;
unsigned char mask = 0xf;
IO1CLR |= LCD_RS|LCD_RW;
delay(100);
tmp = (cmd>>4) & 0x0000000f;
IO0CLR |= mask<<10;
IO0SET |= tmp<<10;
IO1SET |= LCD_EN;
delay(10);
IO1CLR |= LCD_EN;
// wait();
delay(100);
tmp = (cmd) & 0x0000000f;
IO0CLR |= mask<<10;
IO0SET |= tmp<<10;
IO1SET |= LCD_EN;
delay(10);
IO1CLR |= LCD_EN;
// wait(); //
}
void lcdWriteDat(unsigned char cmd)
{
unsigned int tmp;
unsigned char mask = 0xf;
IO1SET |= LCD_RS;
IO1CLR |= LCD_RW;
delay(100);
tmp = (cmd>>4) & 0x0000000f;
IO0CLR |= mask<<10;
IO0SET |= tmp<<10;
IO1SET |= LCD_EN;
delay(10);
IO1CLR |= LCD_EN;
// wait();
delay(100);
tmp = (cmd) & 0x0000000f;
IO0CLR |= mask<<10;
IO0SET |= tmp<<10;
IO1SET |= LCD_EN;
delay(10);
IO1CLR |= LCD_EN;
// wait(); //
}
void strOut(char * data)
{
while(*data)
{
lcdWriteDat(* data);
data++;
}
}
void initLcd()
{
IO1DIR |= LCD_EN|LCD_RW|LCD_RS ;
IO0DIR |= D7_LCD|D6_LCD|D5_LCD|D4_LCD;
delay(1000);
lcdWriteCmd(0x28); /* 4-bit interface, two line, 5X7 dots. */
lcdWriteCmd(0x01); /* LCD clear */
lcdWriteCmd(0x02); /* cursor home */
lcdWriteCmd(0x06); /* cursor move direction */
lcdWriteCmd(0x0C); /* display on */
// lcdWriteCmd(0x0F);
}
--------------------------------------------------------------------------------------------------
lcd.h
-----------------------------------------------------------------------
#ifndef __LCD__H__
#define __LCD__H__
#define LCD_EN (1<<22)
#define LCD_RW (1<<23)
#define LCD_RS (1<<24)
#define D7_LCD (1<<13)
#define D6_LCD (1<<12)
#define D5_LCD (1<<11)
#define D4_LCD (1<<10)
void initLcd(void);
void lcdWriteCmd(unsigned char cmd);
void lcdWriteDat(unsigned char cmd);
void strOut(char *);
void lowDelay(void);
void lowDelay1(void);
void delay(int count);
void wait(void);
void lowBeep(void);
#endif
------------------------------------------------------------------------------------------------------
main.c
---------------------------
#include "lcd.h"
#include <LPC214X.H>
main()
{
initLcd();
delay(1000*10);
IO1DIR |= (1<<25);
lowBeep();
lcdWriteCmd(0x01);
delay(1000*10);
strOut("Hello LCD...");
delay(1000*100);
while(1)
{
// delay(1000*6);
// lcdWriteCmd(0x10);
// lcdWriteDat(0x2d);
//
// delay(1000*6);
// lcdWriteCmd(0x10);
// lcdWriteDat(0x7c);
//
// delay(1000*6);
// lcdWriteCmd(0x10);
// lcdWriteDat(0x2f);
}
}
------------------------------------------------------------------------
No comments:
Post a Comment