1 | #ifndef __XLCD_H
|
2 | #define __XLCD_H
|
3 | #include "p18cxxx.h"
|
4 | /* PIC18 XLCD peripheral routines.
|
5 | *
|
6 | * Notes:
|
7 | * - These libraries routines are written to support the
|
8 | * Hitachi HD44780 LCD controller.
|
9 | * - The user must define the following items:
|
10 | * - The LCD interface type (4- or 8-bits)
|
11 | * - If 4-bit mode
|
12 | * - whether using the upper or lower nibble
|
13 | * - The data port
|
14 | * - The tris register for data port
|
15 | * - The control signal ports and pins
|
16 | * - The control signal port tris and pins
|
17 | * - The user must provide three delay routines:
|
18 | * - DelayFor18TCY() provides a 18 Tcy delay
|
19 | * - DelayPORXLCD() provides at least 15ms delay
|
20 | * - DelayXLCD() provides at least 5ms delay
|
21 | */
|
22 |
|
23 | /* Interface type 8-bit or 4-bit
|
24 | * For 8-bit operation uncomment the #define BIT8
|
25 | */
|
26 | /* #define BIT8 */
|
27 |
|
28 | /* When in 4-bit interface define if the data is in the upper
|
29 | * or lower nibble. For lower nibble, comment the #define UPPER
|
30 | */
|
31 | /* #define UPPER */
|
32 |
|
33 | /* DATA_PORT defines the port to which the LCD data lines are connected */
|
34 | #define DATA_PORT PORTD
|
35 | #define TRIS_DATA_PORT TRISD
|
36 |
|
37 | /* CTRL_PORT defines the port where the control lines are connected.
|
38 | * These are just samples, change to match your application.
|
39 | */
|
40 | #define RW_PIN LATEbits.LATE1 /* PORT for RW */
|
41 | #define TRIS_RW TRISEbits.TRISE1 /* TRIS for RW */
|
42 |
|
43 | #define RS_PIN LATEbits.LATE0 /* PORT for RS */
|
44 | #define TRIS_RS TRISEbits.TRISE0 /* TRIS for RS */
|
45 |
|
46 | #define E_PIN LATEbits.LATE2 /* PORT for D */
|
47 | #define TRIS_E TRISEbits.TRISE2 /* TRIS for E */
|
48 |
|
49 | /* Display ON/OFF Control defines */
|
50 | #define DON 0b00001111 /* Display on */
|
51 | #define DOFF 0b00001011 /* Display off */
|
52 | #define CURSOR_ON 0b00001111 /* Cursor on */
|
53 | #define CURSOR_OFF 0b00001101 /* Cursor off */
|
54 | #define BLINK_ON 0b00001111 /* Cursor Blink */
|
55 | #define BLINK_OFF 0b00001110 /* Cursor No Blink */
|
56 |
|
57 | /* Cursor or Display Shift defines */
|
58 | #define SHIFT_CUR_LEFT 0b00000100 /* Cursor shifts to the left */
|
59 | #define SHIFT_CUR_RIGHT 0b00000101 /* Cursor shifts to the right */
|
60 | #define SHIFT_DISP_LEFT 0b00000110 /* Display shifts to the left */
|
61 | #define SHIFT_DISP_RIGHT 0b00000111 /* Display shifts to the right */
|
62 |
|
63 | /* Function Set defines */
|
64 | #define FOUR_BIT 0b00101100 /* 4-bit Interface */
|
65 | #define EIGHT_BIT 0b00111100 /* 8-bit Interface */
|
66 | #define LINE_5X7 0b00110000 /* 5x7 characters, single line */
|
67 | #define LINE_5X10 0b00110100 /* 5x10 characters */
|
68 | #define LINES_5X7 0b00111000 /* 5x7 characters, multiple line */
|
69 |
|
70 | #ifdef _OMNI_CODE_
|
71 | #define PARAM_SCLASS
|
72 | #else
|
73 | #define PARAM_SCLASS auto
|
74 | #endif
|
75 |
|
76 | #ifndef MEM_MODEL
|
77 | #ifdef _OMNI_CODE_
|
78 | #define MEM_MODEL
|
79 | #else
|
80 | #define MEM_MODEL far /* Change this to near for small memory model */
|
81 | #endif
|
82 | #endif
|
83 |
|
84 | /* OpenXLCD
|
85 | * Configures I/O pins for external LCD
|
86 | */
|
87 | void OpenXLCD(PARAM_SCLASS unsigned char);
|
88 |
|
89 | /* SetCGRamAddr
|
90 | * Sets the character generator address
|
91 | */
|
92 | void SetCGRamAddr(PARAM_SCLASS unsigned char);
|
93 |
|
94 | /* SetDDRamAddr
|
95 | * Sets the display data address
|
96 | */
|
97 | void SetDDRamAddr(PARAM_SCLASS unsigned char);
|
98 |
|
99 | /* BusyXLCD
|
100 | * Returns the busy status of the LCD
|
101 | */
|
102 | unsigned char BusyXLCD(void);
|
103 |
|
104 | /* ReadAddrXLCD
|
105 | * Reads the current address
|
106 | */
|
107 | unsigned char ReadAddrXLCD(void);
|
108 |
|
109 | /* ReadDataXLCD
|
110 | * Reads a byte of data
|
111 | */
|
112 | char ReadDataXLCD(void);
|
113 |
|
114 | /* WriteCmdXLCD
|
115 | * Writes a command to the LCD
|
116 | */
|
117 | void WriteCmdXLCD(PARAM_SCLASS unsigned char);
|
118 |
|
119 | /* WriteDataXLCD
|
120 | * Writes a data byte to the LCD
|
121 | */
|
122 | void WriteDataXLCD(PARAM_SCLASS char);
|
123 |
|
124 | /* putcXLCD
|
125 | * A putc is a write
|
126 | */
|
127 | #define putcXLCD WriteDataXLCD
|
128 |
|
129 | /* putsXLCD
|
130 | * Writes a string of characters to the LCD
|
131 | */
|
132 | void putsXLCD(PARAM_SCLASS char *);
|
133 |
|
134 | /* putrsXLCD
|
135 | * Writes a string of characters in ROM to the LCD
|
136 | */
|
137 | void putrsXLCD(const char *);
|
138 |
|
139 | /* User defines these routines according to the oscillator frequency */
|
140 | extern void DelayFor18TCY(void);
|
141 | extern void DelayPORXLCD(void);
|
142 | extern void DelayXLCD(void);
|
143 |
|
144 | #endif
|