Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
39Activity
0 of .
Results for:
No results containing your search query
P. 1
interfacing lcd in 4bit mode with lpc2138

interfacing lcd in 4bit mode with lpc2138

Ratings: (0)|Views: 5,274|Likes:
Published by hypernuclide
keil code for interfacing lcd in 4bit mode with lpc2138
keil code for interfacing lcd in 4bit mode with lpc2138

More info:

Published by: hypernuclide on Dec 31, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

02/01/2013

pdf

text

original

Interfacing Lcd in 4bit mode
with LPC2138
Code:
#include<lpc21xx.h>
#define pin_rs 1<<24
/*lcd rs pin*/
#define pin_rw 1<<23
/*lcd rw pin*/
#define pin_en 1<<22
/*lcd en pin*/
#define pin_ctrl pin_rs|pin_rw|pin_en
/*lcd control pins*/
#define lcd_d4 1<<10

/*lcd data pins D4,D5,D6,D7*/
#define lcd_d5 1<<11
#define lcd_d6 1<<12
#define lcd_d7 1<<13
#define lcd_data lcd_d4|lcd_d5|lcd_d6|lcd_d7
#define lcd_rs(x) ((x)?(IOSET1=pin_rs):(IOCLR1=pin_rs)); /*lcd_rs(x) if x=1 will set the lcd_rs pin will clear if x=0*/
#define lcd_rw(x) ((x)?(IOSET1=pin_rw):(IOCLR1=pin_rw));
#define lcd_en(x) ((x)?(IOSET1=pin_en):(IOCLR1=pin_en));
#define data_in ((IOPIN0>>10)&(0x0F))

/*direction of the data pins as input*/
#define data_out(x) IOCLR0=lcd_data; IOSET0=(x & 0x0F)<<10;
/*direction of the data pins and control pins

as output*/
#define lcd_all_dir_out IODIR0 |= lcd_data ; IODIR1 |= pin_ctrl; /*setting as output for both data and control pins*/
#define lcd_dir_data_out IODIR0 |= lcd_data
#define lcd_dir_data_in IODIR0 &= ~(lcd_data)
#define delay_2n 4
static void delay(int);
static unsigned char busy_wait();

static void delay(int cnt)
{
cnt <<= delay_2n;
while(cnt--);
}static unsigned char busy_wait()

{
unsigned char status;
do
{lcd_dir_data_in;

delay(10);
lcd_rs(0);
delay(10);
lcd_rw(1);
delay(10);
lcd_en(1);
delay(10);
status= (data_in<<4)&(0xF0);
lcd_en(0);
delay(10);
lcd_en(1);
delay(10);
status |=data_in;
lcd_en(0);
delay(10);
lcd_dir_data_out;
delay(10);
}while(status & 0x80);

return (status);
}
void lcd_write_4bit(unsigned char c)

{
lcd_rw(0);
delay(10);
lcd_en(1);
delay(10);
data_out(c & 0x0F);
delay(10);
lcd_en(0);
delay(10);

}void lcd_cmd_write(unsigned char c)

{
busy_wait();
lcd_rs(0);
delay(10);
lcd_write_4bit(c>>4);
lcd_write_4bit(c);

}static void lcd_data_write(unsigned char c)

{
busy_wait();
lcd_rs(1);
delay(10);
lcd_write_4bit(c>>4);
lcd_write_4bit(c);

Activity (39)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads
Gudipati Mounika liked this
hle5457 liked this
Pham Huong liked this
sandeep2506 liked this
sivar22 liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->