📄 lcd_8c-source.html
字号:
00155 <span class="preprocessor"> #endif</span>00156 <span class="preprocessor"></span> <span class="comment">// leave data lines in input mode so they can be most easily used for other purposes</span>00157 <span class="preprocessor"> #ifdef LCD_DATA_4BIT</span>00158 <span class="preprocessor"></span> outb(LCD_DATA_DDR, inb(LCD_DATA_DDR)&0x0F); <span class="comment">// set data I/O lines to input (4bit)</span>00159 outb(LCD_DATA_POUT, inb(LCD_DATA_POUT)|0xF0); <span class="comment">// set pull-ups to on (4bit)</span>00160 <span class="preprocessor"> #else</span>00161 <span class="preprocessor"></span> outb(LCD_DATA_DDR, 0x00); <span class="comment">// set data I/O lines to input (8bit)</span>00162 outb(LCD_DATA_POUT, 0xFF); <span class="comment">// set pull-ups to on (8bit)</span>00163 <span class="preprocessor"> #endif</span>00164 <span class="preprocessor"></span><span class="preprocessor">#else</span>00165 <span class="preprocessor"></span> <span class="comment">// memory bus write</span>00166 <span class="comment">//sbi(MCUCR, SRW); // enable RAM waitstate</span>00167 lcdBusyWait(); <span class="comment">// wait until LCD not busy</span>00168 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *) (LCD_CTRL_ADDR)) = data;00169 <span class="comment">//cbi(MCUCR, SRW); // disable RAM waitstate</span>00170 <span class="preprocessor">#endif</span>00171 <span class="preprocessor"></span>}00172 00173 u08 lcdControlRead(<span class="keywordtype">void</span>)00174 {00175 <span class="comment">// read the control byte from the display controller</span>00176 <span class="keyword">register</span> u08 data;00177 <span class="preprocessor">#ifdef LCD_PORT_INTERFACE</span>00178 <span class="preprocessor"></span> lcdBusyWait(); <span class="comment">// wait until LCD not busy</span>00179 <span class="preprocessor"> #ifdef LCD_DATA_4BIT</span>00180 <span class="preprocessor"></span> outb(LCD_DATA_DDR, inb(LCD_DATA_DDR)&0x0F); <span class="comment">// set data I/O lines to input (4bit)</span>00181 outb(LCD_DATA_POUT, inb(LCD_DATA_POUT)|0xF0); <span class="comment">// set pull-ups to on (4bit)</span>00182 <span class="preprocessor"> #else</span>00183 <span class="preprocessor"></span> outb(LCD_DATA_DDR, 0x00); <span class="comment">// set data I/O lines to input (8bit)</span>00184 outb(LCD_DATA_POUT, 0xFF); <span class="comment">// set pull-ups to on (8bit)</span>00185 <span class="preprocessor"> #endif</span>00186 <span class="preprocessor"></span> cbi(LCD_CTRL_PORT, LCD_CTRL_RS); <span class="comment">// set RS to "control"</span>00187 sbi(LCD_CTRL_PORT, LCD_CTRL_RW); <span class="comment">// set R/W to "read"</span>00188 <span class="preprocessor"> #ifdef LCD_DATA_4BIT</span>00189 <span class="preprocessor"></span> <span class="comment">// 4 bit read</span>00190 sbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// set "E" line</span>00191 LCD_DELAY; <span class="comment">// wait</span>00192 LCD_DELAY; <span class="comment">// wait</span>00193 data = inb(LCD_DATA_PIN)&0xF0; <span class="comment">// input data, high 4 bits</span>00194 cbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// clear "E" line</span>00195 LCD_DELAY; <span class="comment">// wait</span>00196 LCD_DELAY; <span class="comment">// wait</span>00197 sbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// set "E" line</span>00198 LCD_DELAY; <span class="comment">// wait</span>00199 LCD_DELAY; <span class="comment">// wait</span>00200 data |= inb(LCD_DATA_PIN)>>4; <span class="comment">// input data, low 4 bits</span>00201 cbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// clear "E" line</span>00202 <span class="preprocessor"> #else</span>00203 <span class="preprocessor"></span> <span class="comment">// 8 bit read</span>00204 sbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// set "E" line</span>00205 LCD_DELAY; <span class="comment">// wait</span>00206 LCD_DELAY; <span class="comment">// wait</span>00207 data = inb(LCD_DATA_PIN); <span class="comment">// input data, 8bits</span>00208 cbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// clear "E" line</span>00209 <span class="preprocessor"> #endif</span>00210 <span class="preprocessor"></span> <span class="comment">// leave data lines in input mode so they can be most easily used for other purposes</span>00211 <span class="preprocessor">#else</span>00212 <span class="preprocessor"></span> <span class="comment">//sbi(MCUCR, SRW); // enable RAM waitstate</span>00213 lcdBusyWait(); <span class="comment">// wait until LCD not busy</span>00214 data = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *) (LCD_CTRL_ADDR));00215 <span class="comment">//cbi(MCUCR, SRW); // disable RAM waitstate</span>00216 <span class="preprocessor">#endif</span>00217 <span class="preprocessor"></span> <span class="keywordflow">return</span> data;00218 }00219 00220 <span class="keywordtype">void</span> lcdDataWrite(u08 data) 00221 {00222 <span class="comment">// write a data byte to the display</span>00223 <span class="preprocessor">#ifdef LCD_PORT_INTERFACE</span>00224 <span class="preprocessor"></span> lcdBusyWait(); <span class="comment">// wait until LCD not busy</span>00225 sbi(LCD_CTRL_PORT, LCD_CTRL_RS); <span class="comment">// set RS to "data"</span>00226 cbi(LCD_CTRL_PORT, LCD_CTRL_RW); <span class="comment">// set R/W to "write"</span>00227 <span class="preprocessor"> #ifdef LCD_DATA_4BIT</span>00228 <span class="preprocessor"></span> <span class="comment">// 4 bit write</span>00229 sbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// set "E" line</span>00230 outb(LCD_DATA_DDR, inb(LCD_DATA_DDR)|0xF0); <span class="comment">// set data I/O lines to output (4bit)</span>00231 outb(LCD_DATA_POUT, (inb(LCD_DATA_POUT)&0x0F) | (data&0xF0) ); <span class="comment">// output data, high 4 bits</span>00232 LCD_DELAY; <span class="comment">// wait</span>00233 LCD_DELAY; <span class="comment">// wait</span>00234 cbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// clear "E" line</span>00235 LCD_DELAY; <span class="comment">// wait</span>00236 LCD_DELAY; <span class="comment">// wait</span>00237 sbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// set "E" line</span>00238 outb(LCD_DATA_POUT, (inb(LCD_DATA_POUT)&0x0F) | (data<<4) ); <span class="comment">// output data, low 4 bits</span>00239 LCD_DELAY; <span class="comment">// wait</span>00240 LCD_DELAY; <span class="comment">// wait</span>00241 cbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// clear "E" line</span>00242 <span class="preprocessor"> #else</span>00243 <span class="preprocessor"></span> <span class="comment">// 8 bit write</span>00244 sbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// set "E" line</span>00245 outb(LCD_DATA_DDR, 0xFF); <span class="comment">// set data I/O lines to output (8bit)</span>00246 outb(LCD_DATA_POUT, data); <span class="comment">// output data, 8bits</span>00247 LCD_DELAY; <span class="comment">// wait</span>00248 LCD_DELAY; <span class="comment">// wait</span>00249 cbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// clear "E" line</span>00250 <span class="preprocessor"> #endif</span>00251 <span class="preprocessor"></span> <span class="comment">// leave data lines in input mode so they can be most easily used for other purposes</span>00252 <span class="preprocessor"> #ifdef LCD_DATA_4BIT</span>00253 <span class="preprocessor"></span> outb(LCD_DATA_DDR, inb(LCD_DATA_DDR)&0x0F); <span class="comment">// set data I/O lines to input (4bit)</span>00254 outb(LCD_DATA_POUT, inb(LCD_DATA_POUT)|0xF0); <span class="comment">// set pull-ups to on (4bit)</span>00255 <span class="preprocessor"> #else</span>00256 <span class="preprocessor"></span> outb(LCD_DATA_DDR, 0x00); <span class="comment">// set data I/O lines to input (8bit)</span>00257 outb(LCD_DATA_POUT, 0xFF); <span class="comment">// set pull-ups to on (8bit)</span>00258 <span class="preprocessor"> #endif</span>00259 <span class="preprocessor"></span><span class="preprocessor">#else</span>00260 <span class="preprocessor"></span> <span class="comment">// memory bus write</span>00261 <span class="comment">//sbi(MCUCR, SRW); // enable RAM waitstate</span>00262 lcdBusyWait(); <span class="comment">// wait until LCD not busy</span>00263 *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *) (LCD_DATA_ADDR)) = data;00264 <span class="comment">//cbi(MCUCR, SRW); // disable RAM waitstate</span>00265 <span class="preprocessor">#endif</span>00266 <span class="preprocessor"></span>}00267 00268 u08 lcdDataRead(<span class="keywordtype">void</span>)00269 {00270 <span class="comment">// read a data byte from the display</span>00271 <span class="keyword">register</span> u08 data;00272 <span class="preprocessor">#ifdef LCD_PORT_INTERFACE</span>00273 <span class="preprocessor"></span> lcdBusyWait(); <span class="comment">// wait until LCD not busy</span>00274 <span class="preprocessor"> #ifdef LCD_DATA_4BIT</span>00275 <span class="preprocessor"></span> outb(LCD_DATA_DDR, inb(LCD_DATA_DDR)&0x0F); <span class="comment">// set data I/O lines to input (4bit)</span>00276 outb(LCD_DATA_POUT, inb(LCD_DATA_POUT)|0xF0); <span class="comment">// set pull-ups to on (4bit)</span>00277 <span class="preprocessor"> #else</span>00278 <span class="preprocessor"></span> outb(LCD_DATA_DDR, 0x00); <span class="comment">// set data I/O lines to input (8bit)</span>00279 outb(LCD_DATA_POUT, 0xFF); <span class="comment">// set pull-ups to on (8bit)</span>00280 <span class="preprocessor"> #endif</span>00281 <span class="preprocessor"></span> sbi(LCD_CTRL_PORT, LCD_CTRL_RS); <span class="comment">// set RS to "data"</span>00282 sbi(LCD_CTRL_PORT, LCD_CTRL_RW); <span class="comment">// set R/W to "read"</span>00283 <span class="preprocessor"> #ifdef LCD_DATA_4BIT</span>00284 <span class="preprocessor"></span> <span class="comment">// 4 bit read</span>00285 sbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// set "E" line</span>00286 LCD_DELAY; <span class="comment">// wait</span>00287 LCD_DELAY; <span class="comment">// wait</span>00288 data = inb(LCD_DATA_PIN)&0xF0; <span class="comment">// input data, high 4 bits</span>00289 cbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// clear "E" line</span>00290 LCD_DELAY; <span class="comment">// wait</span>00291 LCD_DELAY; <span class="comment">// wait</span>00292 sbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// set "E" line</span>00293 LCD_DELAY; <span class="comment">// wait</span>00294 LCD_DELAY; <span class="comment">// wait</span>00295 data |= inb(LCD_DATA_PIN)>>4; <span class="comment">// input data, low 4 bits</span>00296 cbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// clear "E" line</span>00297 <span class="preprocessor"> #else</span>00298 <span class="preprocessor"></span> <span class="comment">// 8 bit read</span>00299 sbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// set "E" line</span>00300 LCD_DELAY; <span class="comment">// wait</span>00301 LCD_DELAY; <span class="comment">// wait</span>00302 data = inb(LCD_DATA_PIN); <span class="comment">// input data, 8bits</span>00303 cbi(LCD_CTRL_PORT, LCD_CTRL_E); <span class="comment">// clear "E" line</span>00304 <span class="preprocessor"> #endif</span>00305 <span class="preprocessor"></span> <span class="comment">// leave data lines in input mode so they can be most easily used for other purposes</span>00306 <span class="preprocessor">#else</span>00307 <span class="preprocessor"></span> <span class="comment">// memory bus read</span>00308 <span class="comment">//sbi(MCUCR, SRW); // enable RAM waitstate</span>00309 lcdBusyWait(); <span class="comment">// wait until LCD not busy</span>00310 data = *((<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *) (LCD_DATA_ADDR));00311 <span class="comment">//cbi(MCUCR, SRW); // disable RAM waitstate</span>00312 <span class="preprocessor">#endif</span>00313 <span class="preprocessor"></span> <span class="keywordflow">return</span> data;00314 }00315
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -