You are on page 1of 7

LCD 4BIT TEST ON MCB23000 .

C FILE

#include <LPC23xx.H>
#include "LCD.h"

void delay()
{
int i,j;
for (i=0;i<=500;i++)
for (j=0;j<=5000;j++);
}

int main (void)

{
int i;
lcd_init();
lcd_clear();
lcd_write_cmd(0x80);
lcd_print (" hello");
lcd_write_cmd(0xC0);
lcd_print (" hoe are u ");

/* while(1)
{

delay();
lcd_write_cmd(0x1C);

}
*/
return 0;
}

LCD 4BIT .C FILE

/*********************************************************************
*********/
/* LCD.c: Functions for 2 line 16 character Text LCD, with 4-bit
interface */
/*********************************************************************
*********/

#include <LPC23xx.H> /* LPC23xx definitions


*/

/*********************** Hardware specific configuration


**********************/
/*------------------------- Text LCD size definitions ----------------
--------*/

#define LineLen 16 /* Width (in characters)


*/
#define NumLines 2 /* Hight (in lines)
*/

/*-------------------- LCD interface hardware definitions ------------


--------*/

/* PINS:
- DB4 = P1.24
- DB5 = P1.25
- DB6 = P1.26
- DB7 = P1.27
- E = P1.31
- RW = P1.29
- RS = P1.28
*/

#define PIN_E 0x80000000


#define PIN_RW 0x20000000
#define PIN_RS 0x10000000
#define PINS_CTRL 0xB0000000
#define PINS_DATA 0x0F000000

/* pin E setting to 0 or 1
*/
#define LCD_E(x) ((x) ? (IOSET1 = PIN_E) : (IOCLR1 =
PIN_E) );

/* pin RW setting to 0 or 1
*/
#define LCD_RW(x) ((x) ? (IOSET1 = PIN_RW) : (IOCLR1 =
PIN_RW));

/* pin RS setting to 0 or 1
*/
#define LCD_RS(x) ((x) ? (IOSET1 = PIN_RS) : (IOCLR1 =
PIN_RS));

/* Reading DATA pins


*/
#define LCD_DATA_IN ((IOPIN1 >> 24) & 0xF)

/* Writing value to DATA pins


*/
#define LCD_DATA_OUT(x) IOCLR1 = PINS_DATA; IOSET1 = (x & 0xF)
<< 24;

/* Setting all pins to output mode


*/
#define LCD_ALL_DIR_OUT IODIR1 |= PINS_CTRL | PINS_DATA;

/* Setting DATA pins to input mode


*/
#define LCD_DATA_DIR_IN IODIR1 &= ~PINS_DATA;

/* Setting DATA pins to output mode


*/
#define LCD_DATA_DIR_OUT IODIR1 |= PINS_DATA;

/*********************************************************************
*********/

/************************ Global function definitions


*************************/

/*********************************************************************
**********
* Delay in while loop cycles
*
* Parameter: cnt: number of while cycles to delay
*
* Return:
*
**********************************************************************
*********/

static void delay (int cnt)


{

while (cnt--);
}

/*********************************************************************
**********
* Write 4-bits to LCD controller
*
* Parameter: c: command to be written
*
* Return:
*
**********************************************************************
*********/

void lcd_write_4bit (unsigned char c)


{
LCD_RW(0)
LCD_E(1)
LCD_DATA_OUT(c&0x0F)
delay(10);
LCD_E(0)
delay(10);
}

/*********************************************************************
**********
* Write command to LCD controller
*
* Parameter: c: command to be written
*
* Return:
*
**********************************************************************
*********/

void lcd_write_cmd (unsigned char c)


{
// wait_while_busy();
delay(4100);
LCD_RS(0)
lcd_write_4bit (c>>4);
lcd_write_4bit (c);
}

/*********************************************************************
**********
* Write data to LCD controller
*
* Parameter: c: data to be written
*
* Return:
*
**********************************************************************
*********/

static void lcd_write_data (unsigned char c)


{
// wait_while_busy();
delay(4100);
LCD_RS(1)
lcd_write_4bit (c>>4);
lcd_write_4bit (c);
}

/*********************************************************************
**********
* Print Character to current cursor position
*
* Parameter: c: character to be printed
*
* Return:
*
**********************************************************************
*********/

void lcd_putchar (char c)


{
lcd_write_data (c);
}

/*********************************************************************
**********
* Initialize the LCD controller
*
* Parameter:
*
* Return:
*
**********************************************************************
*********/

void lcd_init (void)


{
int i;

/* Set all pins for LCD as outputs


*/
LCD_ALL_DIR_OUT
delay (15000);
LCD_RS(0)
lcd_write_4bit (0x3); /* Select 4-bit interface
*/
delay (4100);
lcd_write_4bit (0x3);
delay (100);
lcd_write_4bit (0x3);
lcd_write_4bit (0x2);
lcd_write_cmd (0x28); /* 2 lines, 5x8 character
matrix */
lcd_write_cmd (0x0C); /* Display
ctrl:Disp=ON,Curs/Blnk=OFF */
lcd_write_cmd (0x06); /* Entry mode: Move right, no
shift */
lcd_write_cmd(0x80); /* Set DDRAM address counter
to 0 */
}

/*********************************************************************
**********
* Clear the LCD display
*
* Parameter:
*
* Return:
*
**********************************************************************
*********/

void lcd_clear (void)


{
lcd_write_cmd(0x01); /* Display clear
*/
lcd_write_cmd (0x80);
}

/*********************************************************************
**********
* Print sting to LCD display
*
* Parameter: string: pointer to output string
*
* Return:
*
**********************************************************************
*********/

void lcd_print (unsigned char const *string)


{
while (*string) {
lcd_putchar (*string++);
}
}

/*********************************************************************
*********/
LCD.H FILE

/*********************************************************************
*********/
/* LCD.h Text LCD function prototypes
*/
/*********************************************************************
*********/

extern void lcd_init (void);


extern void lcd_clear (void);
extern void lcd_putchar (char c);
extern void lcd_print (unsigned char const *string);

You might also like