【Microchip WBZ451 Curiosity】-6- gpio驱动
本帖最后由 慕容雪花 于 2023-8-19 18:13 编辑<p>GPIO是非常重要的外设,本文以驱动WBZ451的PB7引脚为例,展示基于MPLABX ide MCC图形化配置工具的快速GPIO驱动设计。</p>
<p>WBZ451模块引脚不多,PB7在好奇开发板上连接到是用户LED,比较直观。</p>
<p> </p>
<p> </p>
<p> </p>
<p>1. 从IDE主界面进入MCC:</p>
<p> </p>
<p>2. 在PLUGINs下来菜单中,选择“Pin Configuration”,自此进入GPIO编辑界面。</p>
<p> </p>
<div style="text-align: center;"></div>
<p> </p>
<p>3. 针对PB7,可以自定义引脚名称,设置Function为GPIO,方向为OUT</p>
<div style="text-align: center;"></div>
<div style="text-align: center;"> </div>
<p>4. 在项目图中,点击System,展开Ports->Pin Configuration,可以看到步骤3中编辑的条目已经显示出来了。</p>
<div style="text-align: center;"></div>
<p> </p>
<div style="text-align: center;"> </div>
<p>5. 点击Generate,自动生成代码。</p>
<p> </p>
<p>6. 到task.c中新创建一个Task:LED_BLINKY,专门用于点灯。</p>
<pre>
<code>void SYS_Tasks ( void )
{
/* Maintain system services */
/* Maintain Device Drivers */
/* Maintain Middleware & Other Libraries */
if (xTaskCreate(BM_Task, "BLE", TASK_BLE_STACK_SIZE, NULL, TASK_BLE_PRIORITY, NULL) != pdPASS)
while (1);
/* Maintain the application's state machine. */
/* Create OS Thread for APP_Tasks. */
xTaskCreate((TaskFunction_t) _APP_Tasks,
"APP_Tasks",
1024,
NULL,
1,
&xAPP_Tasks);
xTaskCreate((TaskFunction_t) _LED_Blinky,
"LED_Tasks",
1024,
NULL,
1,
&xLED_Blinky);
/* Start RTOS Scheduler. */
/**********************************************************************
* Create all Threads for APP Tasks before starting FreeRTOS Scheduler *
***********************************************************************/
vTaskStartScheduler(); /* This function never returns. */
}</code></pre>
<p> </p>
<p>这个task的入口函数定义如下,其中精确延迟采用了freeRTOS推荐的API.</p>
<pre>
<code>void _LED_Blinky(void *pvParameters){
while(1){
GPIO_RB7_Toggle();
vTaskDelay(1000/portTICK_PERIOD_MS);
}
}</code></pre>
<p>7. 编译,烧录。</p>
<pre>
<code>Currently loaded versions:
Application version...........00.06.60
Boot version..................01.01.41
Script version................00.05.72
Script build number...........2889965820
Tool pack version ............1.11.1054
Target voltage detected
Target device WBZ451 found.
Device Revision Id= 0xfbf
Device Id = 0x9b8f
Calculating memory ranges for operation...
Erasing...
The following memory area(s) will be programmed:
program memory: start address = 0x1004000, end address = 0x1025fff
configuration memory
boot config memory
Programming/Verify complete</code></pre>
<p>8. 结果:</p>
<p> </p>
<div style="text-align: center;">
<div style="text-align: center;"></div>
<p> </p>
</div>
<div style="text-align: center;"> </div>
<p> </p>
<p>第5篇文章解决了UART后,更新了本文的代码,在单片机启动后打印:</p>
<pre>
<code>SERCOM0_USART_Write((uint8_t *)"Hello Welcome to WBZ451 World\r\n",strlen("Hello Welcome to WBZ451 World\r\n"));</code></pre>
<p> </p>
<p>在ble回调函数中:</p>
<p> </p>
<pre>
<code>void APP_BleGapEvtHandler(BLE_GAP_Event_T *p_event)
{
switch(p_event->eventId)
{
case BLE_GAP_EVT_CONNECTED:
{
/* TODO: implement your application code.*/
SERCOM0_USART_Write((uint8_t *)"Great! ^-^ Connect to GAP Center Device\r\n",strlen("Great! ^-^ Connect to GAP Center Device\r\n"));
}
break;
case BLE_GAP_EVT_DISCONNECTED:
{
/* TODO: implement your application code.*/
SERCOM0_USART_Write((uint8_t *)"Ah oh... :( Disconnect to GAP Center Device\r\n",strlen("Ah oh... :( Disconnect to GAP Center Device\r\n"));
}
break;</code></pre>
<p>实测结果如下:</p>
<p> </p>
<p> </p>
<p>很有趣!MCC配置工具使用熟练后,更会觉得它的强大!</p>
页:
[1]