📄 button_8c-source.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>AVR323 Interfacing GSM modems: ATAVRBFLY_FILES/button.c Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.7 --><div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a></div><h1>ATAVRBFLY_FILES/button.c</h1><a href="button_8c.html">Go to the documentation of this file.</a><pre class="fragment"><div>00001 <span class="comment">// This file has been prepared for Doxygen automatic documentation generation.</span>00023 <span class="comment"></span><span class="preprocessor">#include <inavr.h></span>00024 <span class="preprocessor">#include "ioavr.h"</span>00025 <span class="preprocessor">#include "<a class="code" href="main_8h.html">main.h</a>"</span>00026 <span class="preprocessor">#include "<a class="code" href="button_8h.html">button.h</a>"</span>00027 <span class="preprocessor">#include "<a class="code" href="types_8h.html">types.h</a>"</span>00028 00029 00030 <span class="comment">//extern char gPowerSaveTimer;</span>00031 <a name="l00032"></a><a class="code" href="button_8c.html#a0">00032</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="button_8c.html#a0">gButtonTimeout</a> = <a class="code" href="LCD__functions_8c.html#a0">FALSE</a>;00033 <a name="l00034"></a><a class="code" href="button_8c.html#a1">00034</a> <span class="keywordtype">char</span> <a class="code" href="button_8c.html#a1">KEY</a> = <a class="code" href="types_8h.html#a3">NULL</a>;<a name="l00035"></a><a class="code" href="button_8c.html#a2">00035</a> <span class="keywordtype">char</span> <a class="code" href="button_8c.html#a2">KEY_VALID</a> = <a class="code" href="LCD__functions_8c.html#a0">FALSE</a>;00036 00037 00038 00039 <span class="comment">/*****************************************************************************</span>00040 <span class="comment">*</span>00041 <span class="comment">* Function name : Button_Init</span>00042 <span class="comment">*</span>00043 <span class="comment">* Returns : None</span>00044 <span class="comment">*</span>00045 <span class="comment">* Parameters : None</span>00046 <span class="comment">*</span>00047 <span class="comment">* Purpose : Initializes the five button pin</span>00048 <span class="comment">*</span>00049 <span class="comment">*****************************************************************************/</span><a name="l00050"></a><a class="code" href="button_8h.html#a8">00050</a> <span class="keywordtype">void</span> <a class="code" href="button_8c.html#a3">Button_Init</a>(<span class="keywordtype">void</span>)00051 {00052 <span class="comment">// Init port pins</span>00053 <a class="code" href="main_8h.html#a1">cbi</a>(DDRB,7);00054 <a class="code" href="main_8h.html#a1">cbi</a>(DDRB,6);00055 <a class="code" href="main_8h.html#a1">cbi</a>(DDRB,4);00056 PORTB |= <a class="code" href="button_8h.html#a0">PINB_MASK</a>;00057 DDRE = 0x00;00058 PORTE |= <a class="code" href="button_8h.html#a1">PINE_MASK</a>;00059 00060 <span class="comment">// Enable pin change interrupt on PORTB and PORTE</span>00061 PCMSK0 = <a class="code" href="button_8h.html#a1">PINE_MASK</a>;00062 PCMSK1 = <a class="code" href="button_8h.html#a0">PINB_MASK</a>;00063 EIFR = (1<<PCIF0)|(1<<PCIF1);00064 EIMSK = (1<<PCIE0)|(1<<PCIE1);00065 }00066 00067 00068 <span class="preprocessor">#pragma vector = PCINT0_vect</span><a name="l00069"></a><a class="code" href="button_8c.html#a4">00069</a> <span class="preprocessor"></span><a class="code" href="splint_8h.html#a2">__interrupt</a> <span class="keywordtype">void</span> <a class="code" href="button_8c.html#a4">PCINT0_interrupt</a>(<span class="keywordtype">void</span>)00070 {00071 <a class="code" href="button_8c.html#a6">PinChangeInterrupt</a>();00072 }00073 00074 <span class="preprocessor">#pragma vector = PCINT1_vect</span><a name="l00075"></a><a class="code" href="button_8c.html#a5">00075</a> <span class="preprocessor"></span><a class="code" href="splint_8h.html#a2">__interrupt</a> <span class="keywordtype">void</span> <a class="code" href="button_8c.html#a5">PCINT1_interrupt</a>(<span class="keywordtype">void</span>)00076 {00077 <a class="code" href="button_8c.html#a6">PinChangeInterrupt</a>();00078 }00079 00080 00081 <span class="comment">/*****************************************************************************</span>00082 <span class="comment">*</span>00083 <span class="comment">* Function name : PinChangeInterrupt</span>00084 <span class="comment">*</span>00085 <span class="comment">* Returns : None</span>00086 <span class="comment">*</span>00087 <span class="comment">* Parameters : None</span>00088 <span class="comment">*</span>00089 <span class="comment">* Purpose : Check status on the joystick</span>00090 <span class="comment">*</span>00091 <span class="comment">*****************************************************************************/</span><a name="l00092"></a><a class="code" href="button_8h.html#a7">00092</a> <span class="keywordtype">void</span> <a class="code" href="button_8c.html#a6">PinChangeInterrupt</a>(<span class="keywordtype">void</span>)00093 {00094 <span class="keywordtype">char</span> buttons;00095 00096 <span class="keywordtype">char</span> key;00097 00098 <span class="comment">/*</span>00099 <span class="comment"> Read the buttons:</span>00100 <span class="comment"></span>00101 <span class="comment"> Bit 7 6 5 4 3 2 1 0</span>00102 <span class="comment"> ---------------------------------------------</span>00103 <span class="comment"> PORTB B A O</span>00104 <span class="comment"> PORTE D C</span>00105 <span class="comment"> ---------------------------------------------</span>00106 <span class="comment"> PORTB | PORTE B A O D C</span>00107 <span class="comment"> =============================================</span>00108 <span class="comment">*/</span>00109 00110 00111 buttons = (~PINB) & <a class="code" href="button_8h.html#a0">PINB_MASK</a>;00112 buttons |= (~PINE) & <a class="code" href="button_8h.html#a1">PINE_MASK</a>;00113 00114 <span class="comment">// Output virtual keys</span>00115 <span class="keywordflow">if</span> (buttons & (1<<<a class="code" href="button_8h.html#a2">BUTTON_A</a>))00116 key = <a class="code" href="main_8h.html#a27a21">KEY_PLUS</a>;00117 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (buttons & (1<<<a class="code" href="button_8h.html#a3">BUTTON_B</a>))00118 key = <a class="code" href="main_8h.html#a27a22">KEY_MINUS</a>;00119 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (buttons & (1<<<a class="code" href="button_8h.html#a4">BUTTON_C</a>))00120 key = <a class="code" href="main_8h.html#a27a20">KEY_PREV</a>;00121 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (buttons & (1<<<a class="code" href="button_8h.html#a5">BUTTON_D</a>))00122 key = <a class="code" href="main_8h.html#a27a19">KEY_NEXT</a>;00123 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (buttons & (1<<<a class="code" href="button_8h.html#a6">BUTTON_O</a>))00124 key = <a class="code" href="main_8h.html#a27a18">KEY_ENTER</a>;00125 <span class="keywordflow">else</span>00126 key = <a class="code" href="main_8h.html#a27a17">KEY_NULL</a>;00127 00128 00129 <span class="keywordflow">if</span>(key != <a class="code" href="main_8h.html#a27a17">KEY_NULL</a>)00130 {00131 <span class="keywordflow">if</span>(<a class="code" href="button_8c.html#a0">gButtonTimeout</a>) <span class="comment">// gButtonTimeout is set in the LCD_SOF_interrupt in LCD_driver.c</span>00132 {00133 <span class="keywordflow">if</span> (!<a class="code" href="button_8c.html#a2">KEY_VALID</a>)00134 {00135 <a class="code" href="button_8c.html#a1">KEY</a> = key; <span class="comment">// Store key in global key buffer</span>00136 <a class="code" href="button_8c.html#a2">KEY_VALID</a> = <a class="code" href="LCD__functions_8c.html#a1">TRUE</a>;00137 }00138 00139 <a class="code" href="button_8c.html#a0">gButtonTimeout</a> = <a class="code" href="LCD__functions_8c.html#a0">FALSE</a>;00140 00141 }00142 }00143 00144 EIFR = (1<<PCIF1) | (1<<PCIF0); <span class="comment">// Delete pin change interrupt flags</span>00145 00146 00147 }00148 00149 00150 <span class="comment">/*****************************************************************************</span>00151 <span class="comment">*</span>00152 <span class="comment">* Function name : getkey</span>00153 <span class="comment">*</span>00154 <span class="comment">* Returns : The valid key</span>00155 <span class="comment">*</span>00156 <span class="comment">* Parameters : None</span>00157 <span class="comment">*</span>00158 <span class="comment">* Purpose : Get the valid key</span>00159 <span class="comment">*</span>00160 <span class="comment">*****************************************************************************/</span><a name="l00161"></a><a class="code" href="button_8h.html#a9">00161</a> <span class="keywordtype">char</span> <a class="code" href="button_8c.html#a7">getkey</a>(<span class="keywordtype">void</span>)00162 {00163 <span class="keywordtype">char</span> k;00164 00165 __disable_interrupt();00166 00167 <span class="keywordflow">if</span> (<a class="code" href="button_8c.html#a2">KEY_VALID</a>) <span class="comment">// Check for unread key in buffer</span>00168 {00169 k = <a class="code" href="button_8c.html#a1">KEY</a>;00170 <a class="code" href="button_8c.html#a2">KEY_VALID</a> = <a class="code" href="LCD__functions_8c.html#a0">FALSE</a>;00171 }00172 <span class="keywordflow">else</span>00173 k = <a class="code" href="main_8h.html#a27a17">KEY_NULL</a>; <span class="comment">// No key stroke available</span>00174 00175 __enable_interrupt();00176 00177 <span class="keywordflow">return</span> k;00178 }</div></pre><hr size="1"><address style="align: right;"><small>Generated on Tue Nov 1 16:21:39 2005 for AVR323 Interfacing GSM modems by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.7 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -