yanxinboy 发表于 2020-9-12 21:35

【CH579M-R1】2. SYSTICK + GPIO + INT

本帖最后由 yanxinboy 于 2020-9-12 21:41 编辑

<p>按申请时的测试计划,目前在熟悉沁恒文档及提供的库,尤其是蓝牙BLE 和 以太网Ethernet 的操作。 同步对CH579提供的常用外设做简单的测试。</p>

<p>&nbsp;</p>

<p>既然CH579是ARM M0内核的,今天测试将对CH579的GPIO 和GPIO外部中断进行测试, 同时使用SYSTICK。&nbsp;</p>

<p>&nbsp;</p>

<p>测试功能: 系统上电,SYSTICK设置100MS的中断,板载LED3, LED4通过SYSTICK 均以1S的周期交替闪烁。按下GPIO外部中断按键后,LED3, LED4 将以0.2秒的速度快速交替闪烁。 再次按下外部外键,LED3, LED4将重新按1S间隔交替闪烁。以此类推。</p>

<p>&nbsp;</p>

<p>硬件连接: LED3, LED4分别连接PA0 和 PB0(沁恒CH579M-R1开发板LED3, LED4未连接到任何GPIO,供用户选择连接使用); 按键使用板载按键S2 (RESET - 默认GPIO功能)连接PA1( S2 本来连接至PB 23, 为方便测试直接连接PB23和PA1脚,因GPIO 外部中断仅在PA0~PA15, PB0~PB15提供)<img height="47" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/lol.gif" width="47" /></p>

<p>&nbsp;</p>

<p>直接上程序代码,比较简单,测试用,写的不好,见谅:</p>

<div aria-label="代码段 小部件" contenteditable="false" role="region" tabindex="-1">
<pre data-widget="codesnippet">
<code class="language-cpp hljs"><span class="hljs-preprocessor">#include &quot;CH57x_common.h&quot;</span>

<span class="hljs-keyword">static</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">char</span> KeyS2status=<span class="hljs-number">0</span>;

<span class="hljs-keyword">void</span> DebugInit(<span class="hljs-keyword">void</span>)               
{
    GPIOA_SetBits(GPIO_Pin_9);
    GPIOA_ModeCfg(GPIO_Pin_8, GPIO_ModeIN_PU);
    GPIOA_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP_5mA);
    UART1_DefInit();
}


<span class="hljs-keyword">void</span> SysTick_Handler(<span class="hljs-keyword">void</span>)
{
        <span class="hljs-keyword">static</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">char</span> cnt=<span class="hljs-number">0</span>;
        <span class="hljs-keyword">if</span>(!KeyS2status){
        cnt++;
        <span class="hljs-keyword">if</span>(cnt&gt;<span class="hljs-number">9</span>){
                cnt=<span class="hljs-number">0</span>;
                GPIOB_InverseBits(GPIO_Pin_0);
                PRINT(<span class="hljs-string">&quot;LED4 Toggle every 1 second\r\n&quot;</span>);               
                GPIOA_InverseBits(GPIO_Pin_0);
                PRINT(<span class="hljs-string">&quot;LED3 Toggle every 1 second\r\n&quot;</span>);
                        }
                                        }
        <span class="hljs-keyword">else</span>{
                cnt++;
        <span class="hljs-keyword">if</span>(cnt&gt;<span class="hljs-number">1</span>){
                cnt=<span class="hljs-number">0</span>;
                GPIOB_InverseBits(GPIO_Pin_0);
                PRINT(<span class="hljs-string">&quot;LED4 Toggle every 0.2 second\r\n&quot;</span>);               
                GPIOA_InverseBits(GPIO_Pin_0);
                PRINT(<span class="hljs-string">&quot;LED3 Toggle every 0.2 second\r\n&quot;</span>);
                        }
                }
}

<span class="hljs-keyword">void</span> GPIO_IRQHandler(<span class="hljs-keyword">void</span>)
{
        KeyS2status=~KeyS2status;
        GPIOA_ClearITFlagBit( GPIO_Pin_1 );
}

<span class="hljs-keyword">int</span> main()
{
    DebugInit();
    PRINT( <span class="hljs-string">&quot;Start @ChipID=%02X Test By Yanxinboy\n&quot;</span>, R8_CHIP_ID );

        GPIOB_SetBits(GPIO_Pin_0);
        GPIOB_ModeCfg(GPIO_Pin_0,GPIO_ModeOut_PP_5mA);
        GPIOB_ResetBits(GPIO_Pin_0);
       
        GPIOA_SetBits(GPIO_Pin_0);
        GPIOA_ModeCfg(GPIO_Pin_0,GPIO_ModeOut_PP_5mA);
       
        SysTick_Config(FREQ_SYS/<span class="hljs-number">10</span>);
       
        GPIOA_ModeCfg( GPIO_Pin_1, GPIO_ModeIN_PU );
    GPIOA_ITModeCfg( GPIO_Pin_1, GPIO_ITMode_FallEdge );
    NVIC_EnableIRQ( GPIO_IRQn );
   
        <span class="hljs-keyword">while</span>(<span class="hljs-number">1</span>){   
                ;
        }
}</code></pre>
<img src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==" /><span style="background: url(&quot;https://bbs.eeworld.com.cn/static/editor/plugins/widget/images/handle.png&quot;) rgba(220, 220, 220, 0.5); top: -15px; left: 0px; display: block;"><img height="15" role="presentation" src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==" title="点击并拖拽以移动" width="15" /></span></div>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>实验现象见视频,串口输出入下:<br />
<iframe allowfullscreen="true" frameborder="0" height="450" src="https://v.qq.com/txp/iframe/player.html?vid=r3151dy5c09" style="background:#eee;margin-bottom:10px;" width="544"></iframe></p>

<p></p>
页: [1]
查看完整版本: 【CH579M-R1】2. SYSTICK + GPIO + INT