打印
[其它产品/技术]

TC397:点灯&GPIO常规操作

[复制链接]
344|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
aoyi|  楼主 | 2023-10-27 10:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如下为GPIO的简单是引脚操作函数:

设置引脚MODE:

void IfxPort_setPinModeInput(Ifx_P *port, uint8 pinIndex, IfxPort_InputMode mode);

void IfxPort_setPinModeOutput(Ifx_P *port, uint8 pinIndex, IfxPort_InputMode mode);

IfxPort_setPinModeInput(&MODULE_P33, 0, IfxPort_InputMode_pullUp);

IfxPort_setPinModeOutput(&MODULE_P33, 0, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);

设置引脚电平:

void IfxPort_setPinHigh(Ifx_P *port, uint8 pinIndex);

void IfxPort_setPinLow(Ifx_P *port, uint8 pinIndex);

IfxPort_setPinLow(&MODULE_P33, 0);

设置引脚状态:

void IfxPort_setPinState(Ifx_P *port, uint8 pinIndex, IfxPort_State action)

设置引脚翻转:

void IfxPort_togglePin(Ifx_P *port, uint8 pinIndex);

读取引脚状态:

boolean IfxPort_getPinState(Ifx_P *port, uint8 pinIndex)

API详细参见:IfxPort.h

延时函数:

waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, WAIT_TIME));    /* Wait 500 milliseconds  

如下点灯:

Blinky LED文件:

#include "IfxPort.h"
#include "Bsp.h"

#define LED_D107    &MODULE_P13,0                                           /* LED D107: Port, Pin definition       */
#define WAIT_TIME   500                                                     /* Wait time constant in milliseconds   */

/* This function initializes the port pin which drives the LED */
void initLED(void)
{
    IfxPort_setPinModeOutput(LED_D107, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);

    IfxPort_setPinHigh(LED_D107);
}

void blinkLED(void)
{
    IfxPort_togglePin(LED_D107);                                                /* Toggle the state of the LED      */
    waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, WAIT_TIME));    /* Wait 500 milliseconds            */
}

main.c

#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "Blinky_LED.h"

IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;

void core0_main(void)
{
    IfxCpu_enableInterrupts();

    /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
     * Enable the watchdogs and service them periodically if it is required
     */
    IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
    IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());

    /* Wait for CPU sync event */
    IfxCpu_emitEvent(&g_cpuSyncEvent);
    IfxCpu_waitEvent(&g_cpuSyncEvent, 1);

    initLED();  /* Initialize the LED port pin      */

    while(1)
    {
        blinkLED(); /* Make the LED blink           */
    }
}

————————————————
版权声明:本文为CSDN博主「IOT-Power」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/a15236617777/article/details/131634000

使用特权

评论回复
沙发
tpgf| | 2024-4-8 14:29 | 只看该作者
在什么应用下选择引脚额哪种模式有没有相关说明啊

使用特权

评论回复
板凳
wowu| | 2024-4-8 15:41 | 只看该作者
点灯的话 需要额外的驱动电路吗

使用特权

评论回复
地板
wakayi| | 2024-4-8 16:51 | 只看该作者
这种硬件上是一个引脚控制一个小灯吗?

使用特权

评论回复
5
renzheshengui| | 2024-4-8 18:01 | 只看该作者
从代码上看好像io的模式只有四种是吗

使用特权

评论回复
6
木木guainv| | 2024-4-9 10:47 | 只看该作者
如何确认引脚自己内置的上拉电阻是不是能力足够呢

使用特权

评论回复
7
xiaoqizi| | 2024-4-9 12:08 | 只看该作者
这样的控制方式太浪费引脚资源了

使用特权

评论回复
8
Burnon_FAE_1| | 2024-4-9 14:28 | 只看该作者
wakayi 发表于 2024-4-8 16:51
这种硬件上是一个引脚控制一个小灯吗?

几mA的LED可以直接驱动,大电流的灯需要加驱动

使用特权

评论回复
9
小夏天的大西瓜| | 2024-4-22 21:40 | 只看该作者
点灯的话直接IO输出应该就可以

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

99

主题

3301

帖子

3

粉丝