1 | #include "LPC11xx.h" /* LPC11xx definitions */
|
2 | #include "timer16.h"
|
3 | #include "clkconfig.h"
|
4 | #include "gpio.h"
|
5 |
|
6 | #include <cr_section_macros.h>
|
7 | #include <NXP/crp.h>
|
8 |
|
9 | // Variable to store CRP value in. Will be placed automatically
|
10 | // by the linker when "Enable Code Read Protect" selected.
|
11 | // See crp.h header for more information
|
12 | __CRP const unsigned int CRP_WORD = CRP_NO_CRP;
|
13 |
|
14 | #define LCD_PORT 2 // Port for lcd
|
15 | #define LCD_RS 0
|
16 | #define LCD_RW 1
|
17 | #define LCD_E 2
|
18 | #define LCD_DB0 3
|
19 | #define LCD_DB1 4
|
20 | #define LCD_DB2 5
|
21 | #define LCD_DB3 6
|
22 | #define LCD_DB4 7
|
23 | #define LCD_DB5 8
|
24 | #define LCD_DB6 9
|
25 | #define LCD_DB7 10
|
26 | #define LCD_ENABLE_TIME 100
|
27 |
|
28 | extern volatile uint32_t timer16_0_counter;
|
29 |
|
30 | void pauseMillis(uint16_t millis);
|
31 | void initOutputs(void);
|
32 |
|
33 | void LCD_send(uint8_t valRS, uint8_t valRW, uint8_t valDB7, uint8_t valDB6, uint8_t valDB5, uint8_t valDB4, uint8_t valDB3, uint8_t valDB2, uint8_t valDB1, uint8_t valDB0);
|
34 |
|
35 | int main(void) {
|
36 |
|
37 | initOutputs();
|
38 |
|
39 |
|
40 | // 1. part init
|
41 | pauseMillis(100); //30ms
|
42 |
|
43 | LCD_send(0,0,0,0,1,1,0,0,0,0);
|
44 |
|
45 | pauseMillis(100); //4.1µs
|
46 |
|
47 | LCD_send(0,0,0,0,1,1,0,0,0,0);
|
48 |
|
49 | pauseMillis(100); //100µs
|
50 |
|
51 | LCD_send(0,0,0,0,1,1,0,0,0,0);
|
52 |
|
53 | pauseMillis(100); //0ms
|
54 |
|
55 | // 2. part init
|
56 | //Function set
|
57 | LCD_send(0,0,0,0,1,1, 1,0, 0,0); // N=1 (2 lines); F=0 (5x7 dots)
|
58 |
|
59 | pauseMillis(100); //0ms
|
60 |
|
61 | //Display off
|
62 | LCD_send(0,0,0,0,0,0,1,0,0,0);
|
63 |
|
64 | pauseMillis(100); //0ms
|
65 |
|
66 | //clear display
|
67 | LCD_send(0,0,0,0,0,0,0,0,0,1);
|
68 |
|
69 | pauseMillis(100); //0ms
|
70 |
|
71 | //Entry mode set
|
72 | LCD_send(0,0,0,0,0,0,0,1, 1,0); // I/D=1 (Increment cursor pos); S=0 (don't shift display)
|
73 |
|
74 | pauseMillis(100);
|
75 |
|
76 | //initialization finished
|
77 |
|
78 |
|
79 | //Display on
|
80 | LCD_send(0,0,0,0,0,0,1, 1,1,1); // D=1 (disp on); C=1 (cursor on); B=1 (cursor blink on)
|
81 |
|
82 | while (1) /* Loop forever */
|
83 | {
|
84 | }
|
85 | }
|
86 |
|
87 | void initOutputs() {
|
88 |
|
89 | GPIOInit();
|
90 |
|
91 | // Set ports for LCD to output
|
92 | GPIOSetDir(LCD_PORT, LCD_RS, 1);
|
93 | GPIOSetDir(LCD_PORT, LCD_RW, 1);
|
94 | GPIOSetDir(LCD_PORT, LCD_E, 1);
|
95 | GPIOSetDir(LCD_PORT, LCD_DB0, 1);
|
96 | GPIOSetDir(LCD_PORT, LCD_DB1, 1);
|
97 | GPIOSetDir(LCD_PORT, LCD_DB2, 1);
|
98 | GPIOSetDir(LCD_PORT, LCD_DB3, 1);
|
99 | GPIOSetDir(LCD_PORT, LCD_DB4, 1);
|
100 | GPIOSetDir(LCD_PORT, LCD_DB5, 1);
|
101 | GPIOSetDir(LCD_PORT, LCD_DB6, 1);
|
102 | GPIOSetDir(LCD_PORT, LCD_DB7, 1);
|
103 |
|
104 | // Set ports for LCD to 'low'
|
105 | GPIOSetValue(LCD_PORT, LCD_RS, 0);
|
106 | GPIOSetValue(LCD_PORT, LCD_RW, 0);
|
107 | GPIOSetValue(LCD_PORT, LCD_E, 0);
|
108 | GPIOSetValue(LCD_PORT, LCD_DB0, 0);
|
109 | GPIOSetValue(LCD_PORT, LCD_DB1, 0);
|
110 | GPIOSetValue(LCD_PORT, LCD_DB2, 0);
|
111 | GPIOSetValue(LCD_PORT, LCD_DB3, 0);
|
112 | GPIOSetValue(LCD_PORT, LCD_DB4, 0);
|
113 | GPIOSetValue(LCD_PORT, LCD_DB5, 0);
|
114 | GPIOSetValue(LCD_PORT, LCD_DB6, 0);
|
115 | GPIOSetValue(LCD_PORT, LCD_DB7, 0);
|
116 | }
|
117 |
|
118 | //Pause-Funktionen
|
119 | void initTimer16(void);
|
120 |
|
121 | uint8_t timer16_initialized = 0;
|
122 |
|
123 | void pauseMillis(uint16_t millis) {
|
124 |
|
125 | if (!timer16_initialized)
|
126 | initTimer16();
|
127 |
|
128 | timer16_0_counter = 0;
|
129 | while (timer16_0_counter <= millis)
|
130 | ;
|
131 | }
|
132 |
|
133 | void initTimer16() {
|
134 |
|
135 | init_timer16(0, (SystemCoreClock / LPC_SYSCON ->SYSAHBCLKDIV) / 1000);
|
136 |
|
137 | // Initialise counter that counts Timer16_0 ticks
|
138 | timer16_0_counter = 0;
|
139 |
|
140 | //Enable Timer16_0
|
141 | enable_timer16(0);
|
142 | }
|
143 |
|
144 | void LCD_enable(void);
|
145 |
|
146 | void LCD_send(uint8_t valRS, uint8_t valRW, uint8_t valDB7, uint8_t valDB6, uint8_t valDB5, uint8_t valDB4, uint8_t valDB3, uint8_t valDB2, uint8_t valDB1, uint8_t valDB0){
|
147 |
|
148 | // Set RS- and R/W- ports to the specified values
|
149 | GPIOSetValue(LCD_PORT, LCD_RS, valRS);
|
150 | GPIOSetValue(LCD_PORT, LCD_RW, valRW);
|
151 | // Set DB-ports to the specified values
|
152 | GPIOSetValue(LCD_PORT, LCD_DB0, valDB0);
|
153 | GPIOSetValue(LCD_PORT, LCD_DB1, valDB1);
|
154 | GPIOSetValue(LCD_PORT, LCD_DB2, valDB2);
|
155 | GPIOSetValue(LCD_PORT, LCD_DB3, valDB3);
|
156 | GPIOSetValue(LCD_PORT, LCD_DB4, valDB4);
|
157 | GPIOSetValue(LCD_PORT, LCD_DB5, valDB5);
|
158 | GPIOSetValue(LCD_PORT, LCD_DB6, valDB6);
|
159 | GPIOSetValue(LCD_PORT, LCD_DB7, valDB7);
|
160 | // Send the enable-Signal
|
161 | LCD_enable();
|
162 | }
|
163 |
|
164 | void LCD_enable(void){
|
165 |
|
166 | GPIOSetValue(LCD_PORT, LCD_E, 1);
|
167 | pauseMillis(LCD_ENABLE_TIME);
|
168 | GPIOSetValue(LCD_PORT, LCD_E, 0);
|
169 | }
|