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

📄 spyglass_8c-source.html

📁 国外牛人公开的AVR代码
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Procyon AVRlib: spyglass.c Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.2 --><div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div><h1>spyglass.c</h1><a href="spyglass_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file spyglass.c \brief Spyglass Control Panel UI Board Driver. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name    : 'spyglass.c'</span>00005 <span class="comment">// Title        : Spyglass Control Panel UI Board Driver</span>00006 <span class="comment">// Author       : Pascal Stang - Copyright (C) 2005</span>00007 <span class="comment">// Created      : 7/20/2005</span>00008 <span class="comment">// Revised      : 7/23/2005</span>00009 <span class="comment">// Version      : 0.9</span>00010 <span class="comment">// Target MCU   : Atmel AVR series</span>00011 <span class="comment">// Editor Tabs  : 4</span>00012 <span class="comment">//</span>00013 <span class="comment">// This code is distributed under the GNU Public License</span>00014 <span class="comment">//      which can be found at http://www.gnu.org/licenses/gpl.txt</span>00015 <span class="comment">//</span>00016 <span class="comment">//*****************************************************************************</span>00017 00018 00019 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00020 <span class="preprocessor">#include "<a class="code" href="rprintf_8h.html">rprintf.h</a>"</span>00021 <span class="preprocessor">#include "<a class="code" href="timer_8h.html">timer.h</a>"</span>00022 <span class="preprocessor">#include "<a class="code" href="i2c_8h.html">i2c.h</a>"</span>00023 <span class="preprocessor">#include "<a class="code" href="spyglass_8h.html">spyglass.h</a>"</span>00024 00025 <span class="preprocessor">#include "<a class="code" href="lcd_8h.html">lcd.h</a>"</span>00026 00027 u08 PcfCtrlData;00028 <a name="l00029"></a><a class="code" href="group__spyglass.html#ga11">00029</a> u08 <a class="code" href="group__spyglass.html#ga11">pcf8574Write</a>(u08 nodeAddr, u08 data)00030 {00031     <span class="comment">// write data</span>00032     <span class="keywordflow">return</span> <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(PCF8574_I2C_BASE_ADDR+(nodeAddr&lt;&lt;1), 1, &amp;data);00033 }00034 <a name="l00035"></a><a class="code" href="group__spyglass.html#ga12">00035</a> u08 <a class="code" href="group__spyglass.html#ga12">pcf8574Read</a>(u08 nodeAddr)00036 {00037     u08 data;00038     <a class="code" href="i2c_8c.html#a25">i2cMasterReceiveNI</a>(PCF8574_I2C_BASE_ADDR+(nodeAddr&lt;&lt;1), 1, &amp;data);00039     <span class="keywordflow">return</span> data;00040 }00041 <a name="l00042"></a><a class="code" href="group__spyglass.html#ga0">00042</a> <span class="keywordtype">void</span> <a class="code" href="group__spyglass.html#ga0">spyglassInit</a>(<span class="keywordtype">void</span>)00043 {00044     <a class="code" href="i2c_8c.html#a10">i2cInit</a>();00045     <a class="code" href="i2c_8c.html#a11">i2cSetBitrate</a>(100);00046     PcfCtrlData = (SPYGLASS_LED0 | SPYGLASS_LED1 | SPYGLASS_BEEPER);00047     <a class="code" href="group__spyglass.html#ga2">spyglassSetLeds</a>(0);00048     <a class="code" href="group__spyglass.html#ga3">spyglassSetBeeper</a>(0);00049 }00050 <a name="l00051"></a><a class="code" href="group__spyglass.html#ga1">00051</a> u08 <a class="code" href="group__spyglass.html#ga1">spyglassGetPushbuttons</a>(<span class="keywordtype">void</span>)00052 {00053     <span class="keywordflow">return</span> ~<a class="code" href="group__spyglass.html#ga12">pcf8574Read</a>(PCF_NODE_BUTTONS);00054 }00055 <a name="l00056"></a><a class="code" href="group__spyglass.html#ga2">00056</a> <span class="keywordtype">void</span> <a class="code" href="group__spyglass.html#ga2">spyglassSetLeds</a>(u08 leds)00057 {00058     PcfCtrlData = (PcfCtrlData|0x03) &amp; ~(leds&amp;0x03);00059     <a class="code" href="group__spyglass.html#ga11">pcf8574Write</a>(PCF_NODE_CONTROL, PcfCtrlData);00060 }00061 <a name="l00062"></a><a class="code" href="group__spyglass.html#ga3">00062</a> <span class="keywordtype">void</span> <a class="code" href="group__spyglass.html#ga3">spyglassSetBeeper</a>(u08 state)00063 {00064     <span class="keywordflow">if</span>(state)00065         PcfCtrlData &amp;=~SPYGLASS_BEEPER;     <span class="comment">// beeper on</span>00066     <span class="keywordflow">else</span>00067         PcfCtrlData |= SPYGLASS_BEEPER;     <span class="comment">// beeper off</span>00068     <a class="code" href="group__spyglass.html#ga11">pcf8574Write</a>(PCF_NODE_CONTROL, PcfCtrlData);00069 }00070 <a name="l00071"></a><a class="code" href="group__spyglass.html#ga4">00071</a> u08 <a class="code" href="group__spyglass.html#ga4">spyglassSetLcdContrast</a>(u08 contrast)00072 {00073     u08 data[2];00074     data[0] = 0;00075     data[1] = contrast;00076     <span class="keywordflow">return</span> <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(MAX517_I2C_BASE_ADDR, 2, data);00077 }00078 <a name="l00079"></a><a class="code" href="group__spyglass.html#ga9">00079</a> <span class="keywordtype">void</span> <a class="code" href="group__spyglass.html#ga9">spyglassLcdWrite</a>(u08 rs, u08 data)00080 {00081     <span class="comment">// prepare LCD control lines</span>00082     PcfCtrlData &amp;= ~(SPYGLASS_LCD_RW | SPYGLASS_LCD_RS | SPYGLASS_LCD_E);00083     <span class="keywordflow">if</span>(rs)00084         PcfCtrlData |= SPYGLASS_LCD_RS;00085     <span class="comment">// set LCD control lines</span>00086     <a class="code" href="group__spyglass.html#ga11">pcf8574Write</a>(PCF_NODE_CONTROL, PcfCtrlData);00087     <span class="comment">// set data lines</span>00088     <a class="code" href="group__spyglass.html#ga11">pcf8574Write</a>(PCF_NODE_LCD_DATA, data);00089     <span class="comment">// clock E line</span>00090     <a class="code" href="group__spyglass.html#ga11">pcf8574Write</a>(PCF_NODE_CONTROL, PcfCtrlData|SPYGLASS_LCD_E);00091     <a class="code" href="group__spyglass.html#ga11">pcf8574Write</a>(PCF_NODE_CONTROL, PcfCtrlData);00092 }00093 <a name="l00094"></a><a class="code" href="group__spyglass.html#ga10">00094</a> <span class="keywordtype">void</span> <a class="code" href="group__spyglass.html#ga10">spyglassLcdWriteChar</a>(u08 c)00095 {00096     <a class="code" href="group__spyglass.html#ga9">spyglassLcdWrite</a>(1,c);00097 }00098 <a name="l00099"></a><a class="code" href="group__spyglass.html#ga5">00099</a> <span class="keywordtype">void</span> <a class="code" href="group__spyglass.html#ga5">spyglassLcdInit</a>(<span class="keywordtype">void</span>)00100 {00101     <span class="comment">// LCD function set</span>00102     <a class="code" href="group__spyglass.html#ga9">spyglassLcdWrite</a>(0,LCD_FUNCTION_DEFAULT);00103     <span class="comment">// clear LCD</span>00104     <a class="code" href="group__spyglass.html#ga9">spyglassLcdWrite</a>(0,1&lt;&lt;LCD_CLR);00105     delay(60000);   <span class="comment">// wait 60ms</span>00106     <span class="comment">// set entry mode</span>00107     <a class="code" href="group__spyglass.html#ga9">spyglassLcdWrite</a>(0,1&lt;&lt;LCD_ENTRY_MODE | 1&lt;&lt;LCD_ENTRY_INC);00108     <span class="comment">// set display to on</span>00109     <a class="code" href="group__spyglass.html#ga9">spyglassLcdWrite</a>(0,1&lt;&lt;LCD_ON_CTRL | 1&lt;&lt;LCD_ON_DISPLAY );00110     <span class="comment">// move cursor to home</span>00111     <a class="code" href="group__spyglass.html#ga9">spyglassLcdWrite</a>(0,1&lt;&lt;LCD_HOME);00112     <span class="comment">// set data address to 0</span>00113     <a class="code" href="group__spyglass.html#ga9">spyglassLcdWrite</a>(0,1&lt;&lt;LCD_DDRAM | 0x00);00114 00115     <span class="comment">// set contrast</span>00116     <a class="code" href="group__spyglass.html#ga4">spyglassSetLcdContrast</a>(20);00117 }00118 <a name="l00119"></a><a class="code" href="group__spyglass.html#ga6">00119</a> <span class="keywordtype">void</span> <a class="code" href="group__spyglass.html#ga6">spyglassLcdHome</a>(<span class="keywordtype">void</span>)00120 {00121     <span class="comment">// move cursor to home</span>00122     <a class="code" href="group__spyglass.html#ga9">spyglassLcdWrite</a>(0,1&lt;&lt;LCD_HOME);00123 }00124 <a name="l00125"></a><a class="code" href="group__spyglass.html#ga7">00125</a> <span class="keywordtype">void</span> <a class="code" href="group__spyglass.html#ga7">spyglassLcdClear</a>(<span class="keywordtype">void</span>)00126 {00127     <span class="comment">// clear LCD</span>00128     <a class="code" href="group__spyglass.html#ga9">spyglassLcdWrite</a>(0,1&lt;&lt;LCD_CLR);00129 }00130 <a name="l00131"></a><a class="code" href="group__spyglass.html#ga8">00131</a> <span class="keywordtype">void</span> <a class="code" href="group__spyglass.html#ga8">spyglassLcdGotoXY</a>(u08 x, u08 y)00132 {00133     <span class="keyword">register</span> u08 DDRAMAddr;00134 00135     <span class="comment">// remap lines into proper order</span>00136     <span class="keywordflow">switch</span>(y)00137     {00138     <span class="keywordflow">case</span> 0: DDRAMAddr = LCD_LINE0_DDRAMADDR+x; <span class="keywordflow">break</span>;00139     <span class="keywordflow">case</span> 1: DDRAMAddr = LCD_LINE1_DDRAMADDR+x; <span class="keywordflow">break</span>;00140     <span class="keywordflow">case</span> 2: DDRAMAddr = LCD_LINE2_DDRAMADDR+x; <span class="keywordflow">break</span>;00141     <span class="keywordflow">case</span> 3: DDRAMAddr = LCD_LINE3_DDRAMADDR+x; <span class="keywordflow">break</span>;00142     <span class="keywordflow">default</span>: DDRAMAddr = LCD_LINE0_DDRAMADDR+x;00143     }00144 00145     <span class="comment">// set data address</span>00146     <a class="code" href="group__spyglass.html#ga9">spyglassLcdWrite</a>(0,1&lt;&lt;LCD_DDRAM | DDRAMAddr);00147 }</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Oct 24 16:03:55 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 + -