⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd_8c-source.html

📁 单片机的软件
💻 HTML
📖 第 1 页 / 共 3 页
字号:
00316 00317 00318 <span class="comment">/*************************************************************/</span>00319 <span class="comment">/********************* PUBLIC FUNCTIONS **********************/</span>00320 <span class="comment">/*************************************************************/</span>00321 00322 <span class="keywordtype">void</span> lcdInit()00323 {00324     <span class="comment">// initialize hardware</span>00325     lcdInitHW();00326     <span class="comment">// LCD function set</span>00327     lcdControlWrite(LCD_FUNCTION_DEFAULT);00328     <span class="comment">// clear LCD</span>00329     lcdControlWrite(1&lt;&lt;LCD_CLR);00330     delay(60000);   <span class="comment">// wait 60ms</span>00331     <span class="comment">// set entry mode</span>00332     lcdControlWrite(1&lt;&lt;LCD_ENTRY_MODE | 1&lt;&lt;LCD_ENTRY_INC);00333     <span class="comment">// set display to on</span>00334     <span class="comment">//lcdControlWrite(1&lt;&lt;LCD_ON_CTRL | 1&lt;&lt;LCD_ON_DISPLAY | 1&lt;&lt;LCD_ON_BLINK);</span>00335     lcdControlWrite(1&lt;&lt;LCD_ON_CTRL | 1&lt;&lt;LCD_ON_DISPLAY );00336     <span class="comment">// move cursor to home</span>00337     lcdControlWrite(1&lt;&lt;LCD_HOME);00338     <span class="comment">// set data address to 0</span>00339     lcdControlWrite(1&lt;&lt;LCD_DDRAM | 0x00);00340 00341     <span class="comment">// load the first 8 custom characters</span>00342     lcdLoadCustomChar((u08*)LcdCustomChar,0,0);00343     lcdLoadCustomChar((u08*)LcdCustomChar,1,1);00344     lcdLoadCustomChar((u08*)LcdCustomChar,2,2);00345     lcdLoadCustomChar((u08*)LcdCustomChar,3,3);00346     lcdLoadCustomChar((u08*)LcdCustomChar,4,4);00347     lcdLoadCustomChar((u08*)LcdCustomChar,5,5);00348     lcdLoadCustomChar((u08*)LcdCustomChar,6,6);00349     lcdLoadCustomChar((u08*)LcdCustomChar,7,7);00350 }00351 00352 <span class="keywordtype">void</span> lcdHome(<span class="keywordtype">void</span>)00353 {00354     <span class="comment">// move cursor to home</span>00355     lcdControlWrite(1&lt;&lt;LCD_HOME);00356 }00357 00358 <span class="keywordtype">void</span> lcdClear(<span class="keywordtype">void</span>)00359 {00360     <span class="comment">// clear LCD</span>00361     lcdControlWrite(1&lt;&lt;LCD_CLR);00362 }00363 00364 <span class="keywordtype">void</span> lcdGotoXY(u08 x, u08 y)00365 {00366     <span class="keyword">register</span> u08 DDRAMAddr;00367 00368     <span class="comment">// remap lines into proper order</span>00369     <span class="keywordflow">switch</span>(y)00370     {00371     <span class="keywordflow">case</span> 0: DDRAMAddr = LCD_LINE0_DDRAMADDR+x; <span class="keywordflow">break</span>;00372     <span class="keywordflow">case</span> 1: DDRAMAddr = LCD_LINE1_DDRAMADDR+x; <span class="keywordflow">break</span>;00373     <span class="keywordflow">case</span> 2: DDRAMAddr = LCD_LINE2_DDRAMADDR+x; <span class="keywordflow">break</span>;00374     <span class="keywordflow">case</span> 3: DDRAMAddr = LCD_LINE3_DDRAMADDR+x; <span class="keywordflow">break</span>;00375     <span class="keywordflow">default</span>: DDRAMAddr = LCD_LINE0_DDRAMADDR+x;00376     }00377 00378     <span class="comment">// set data address</span>00379     lcdControlWrite(1&lt;&lt;LCD_DDRAM | DDRAMAddr);00380 }00381 00382 <span class="keywordtype">void</span> lcdLoadCustomChar(u08* lcdCustomCharArray, u08 romCharNum, u08 lcdCharNum)00383 {00384     <span class="keyword">register</span> u08 i;00385     u08 saveDDRAMAddr;00386 00387     <span class="comment">// backup the current cursor position</span>00388     saveDDRAMAddr = lcdControlRead() &amp; 0x7F;00389 00390     <span class="comment">// multiply the character index by 8</span>00391     lcdCharNum = (lcdCharNum&lt;&lt;3);   <span class="comment">// each character occupies 8 bytes</span>00392     romCharNum = (romCharNum&lt;&lt;3);   <span class="comment">// each character occupies 8 bytes</span>00393 00394     <span class="comment">// copy the 8 bytes into CG (character generator) RAM</span>00395     <span class="keywordflow">for</span>(i=0; i&lt;8; i++)00396     {00397         <span class="comment">// set CG RAM address</span>00398         lcdControlWrite((1&lt;&lt;LCD_CGRAM) | (lcdCharNum+i));00399         <span class="comment">// write character data</span>00400         lcdDataWrite( pgm_read_byte(lcdCustomCharArray+romCharNum+i) );00401     }00402 00403     <span class="comment">// restore the previous cursor position</span>00404     lcdControlWrite(1&lt;&lt;LCD_DDRAM | saveDDRAMAddr);00405 00406 }00407 00408 <span class="keywordtype">void</span> lcdPrintData(<span class="keywordtype">char</span>* data, u08 nBytes)00409 {00410     <span class="keyword">register</span> u08 i;00411 00412     <span class="comment">// check to make sure we have a good pointer</span>00413     <span class="keywordflow">if</span> (!data) <span class="keywordflow">return</span>;00414 00415     <span class="comment">// print data</span>00416     <span class="keywordflow">for</span>(i=0; i&lt;nBytes; i++)00417     {00418         lcdDataWrite(data[i]);00419     }00420 }00421 00422 <span class="keywordtype">void</span> lcdProgressBar(u16 progress, u16 maxprogress, u08 length)00423 {00424     u08 i;00425     u32 pixelprogress;00426     u08 c;00427 00428     <span class="comment">// draw a progress bar displaying (progress / maxprogress)</span>00429     <span class="comment">// starting from the current cursor position</span>00430     <span class="comment">// with a total length of "length" characters</span>00431     <span class="comment">// ***note, LCD chars 0-5 must be programmed as the bar characters</span>00432     <span class="comment">// char 0 = empty ... char 5 = full</span>00433 00434     <span class="comment">// total pixel length of bargraph equals length*PROGRESSPIXELS_PER_CHAR;</span>00435     <span class="comment">// pixel length of bar itself is</span>00436     pixelprogress = ((progress*(length*PROGRESSPIXELS_PER_CHAR))/maxprogress);00437     00438     <span class="comment">// print exactly "length" characters</span>00439     <span class="keywordflow">for</span>(i=0; i&lt;length; i++)00440     {00441         <span class="comment">// check if this is a full block, or partial or empty</span>00442         <span class="comment">// (u16) cast is needed to avoid sign comparison warning</span>00443         <span class="keywordflow">if</span>( ((i*(u16)PROGRESSPIXELS_PER_CHAR)+5) &gt; pixelprogress )00444         {00445             <span class="comment">// this is a partial or empty block</span>00446             <span class="keywordflow">if</span>( ((i*(u16)PROGRESSPIXELS_PER_CHAR)) &gt; pixelprogress )00447             {00448                 <span class="comment">// this is an empty block</span>00449                 <span class="comment">// use space character?</span>00450                 c = 0;00451             }00452             <span class="keywordflow">else</span>00453             {00454                 <span class="comment">// this is a partial block</span>00455                 c = pixelprogress % PROGRESSPIXELS_PER_CHAR;00456             }00457         }00458         <span class="keywordflow">else</span>00459         {00460             <span class="comment">// this is a full block</span>00461             c = 5;00462         }00463         00464         <span class="comment">// write character to display</span>00465         lcdDataWrite(c);00466     }00467 00468 }00469 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Aug 22 04:29:27 2005 for Procyon AVRlib by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -