include "LPC13xx.h"
#include "gpio.h"
#define LCD_MAX_COL 16
#define LCD_MAX_ROW 2
#define LCD_BASEADDR0x8000
#define LCD_DELAY 500
#define LED_ONGPIOSetValue(0,7,1)
#define LED_OFFGPIOSetValue(0,7,0)
#define LCD_ENABLE()GPIOSetValue(2,8,1) //Port P2.8 = 1
#define LCD_DISABLE()GPIOSetValue(2,8,0) //Port P2.8 = 0
#define LCD_RWON() GPIOSetValue(2,9,1) //Port P2.9 = 1
#define LCD_RWOFF() GPIOSetValue(2,9,0) //Port P2.9 = 0
#define LCD_RSON() GPIOSetValue(2,10,1) //Port P2.10 = 1
#define LCD_RSOFF() GPIOSetValue(2,10,0) //Port P2.10 = 0
#define LCD_DATA(Data)LPC_GPIO[2]->MASKED_ACCESS[(0x00FF)] = Data //P2.0-7 = Data
#define LCD_SET_SYSTEM 0x20 //
#define LCD_SYS_8BIT 0x10 //
#define LCD_SYS_2LINE 0x08 //
#define LCD_DOT_5_11 0x04
#define LCD_SET_DISPLAY 0x08 //
#define LCD_DISP_DISPLAY_ON 0x04 //
#define LCD_CURSOR_HOME 0x02
#define LCD_CLEAR 0x01
//Function prototype
char lcd_ready(void); // Check for LCD to be ready
char lcd_init(void); // LCD Init
void lcd_gotoxy(uint8_t x, uint8_t y);// Output character string in current Cursor.
char* lcd_puts(uint8_t* str); // Output character stream in current Cursor.
void evb_set_lcd_text(uint8_t row, uint8_t* lcd);
void lcd_busy(void);
void lcd_command(uint8_t Value);
void Delay (uint32_t dlyTicks);
volatile uint32_t msTicks; // counts 1ms timeTicks
//*******************************************
// system stick interrupt handler
void SysTick_Handler(void) {
msTicks++; // increment counter necessary in Delay()
}
//*******************************************
// delays number of tick Systicks (happens every 1 ms)
void Delay (uint32_t dlyTicks) {
uint32_t curTicks;
curTicks = msTicks;
while ((msTicks - curTicks) < dlyTicks);
}
//*******************************************
void write_byte (uint8_t Value)
{
uint8_t upperNibble = Value >> 4;
uint8_t lowerNibble = Value & 0x0F;
LCD_DATA(upperNibble);
LCD_DISABLE();
Delay(1);
LCD_ENABLE();
Delay(1);
LCD_DISABLE();
Delay(1);
LCD_DATA(lowerNibble);
LCD_DISABLE();
Delay(1);
LCD_ENABLE();
Delay(1);
LCD_DISABLE();
Delay(1);
}
void lcd_command(uint8_t cmd)
{
LCD_RSOFF();
Delay(3);
write_byte(cmd);
Delay(3);
}
//*******************************************
void lcd_data(uint8_t ch)
{
LCD_RSON();
Delay(3);
write_byte(ch);
Delay(3);
}
//*******************************************
char lcd_init(void)
{LCD_RWOFF();
//LCD_DISABLE();
//LCD_RSOFF();
Delay(20);
write_byte(0x30);
Delay(10);
write_byte(0x30);
Delay(5);
write_byte(0x30);
Delay(5);
write_byte(0x20);
Delay(5);
lcd_command(0x28);
Delay(100);
lcd_command(0x0C);
Delay(100);
lcd_command(0x08);
Delay(100);
lcd_command(LCD_CLEAR);
Delay(100);
lcd_command(LCD_CURSOR_HOME);
return 1;
}
//*******************************************
void lcd_gotoxy( uint8_t x, uint8_t y )
{
switch(y)
{
case 0 : lcd_command(0x80 + x); break;
case 1 : lcd_command(0xC0 + x); break;
case 2 : lcd_command(0x94 + x); break;
case 3 : lcd_command(0xD4 + x); break;
}
}
//*******************************************
char * lcd_puts(uint8_t * str)
{
uint8_t i;
for (i=0; str != '\0'; i++){
// wait_1ms(4);
lcd_data(str);
}
return str;
}
//*******************************************
void evb_set_lcd_text(uint8_t row, uint8_t * lcd)
{
lcd_gotoxy(0,row);
lcd_puts((char*)lcd);
}
//*********************************************
// Main Program
int main (void)
{
GPIOInit();
LPC_GPIO[2]->DIR = 0b011111111111;
GPIOSetDir( 0, 7, 1 );
LED_OFF;
LCD_RWOFF();
if (SysTick_Config(SystemCoreClock / 1000)) {
while (1);
}
if ( !(SysTick->CTRL & SysTick_CTRL_CLKSOURCE_Msk) )
{LPC_SYSCON->SYSTICKCLKDIV = 0x08;}
LED_ON;
lcd_init();
LED_OFF;
lcd_command(LCD_CLEAR);
evb_set_lcd_text(1,"abcdef");
lcd_gotoxy(4,1);
lcd_puts("abc123");
} |