PIC24 Support Libraries
esos_lcd44780.h
Go to the documentation of this file.
1 /*
2  * "Copyright (c) 2013 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
3  * All rights reserved.
4  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
5  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
6  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation for any purpose, without fee, and without written agreement is
10  * hereby granted, provided that the above copyright notice, the following
11  * two paragraphs and the authors appear in all copies of this software.
12  *
13  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
15  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
16  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17  *
18  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
19  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
23  *
24  * Please maintain this header in its entirety when copying/modifying
25  * these files.
26  *
27  *
28  */
29 
30  /**
31  * \addtogroup ESOS_Task_LCD_Service
32  * @{
33  */
34 
35  /** \file
36  * This file contains macros, prototypes, and definitions for
37  * LCD services for ESOS tasks.
38  *
39  */
40 
41 #ifndef ESOS_LCD_H
42 #define ESOS_LCD_H
43 
44 /* I N C L U D E S **********************************************************/
45 #include <esos.h>
46 
47 /* D E F I N E S ************************************************************/
48 #define ESOS_TASK_WAIT_ON_LCD44780_REFRESH() ESOS_TASK_WAIT_UNTIL(esos_lcd44780_isCurrent())
49 
50 #define ESOS_LCD44780_CMD_CLEAR_DISPLAY 0b00000001
51 #define ESOS_LCD44780_CMD_RETURN_HOME 0b00000010
52 #define ESOS_LCD44780_CMD_ENTRY_MODE_SET 0b00000100
53 #define ESOS_LCD44780_CMD_ENTRY_MODE_SET_INC 0b00000010
54 #define ESOS_LCD44780_CMD_ENTRY_MODE_SET_SHIFT 0b00000001
55 #define ESOS_LCD44780_CMD_DISPLAY_ON_OFF 0b00001000
56 #define ESOS_LCD44780_CMD_DISPLAY_ON_OFF_DISP 0b00000100
57 #define ESOS_LCD44780_CMD_DISPLAY_ON_OFF_CUR 0b00000010
58 #define ESOS_LCD44780_CMD_DISPLAY_ON_OFF_BLINK 0b00000001
59 #define ESOS_LCD44780_CMD_CUR_DISP_SHIFT 0b00010000
60 #define ESOS_LCD44780_CMD_FUNCTION_SET 0b00100000
61 #define ESOS_LCD44780_CMD_SET_CGRAM_ADDR 0b01000000
62 #define ESOS_LCD44780_CMD_SET_DDRAM_ADDR 0b10000000
63 #define ESOS_LCD44780_MEM_WIDTH 40
64 #define ESOS_LCD44780_MEM_HEIGHT 2
65 #define ESOS_LCD44780_NUM_CUSTOM_CHARS 8
66 
67 #define LCD44780_READ 1
68 #define LCD44780_WRITE 0
69 
70 #define ESOS_TASK_WAIT_LCD44780_WRITE_COMMAND(u8_cmd) do { \
71  ESOS_ALLOCATE_CHILD_TASK(th_lcd44780_child); \
72  ESOS_TASK_SPAWN_AND_WAIT( th_lcd44780_child, __esos_lcd44780_write_u8, u8_cmd, FALSE, TRUE ); \
73 } while(0)
74 
75 #define ESOS_TASK_WAIT_LCD44780_WRITE_COMMAND_NOWAIT(u8_cmd) do { \
76  ESOS_ALLOCATE_CHILD_TASK(th_lcd44780_child); \
77  ESOS_TASK_SPAWN_AND_WAIT( th_lcd44780_child, __esos_lcd44780_write_u8, u8_cmd, FALSE, TRUE ); \
78 } while(0)
79 
80 #define ESOS_TASK_WAIT_LCD44780_SET_CG_ADDRESS(u8_addr) \
81  ESOS_TASK_WAIT_LCD44780_WRITE_COMMAND( u8_addr | ESOS_LCD44780_CMD_SET_CGRAM_ADDR )
82 
83 #define ESOS_TASK_WAIT_LCD44780_SET_DATA_ADDRESS(u8_addr) \
84  ESOS_TASK_WAIT_LCD44780_WRITE_COMMAND( u8_addr | ESOS_LCD44780_CMD_SET_DDRAM_ADDR )
85 
86 #define ESOS_TASK_WAIT_LCD44780_READ_ADDRESS(u8_addr) do { \
87  ESOS_ALLOCATE_CHILD_TASK(th_lcd44780_child); \
88  ESOS_TASK_SPAWN_AND_WAIT( th_lcd44780_child, __esos_lcd44780_read_u8, u8_addr, FALSE, TRUE ); \
89 } while(0)
90 
91 #define ESOS_TASK_WAIT_LCD44780_WRITE_DATA(u8_data) do { \
92  ESOS_ALLOCATE_CHILD_TASK(th_lcd44780_child); \
93  ESOS_TASK_SPAWN_AND_WAIT( th_lcd44780_child, __esos_lcd44780_write_u8, u8_data, TRUE, TRUE ); \
94 } while(0)
95 
96 #define ESOS_TASK_WAIT_LCD44780_READ_DATA(u8_addr) do { \
97  ESOS_ALLOCATE_CHILD_TASK(th_lcd44780_child); \
98  ESOS_TASK_SPAWN_AND_WAIT( th_lcd44780_child, __esos_lcd44780_read_u8, u8_addr, TRUE, TRUE ); \
99 } while(0)
100 
101 /* S T R U C T U R E S ******************************************************/
102 typedef struct {
103  uint8_t au8_data[8];
104 } esos_lcd44780_char_t;
105 
106 // allocate space for the child task used by the LCD character module
107 // service. Only one child should ever be active at a time.
108 static ESOS_TASK_HANDLE th_lcd44780_child;
109 
110 /* P U B L I C P R O T O T Y P E S *****************************************/
111 void esos_lcd44780_configDisplay( void );
112 void esos_lcd44780_init( void );
113 void esos_lcd44780_clearScreen( void );
114 void esos_lcd44780_setCursorHome( void );
115 void esos_lcd44780_setCursor( uint8_t u8_row, uint8_t u8_column );
116 void esos_lcd44780_writeChar( uint8_t u8_row, uint8_t u8_column, uint8_t u8_data );
117 uint8_t esos_lcd44780_getChar( uint8_t u8_row, uint8_t u8_column );
118 void esos_lcd44780_writeBuffer( uint8_t u8_row, uint8_t u8_column, uint8_t *pu8_data, uint8_t u8_bufflen );
119 void esos_lcd44780_getBuffer( uint8_t u8_row, uint8_t u8_column, uint8_t *pu8_data, uint8_t u8_bufflen );
120 void esos_lcd44780_writeString( uint8_t u8_row, uint8_t u8_column, char *psz_data );
121 void esos_lcd44780_setCursorDisplay( BOOL u8_state );
122 BOOL esos_lcd44780_getCursorDisplay( void );
123 void esos_lcd44780_setCursorBlink( BOOL u8_state );
124 BOOL esos_lcd44780_getCursorBlink( void );
125 void esos_lcd44780_setDisplayVisible( BOOL u8_state );
126 BOOL esos_lcd44780_getDisplayVisible( void );
127 void esos_lcd44780_setCustomChar( uint8_t u8_charSlot, uint8_t *pu8_charData );
128 void esos_lcd44780_getCustomChar( uint8_t u8_charSlot, uint8_t *pu8_charData );
129 BOOL esos_lcd44780_isCurrent( void );
130 
131 ESOS_USER_TASK( __esos_lcd44780_service );
132 ESOS_CHILD_TASK( __esos_task_wait_lcd44780_while_busy );
133 ESOS_CHILD_TASK(__esos_lcd44780_write_u8, uint8_t u8_data, BOOL b_isData, BOOL b_useBusyFlag);
134 ESOS_CHILD_TASK(__esos_lcd44780_read_u8, uint8_t *pu8_data, BOOL b_isData, BOOL b_useBusyFlag);
135 
136 
137 #endif
#define ESOS_CHILD_TASK(taskname,...)
Definition: esos_task.h:247
BOOL
Definition: all_generic.h:402
ESOS_USER_TASK(CANFactory)
Definition: esos_ecan.c:70
unsigned char uint8_t
An abbreviation for an 8-bit unsigned integer.
Definition: dataXferImpl.h:194