<pre style="max-width: 100%;"><code class="cpp hljs" codemark="1"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><msp430x14x.h></span></span>
<span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span> t=<span class="hljs-number">0</span>,
time=<span class="hljs-number">0</span>;
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">main</span> <span class="hljs-params">(<span class="hljs-keyword">void</span>)</span>
</span>{
WDTCTL=WDTPW+WDTHOLD;
P2DIR = <span class="hljs-number">0x01</span>;
P2OUT=<span class="hljs-number">0xfe</span>; <span class="hljs-comment">//点亮LED灯</span>
TACTL=TASSEL1+TACLR+ID0+ID1+MC0+TAIE;
CCR0=<span class="hljs-number">9999</span>;
_EINT();
<span class="hljs-keyword">while</span>(<span class="hljs-number">1</span>)
{
IF
(t==<span class="hljs-number">1</span>) 当t=一时实现LED灯反转
{
t=<span class="hljs-number">0</span>;
time++;
<span class="hljs-keyword">if</span>(time==<span class="hljs-number">100</span>)
{
time=<span class="hljs-number">0</span>;
P2OUT=<span class="hljs-number">0xfe</span>|(~P2OUT&BIT0);
}
}
}
}
<span class="hljs-meta">#<span class="hljs-meta-keyword">pragma</span> vector=TIMERA1_VECTOR</span>
__<span class="hljs-function">nterrupt <span class="hljs-keyword">void</span> <span class="hljs-title">timer_A</span> <span class="hljs-params">(<span class="hljs-keyword">void</span>)</span>
</span>{
<span class="hljs-keyword">switch</span>(TAIV) <span class="hljs-comment">//TAIV选择溢出中短</span>
{
<span class="hljs-keyword">case</span> <span class="hljs-number">2</span>:<span class="hljs-keyword">break</span>;
<span class="hljs-keyword">case</span> <span class="hljs-number">4</span>:<span class="hljs-keyword">break</span>;
<span class="hljs-keyword">case</span> <span class="hljs-number">10</span>:t=<span class="hljs-number">1</span>;<span class="hljs-keyword">break</span>;
}
}
</code></pre>
<br>
<p><br></p>
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>