#ifdef __USE_CMSIS
#include "LPC122x.h"
#endif
#include "driver_config.h"
#include "target_config.h"
#include "lcd.h"
#include "gpio.h"
#include "../src/main.h"
char DISP_BUFFER[16];
void lcd_delay(int msec){
volatile uint32_t done = msTicks + msec;
while (msTicks != done);
}
/*************************************************
* LCDSendNibble
* sends a 4-bit nibble to the display
*
* PARAMS:
* uint8_t nibble: The high nibble of this byte
* is sent to the display
*
* RETURNS:
* none
**************************************************/
void LCDSendNibble(uint32_t nibble){
uint8_t i=0;
uint8_t x=0;
lcd_delay(3);
//output upper nibble to the data port upper bits
LPC_GPIO0->OUT &= ~0x78;
LPC_GPIO0->OUT |= ((nibble & 0x0f) << LCD_PIN0);
//toggle the E line
LPC_GPIO0->SET = (1 << LCD_PINE);
/*__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();*/
LPC_GPIO0->CLR = (1 << LCD_PINE);
}
/**************************************************
* LCDSendByte
*
* Sends 8-bit byte to display
*
* PARAMS:
* uint8_t theByte the byte to send to the display
*
* RETURNS:
* none
*
***************************************************/
void LCDSendByte(uint8_t theByte){
//send high nibble
LCDSendNibble(theByte >> 4);
//send low nibble
LCDSendNibble(theByte);
}
/***************************************************
* LCDSendInstruction
* Sends an instruction to the display
*
* PARAMS:
* uint8_t command This byte is sent to the display as
* an instruction (RS low)
*
* RETURNS:
* none
*
****************************************************/
void LCDSendInstruction(uint8_t theInstruction) {
//RS Low for instructions
LPC_GPIO0->CLR |= (1 << LCD_PINRS);
//send the instructions
LCDSendByte(theInstruction);
}
void lcd_gotoxy(uint8_t x, uint8_t y) {
if (y==0){
LCDSendInstruction((1<<LCD_DDRAM)+LCD_LINE1+x);
}else if(y==1){
LCDSendInstruction((1<<LCD_DDRAM)+LCD_LINE2+x);
}else if(y==2){
LCDSendInstruction((1<<LCD_DDRAM)+LCD_LINE3+x);
}else{
LCDSendInstruction((1<<LCD_DDRAM)+LCD_LINE4+x);
}
}
/******************************************************
* LCD_send_character
* Sends a character to the display
*
* PARAMS:
* uint8_t nibble This byte is send to the display as
* a characters (RS high)
*
* RETURNS:
* none
*
*******************************************************/
void LCD_send_character(uint8_t theChar){
LPC_GPIO0->SET |= (1 << LCD_PINRS);
LCDSendByte(theChar);
}
void LCD_print(char *p){
while (*p != 0){
LCD_send_character(*p++);
}
}
void LCD_init(void){
uint8_t i;
//SET PINS TO OUTPUT
for(i=0; i < 4; i++){
GPIOSetDir(0,LCD_PIN0+i,1);
}
GPIOSetDir(0,LCD_PINE,1);
GPIOSetDir(0,LCD_PINRS,1);
GPIOSetValue(0,LCD_PINRS,0);
GPIOSetValue(0,LCD_PINE,0);
lcd_delay(16);
LCDSendNibble(0x03);
lcd_delay(5);
LCDSendNibble(0x03);
lcd_delay(100);
LCDSendNibble(0x03);
LCDSendNibble(0x02);
LCDSendByte(0x28);
LCDSendByte(0x0c);
LCDSendByte(0x06);
//LCDSendInstruction(LCD_FUNCTION_SET_4BIT);
//now set display to 4bit mode
//LCDSendNibble(0x02);
//now in 4 bit mode, finish init the display
/*LCDSendInstruction(LCD_FUNCTION_SET_4BIT);
LCDSendInstruction(LCD_DISPLAY_OFF);
LCDSendInstruction(LCD_DISPLAY_CLEAR);
LCDSendInstruction(LCD_ENTRY_MODE_SET);
LCDSendInstruction(LCD_DISPLAY_ON);
LCDSendByte(0x28);
LCDSendByte(0x0C);
LCDSendByte(0x06);
*/
}
|