Code:
/* PIC18 XLCD peripheral routines.
*
* Notes:
* - These libraries routines are written to support the
* Hitachi HD44780 LCD controller.
* - The user must define the following items:
* - The LCD interface type (4- or 8-bits)
* - If 4-bit mode
* - whether using the upper or lower nibble
* - The data port
* - The tris register for data port
* - The control signal ports and pins
* - The control signal port tris and pins
* - The user must provide three delay routines:
* - DelayFor18TCY() provides a 18 Tcy delay
* - DelayPORXLCD() provides at least 15ms delay
* - DelayXLCD() provides at least 5ms delay
*/
/* Interface type 8-bit or 4-bit
* For 8-bit operation uncomment the #define BIT8
*/
/* #define BIT8 */
/* When in 4-bit interface define if the data is in the upper
* or lower nibble. For lower nibble, comment the #define UPPER
*/
#define UPPER
/* DATA_PORT defines the port to which the LCD data lines are connected */
#define DATA_PORT PORTD
#define TRIS_DATA_PORT TRISD
/* CTRL_PORT defines the port where the control lines are connected.
* These are just samples, change to match your application.
*/
#define RW_PIN LATDbits.LATD2 /* PORT for RW */
#define TRIS_RW TRISDbits.TRISD2 /* TRIS for RW */
#define RS_PIN LATDbits.LATD1 /* PORT for RS */
#define TRIS_RS TRISDbits.TRISD1 /* TRIS for RS */
#define E_PIN LATDbits.LATD3 /* PORT for D */
#define TRIS_E TRISDbits.TRISD3 /* TRIS for E */
/* PIC18 XLCD peripheral routines.
*
* Notes:
* - These libraries routines are written to support the
* Hitachi HD44780 LCD controller.
* - The user must define the following items:
* - The LCD interface type (4- or 8-bits)
* - If 4-bit mode
* - whether using the upper or lower nibble
* - The data port
* - The tris register for data port
* - The control signal ports and pins
* - The control signal port tris and pins
* - The user must provide three delay routines:
* - DelayFor18TCY() provides a 18 Tcy delay
* - DelayPORXLCD() provides at least 15ms delay
* - DelayXLCD() provides at least 5ms delay
*/
/* Interface type 8-bit or 4-bit
* For 8-bit operation uncomment the #define BIT8
*/
/* #define BIT8 */
/* When in 4-bit interface define if the data is in the upper
* or lower nibble. For lower nibble, comment the #define UPPER
*/
#define UPPER
/* DATA_PORT defines the port to which the LCD data lines are connected */
#define DATA_PORT PORTD
#define TRIS_DATA_PORT TRISD
/* CTRL_PORT defines the port where the control lines are connected.
* These are just samples, change to match your application.
*/
#define RW_PIN LATDbits.LATD2 /* PORT for RW */
#define TRIS_RW TRISDbits.TRISD2 /* TRIS for RW */
#define RS_PIN LATDbits.LATD1 /* PORT for RS */
#define TRIS_RS TRISDbits.TRISD1 /* TRIS for RS */
#define E_PIN LATDbits.LATD3 /* PORT for D */
#define TRIS_E TRISDbits.TRISD3 /* TRIS for E */