00001 #ifndef __XLCD_H 00002 #define __XLCD_H 00003 00004 /* PIC18 XLCD peripheral routines. 00005 * 00006 * Notes: 00007 * - These libraries routines are written to support the 00008 * Hitachi HD44780 LCD controller. 00009 * - The user must define the following items: 00010 * - The LCD interface type (4- or 8-bits) 00011 * - If 4-bit mode 00012 * - whether using the upper or lower nibble 00013 * - The data port 00014 * - The tris register for data port 00015 * - The control signal ports and pins 00016 * - The control signal port tris and pins 00017 * - The user must provide three delay routines: 00018 * - DelayFor18TCY() provides a 18 Tcy delay 00019 * - DelayPORXLCD() provides at least 15ms delay 00020 * - DelayXLCD() provides at least 5ms delay 00021 */ 00022 00023 /* Interface type 8-bit or 4-bit 00024 * For 8-bit operation uncomment the #define BIT8 00025 */ 00026 #define BIT8 00027 00028 /* When in 4-bit interface define if the data is in the upper 00029 * or lower nibble. For lower nibble, comment the #define UPPER 00030 */ 00031 #define UPPER 00032 00033 /* DATA_PORT defines the port to which the LCD data lines are connected */ 00034 #define DATA_PORT PORTC 00035 #define TRIS_DATA_PORT TRISC 00036 00037 /* CTRL_PORT defines the port where the control lines are connected. 00038 * These are just samples, change to match your application. 00039 */ 00040 #define RS_PIN LATBbits.LATB5 /* PORT for RS */ 00041 #define TRIS_RS TRISBbits.TRISB5 /* TRIS for RS */ 00042 #define RW_PIN LATBbits.LATB6 /* PORT for RW */ 00043 #define TRIS_RW TRISBbits.TRISB6 /* TRIS for RW */ 00044 #define E_PIN LATBbits.LATB7 /* PORT for E */ 00045 #define TRIS_E TRISBbits.TRISB7 /* TRIS for E */ 00046 00047 /* Display ON/OFF Control defines */ 00048 #define DON 0b00001111 /* Display on */ 00049 #define DOFF 0b00001011 /* Display off */ 00050 #define CURSOR_ON 0b00001111 /* Cursor on */ 00051 #define CURSOR_OFF 0b00001101 /* Cursor off */ 00052 #define BLINK_ON 0b00001111 /* Cursor Blink */ 00053 #define BLINK_OFF 0b00001110 /* Cursor No Blink */ 00054 00055 /* Cursor or Display Shift defines */ 00056 #define SHIFT_CUR_LEFT 0b00010011 /* Cursor shifts to the left */ 00057 #define SHIFT_CUR_RIGHT 0b00010111 /* Cursor shifts to the right */ 00058 #define SHIFT_DISP_LEFT 0b00011011 /* Display shifts to the left */ 00059 #define SHIFT_DISP_RIGHT 0b00011111 /* Display shifts to the right */ 00060 00061 /* Function Set defines */ 00062 #define FOUR_BIT 0b00101111 /* 4-bit Interface */ 00063 #define EIGHT_BIT 0b00111111 /* 8-bit Interface */ 00064 #define LINE_5X7 0b00110011 /* 5x7 characters, single line */ 00065 #define LINE_5X10 0b00110111 /* 5x10 characters */ 00066 #define LINES_5X7 0b00111011 /* 5x7 characters, multiple line */ 00067 00068 #define PARAM_SCLASS auto 00069 #define MEM_MODEL far /* Change this to near for small memory model */ 00070 00071 /* OpenXLCD 00072 * Configures I/O pins for external LCD 00073 */ 00074 void OpenXLCD(PARAM_SCLASS unsigned char); 00075 00076 /* SetCGRamAddr 00077 * Sets the character generator address 00078 */ 00079 void SetCGRamAddr(PARAM_SCLASS unsigned char); 00080 00081 /* SetDDRamAddr 00082 * Sets the display data address 00083 */ 00084 void SetDDRamAddr(PARAM_SCLASS unsigned char); 00085 00086 /* BusyXLCD 00087 * Returns the busy status of the LCD 00088 */ 00089 unsigned char BusyXLCD(void); 00090 00091 /* ReadAddrXLCD 00092 * Reads the current address 00093 */ 00094 unsigned char ReadAddrXLCD(void); 00095 00096 /* ReadDataXLCD 00097 * Reads a byte of data 00098 */ 00099 char ReadDataXLCD(void); 00100 00101 /* WriteCmdXLCD 00102 * Writes a command to the LCD 00103 */ 00104 void WriteCmdXLCD(PARAM_SCLASS unsigned char); 00105 00106 /* WriteDataXLCD 00107 * Writes a data byte to the LCD 00108 */ 00109 void WriteDataXLCD(PARAM_SCLASS char); 00110 00111 /* putcXLCD 00112 * A putc is a write 00113 */ 00114 #define putcXLCD WriteDataXLCD 00115 00116 /* putsXLCD 00117 * Writes a string of characters to the LCD 00118 */ 00119 void putsXLCD(PARAM_SCLASS char *); 00120 00121 /* putrsXLCD 00122 * Writes a string of characters in ROM to the LCD 00123 */ 00124 void putrsXLCD(PARAM_SCLASS const MEM_MODEL rom char *); 00125 00126 /* User defines these routines according to the oscillator frequency */ 00127 extern void DelayFor18TCY(void); 00128 extern void DelayPORXLCD(void); 00129 extern void DelayXLCD(void); 00130 00131 #endif