Anda di halaman 1dari 2

/*

***********************************************************************************
**********************
* (c) Copyright 03/09/2017, Ankush P. Chavhan, Pune, India
* All Rights Reserved
* File : APCLCD.H
* Descripton : This is header file for 16x2 LCD interfacing with ARM7.
* D0-D7: P1.19-P1.25, RS=P1.16, EN=P1.17 RW=Connected to ground
* Cotains Lcd_Ini, Lcd_Cmd, Lcd_Data and Lcd_Msg functions give
following functionality
* Lcd_Ini : Initialize the LCD
* Lcd_Cmd : To send command to LCD
* Lcd_Data: To send 8 bit data to be displayed to the LCD
* Lcd_Msg : To send msg string to be displayed on lcd with row and
column location
* By : Ankush P. Chavhan
* E&TC Engineer,Pune
* Date : 03/09/2017
* Tested on Proteus 8.1 with lpc2138.
* Have Fun!!!
***********************************************************************************
**********************
*/

#include <LPC22xx.h>
#define rs 0x00010000
#define en 0x00020000

void MDelay(unsigned int apc);


void Lcd_Cmd(unsigned char apc);
void Lcd_Data(unsigned char apc);
void Lcd_Ini(void);
void Lcd_Msg(unsigned char row,unsigned char col,const unsigned char *msg);

void MDelay(unsigned int apc)


{
unsigned int i,j;
for(i=0;i<apc;i++)
for(j=0;j<1275;j++);
}

void Lcd_Cmd(unsigned char apc)


{
IOSET1=apc<<18;
IOCLR1=~apc<<18;
IOCLR1=rs;
IOSET1=en;
MDelay(1);
IOCLR1=en;
}

void Lcd_Data(unsigned char apc)


{
IOSET1=apc<<18;
IOCLR1=~apc<<18;
IOSET1=rs;
IOSET1=en;
MDelay(1);
IOCLR1=en;
}

void Lcd_Ini(void)
{
IODIR1 |= 0X03FF0000;
Lcd_Cmd(0x38);
Lcd_Cmd(0x0C);
Lcd_Cmd(0x01);
Lcd_Cmd(0x06);
}

void Lcd_Msg(unsigned char row,unsigned char col,const unsigned char *msg)


{
if(row==0x01)
row=0x80;
else
row=0xc0;
MDelay(10);
Lcd_Cmd(row|col);
while(*msg)
{
MDelay(10);
Lcd_Data(*msg);
msg++;
}
}

Anda mungkin juga menyukai