/*
*********************************************************************************************************
* Embedded Systems Building Blocks
* Complete and Ready-to-Use Modules in C
*
* LCD Display Module Driver
*
* (c) Copyright 1999, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
* Filename : LCD.C
* Programmer : Jean J. Labrosse
*********************************************************************************************************
* DESCRIPTION
*
*
* This module provides an interface to an alphanumeric display module.
*
* The current version of this driver supports any alphanumeric LCD module based on the:
* Hitachi HD44780 DOT MATRIX LCD controller.
*
* This driver supports LCD displays having the following configuration:
*
* 1 line x 16 characters 2 lines x 16 characters 4 lines x 16 characters
* 1 line x 20 characters 2 lines x 20 characters 4 lines x 20 characters
* 1 line x 24 characters 2 lines x 24 characters
* 1 line x 40 characters 2 lines x 40 characters
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "ucos_ii.h"
#include "LCD.h"
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/* ---------------------- HD44780 COMMANDS -------------------- */
#define DISP_CMD_CLS 0x01 /* Clr display : clears display and returns cursor home */
#define DISP_CMD_FNCT 0x3B /* Function Set: Set 8 bit data length, 1/16 duty, 5x8 dots */
#define DISP_CMD_MODE 0x06 /* Entry mode : Inc. display data address when writing */
#define DISP_CMD_ON_OFF 0x0C /* Disp ON/OFF : Display ON, cursor OFF and no BLINK character */
/*
*********************************************************************************************************
* LOCAL VARIABLES
*********************************************************************************************************
*/
static INT8U DispMaxCols; /* Maximum number of columns (i.e. characters per line) */
static INT8U DispMaxRows; /* Maximum number of rows for the display */
static OS_EVENT *DispSem; /* Semaphore used to access display functions */
__flash INT8U DispBar1[][8] = {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10};
__flash INT8U DispBar2[][8] = {0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18};
__flash INT8U DispBar3[][8] = {0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C};
__flash INT8U DispBar4[][8] = {0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E};
__flash INT8U DispBar5[][8] = {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F};
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void LCDGotoXY(INT8U Row, INT8U Col);
/*$PAGE*/
/*
*********************************************************************************************************
* DISPLAY A CHARACTER
*
* Description : This function is used to display a single character on the display device
* Arguments : 'row' is the row position of the cursor in the LCD Display
* 'row' can be a value from 0 to 'DispMaxRows - 1'
* 'col' is the column position of the cursor in the LCD Display
* 'col' can be a value from 0 to 'DispMaxCols - 1'
* 'c' is the character to write to the display at the current ROW/COLUMN position.
* Returns : none
*********************************************************************************************************
*/
void LCDSendChar (INT8U Row, INT8U Col, char c)
{
INT8U err;
if (Row < DispMaxRows && Col < DispMaxCols) {
OSSemPend(DispSem, 0, &err); /* Obtain exclusive access to the display */
LCDGotoXY(Row, Col); /* Position cursor at ROW/COL */
LCDWriteData(c,DATA); /* Send character to display */
OSSemPost(DispSem); /* Release access to display */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* CLEAR LINE
*
* Description : This function clears one line on the LCD display and positions the cursor at the
* beginning of the line.
* Arguments : 'line' is the line number to clear and can take the value
* 0 to 'DispMaxRows - 1'
* Returns : none
*********************************************************************************************************
*/
void LCDClearLine (INT8U Line)
{
INT8U i;
INT8U err;
if (Line < DispMaxRows) {
OSSemPend(DispSem, 0, &err); /* Obtain exclusive access to the display */
LCDGotoXY(Line, 0); /* Position cursor at begin of the line to clear */
for (i = 0; i < DispMaxCols; i++) { /* Write ' ' into all column positions of that line */
LCDWriteData(' ',DATA); /* Write an ASCII space at current cursor position */
}
LCDGotoXY(Line, 0); /* Position cursor at begin of the line to clear */
OSSemPost(DispSem); /* Release access to display */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* CLEAR THE SCREEN
*
* Description : This function clears the display
* Arguments : none
* Returns : none
*********************************************************************************************************
*/
void LCDClearScreen (void)
{
INT8U err;
OSSemPend(DispSem, 0, &err); /* Obtain exclusive access to the display */
LCDWriteData(DISP_CMD_CLS,CMD); /* Send command to LCD display to clear the display */
OSTimeDly(2); /* Delay at least 2 mS (2 ticks ensures at least this much) */
OSSemPost(DispSem); /* Release access to display */
}
/*$PAGE*/
/*
*********************************************************************************************************
* POSITION THE CURSOR (Internal)
*
* Description : This function positions the cursor into the LCD buffer
* Arguments : 'row' is the row position of the cursor in the LCD Display
* 'row' can be a value from