periphery_8c-source.html
来自「MSP acquires data and sends through USB 」· HTML 代码 · 共 225 行 · 第 1/2 页
HTML
225 行
<!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>Sample MSP430-4619LCD Project: periphery.c Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"><link href="tabs.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.5.1 --><div class="tabs"> <ul> <li><a href="main.html"><span>Main Page</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li id="current"><a href="files.html"><span>Files</span></a></li> </ul></div><div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>Globals</span></a></li> </ul></div><h1>periphery.c</h1><a href="periphery_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span><a name="l00002"></a>00002 <span class="comment"> * File: periphery.c</span><a name="l00003"></a>00003 <span class="comment"> * Purpose: Keyboard and joystick handler functions</span><a name="l00004"></a>00004 <span class="comment"> * Author: Peter Ivanov, Olimex Ltd.</span><a name="l00005"></a>00005 <span class="comment"> * Modified by:</span><a name="l00006"></a>00006 <span class="comment"> * Created: 2007-05-19 11:29:32</span><a name="l00007"></a>00007 <span class="comment"> * Last modify: 2007-10-03 21:05:09 ivanovp {Time-stamp}</span><a name="l00008"></a>00008 <span class="comment"> * Copyright: (C) Peter Ivanov, Olimex Ltd., 2007</span><a name="l00009"></a>00009 <span class="comment"> * Licence: GPL</span><a name="l00010"></a>00010 <span class="comment"> */</span><a name="l00016"></a>00016 <span class="preprocessor">#include <msp430xG461x.h></span><a name="l00017"></a>00017 <span class="preprocessor">#include <signal.h></span><a name="l00018"></a>00018 <span class="preprocessor">#include "<a class="code" href="periphery_8h.html">periphery.h</a>"</span><a name="l00019"></a>00019 <span class="preprocessor">#include "<a class="code" href="lcd_8h.html">lcd.h</a>"</span><a name="l00020"></a>00020 <span class="preprocessor">#include "<a class="code" href="time_8h.html">time.h</a>"</span><a name="l00021"></a>00021 <a name="l00022"></a><a class="code" href="periphery_8h.html#091d014581a2dd236ee7eb29ea220219">00022</a> <span class="keyword">volatile</span> <a class="code" href="common_8h.html#449976458a084f880dc8e3d29e7eb6f5">bool_t</a> <a class="code" href="periphery_8c.html#091d014581a2dd236ee7eb29ea220219">KBD_b1Pressed</a>;<a name="l00023"></a><a class="code" href="periphery_8h.html#073df23545e437a9157e7e7bd906821f">00023</a> <span class="keyword">volatile</span> <a class="code" href="common_8h.html#449976458a084f880dc8e3d29e7eb6f5">bool_t</a> <a class="code" href="periphery_8c.html#073df23545e437a9157e7e7bd906821f">KBD_b2Pressed</a>;<a name="l00024"></a>00024 <a name="l00031"></a><a class="code" href="periphery_8h.html#2a649e701ffa69773fb450e89db89698">00031</a> <span class="keyword">inline</span> uint8_t <a class="code" href="periphery_8c.html#2a649e701ffa69773fb450e89db89698">KBD_getB1</a> ()<a name="l00032"></a>00032 {<a name="l00033"></a>00033 <span class="keywordflow">return</span> !(P1IN & BIT6);<a name="l00034"></a>00034 }<a name="l00035"></a>00035 <a name="l00042"></a><a class="code" href="periphery_8h.html#d16bb4f020abd6db5093cccc2fdede88">00042</a> <span class="keyword">inline</span> uint8_t <a class="code" href="periphery_8c.html#d16bb4f020abd6db5093cccc2fdede88">KBD_getB2</a> ()<a name="l00043"></a>00043 {<a name="l00044"></a>00044 <span class="keywordflow">return</span> !(P1IN & BIT7);<a name="l00045"></a>00045 }<a name="l00046"></a>00046 <a name="l00050"></a>00050 <span class="comment">//#pragma vector=PORT1_VECTOR</span><a name="l00051"></a>00051 <span class="comment">//__interrupt void handle_port_interrupt( void )</span><a name="l00052"></a><a class="code" href="periphery_8c.html#aef39e368becfc8ede2d7e992660ded8">00052</a> <a class="code" href="periphery_8c.html#aef39e368becfc8ede2d7e992660ded8">interrupt</a> (PORT1_VECTOR) handle_port_interrupt( <span class="keywordtype">void</span> ) <a name="l00053"></a>00053 {<a name="l00054"></a>00054 <span class="comment">// Button 1 (B1)</span><a name="l00055"></a>00055 <span class="keywordflow">if</span> (P1IFG & BIT6) <a name="l00056"></a>00056 {<a name="l00057"></a>00057 <a class="code" href="periphery_8c.html#091d014581a2dd236ee7eb29ea220219">KBD_b1Pressed</a> = <a class="code" href="common_8h.html#a8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;<a name="l00058"></a>00058 }<a name="l00059"></a>00059 <a name="l00060"></a>00060 <span class="comment">// Button 2 (B2)</span><a name="l00061"></a>00061 <span class="keywordflow">if</span> (P1IFG & BIT7) <a name="l00062"></a>00062 {<a name="l00063"></a>00063 <a class="code" href="periphery_8c.html#073df23545e437a9157e7e7bd906821f">KBD_b2Pressed</a> = <a class="code" href="common_8h.html#a8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;<a name="l00064"></a>00064 }<a name="l00065"></a>00065 <a name="l00066"></a>00066 <span class="comment">// Clear all interupt flag</span><a name="l00067"></a>00067 P1IFG = 0x0;<a name="l00068"></a>00068 P2IFG = 0x0;<a name="l00069"></a>00069 }<a name="l00070"></a>00070 <a name="l00074"></a><a class="code" href="periphery_8h.html#477b8611b60e8470d77f072cf7c9d0b7">00074</a> <span class="keywordtype">void</span> <a class="code" href="periphery_8c.html#477b8611b60e8470d77f072cf7c9d0b7">KBD_init</a> (<span class="keywordtype">void</span>) <a name="l00075"></a>00075 {<a name="l00076"></a>00076 <span class="comment">// Ports P1.6, P1.7 as input</span><a name="l00077"></a>00077 P1DIR &= ~(BIT6 | BIT7);<a name="l00078"></a>00078 <a name="l00079"></a>00079 <span class="comment">// Set high-to-low transition for P1.6, P1.7</span><a name="l00080"></a>00080 P1IES |= BIT6 | BIT7;<a name="l00081"></a>00081 <a name="l00082"></a>00082 <span class="comment">// Enable interupts for P1.6, P1.7</span><a name="l00083"></a>00083 P1IE |= BIT6 | BIT7;<a name="l00084"></a>00084 <a name="l00085"></a>00085 <span class="comment">// Clear all interrupts flag</span><a name="l00086"></a>00086 P1IFG = 0x0;<a name="l00087"></a>00087 P2IFG = 0x0;<a name="l00088"></a>00088 }<a name="l00089"></a>00089 <a name="l00093"></a><a class="code" href="periphery_8h.html#b28c3e1b3cf39437be09919fb78a364c">00093</a> <span class="keywordtype">void</span> <a class="code" href="periphery_8c.html#b28c3e1b3cf39437be09919fb78a364c">JOY_init</a>(<span class="keywordtype">void</span>) <a name="l00094"></a>00094 {<a name="l00095"></a>00095 <span class="comment">// Init ADC interface</span><a name="l00096"></a>00096 <a class="code" href="periphery_8c.html#d773088e6129cd48c3d19dc2d2bd9a94">ADC12_init</a> ();<a name="l00097"></a>00097 <a name="l00098"></a>00098 <span class="comment">// A7 as analog input</span><a name="l00099"></a>00099 P6SEL |= BIT7; <span class="comment">// P6.7 ADC10 function</span><a name="l00100"></a>00100 P6DIR &= ~BIT7; <span class="comment">// P6.7 input direction</span><a name="l00101"></a>00101 <a name="l00102"></a>00102 <span class="comment">// P2.6 as input</span><a name="l00103"></a>00103 P2SEL &= ~BIT6; <span class="comment">// P2.6 as GPIO</span><a name="l00104"></a>00104 P2DIR &= ~BIT6; <span class="comment">// P2.6 as input</span><a name="l00105"></a>00105 }<a name="l00106"></a>00106 <a name="l00114"></a><a class="code" href="periphery_8h.html#3ef001533f2bf00e62e27f2a1e5172ed">00114</a> JOY_pos_t <a class="code" href="periphery_8c.html#3ef001533f2bf00e62e27f2a1e5172ed">JOY_getPosition</a> (<span class="keywordtype">void</span>) <a name="l00115"></a>00115 {<a name="l00116"></a>00116 JOY_pos_t jresult;<a name="l00117"></a>00117 <span class="keywordtype">int</span> adcresult;<a name="l00118"></a>00118 <span class="keywordtype">char</span> nsample;<a name="l00119"></a>00119 <a name="l00120"></a>00120 adcresult = 0;<a name="l00121"></a>00121 jresult = 0;<a name="l00122"></a>00122 <a name="l00123"></a>00123 <span class="keywordflow">for</span> (nsample = 0; nsample < 8; nsample++) <a name="l00124"></a>00124 {<a name="l00125"></a>00125 adcresult += <a class="code" href="periphery_8c.html#231a7acdc6e3232732bedba92e905288">ADC12_get</a> (INCH_7);<a name="l00126"></a>00126 }<a name="l00127"></a>00127 <a name="l00128"></a>00128 adcresult /= (nsample + 1);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?