(三)点亮LED


点亮LED


简单描述

查看原理图,对应LED的io口是:

P33_4 P33_5;

一般外设io口 在英飞凌这边都写成:&MODULE_P33 以&MODULE开头(并且一般其他的外设也都是以&MODULE开头,比如GTM外设模块,&MODULE_GTM,再比如ASCLIN模块,&MODULE_ASCLIN2)等等

基于iLLD库里面,跟外设io口相关的基本都在IfxPort.h里面:

#include "IfxPort.h"

延时的waitTime函数,以及获取相应时间,对应的滴答定时器的数值函数,分别在:

#include "Bsp.h"
#include "IfxStm.h"

注意:waitTime传入的参数是,系统的滴答数值,借助IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 1000)可以直接获取对应时间的滴答数量。比如这里延时1000ms,就用IfxStm_getTicksFromMilliseconds,如果是1000us,那就是调用这个IfxStm_getTicksFromMicroseconds。

添加.c.h文件,应用为王

.c 代码:

void led_Init(void)
{
    IfxPort_setPinMode(&MODULE_P33,5,IfxPort_Mode_outputPushPullGeneral);  //初始化P33_5推挽输出
    IfxPort_setPinMode(&MODULE_P33,4,IfxPort_Mode_outputPushPullGeneral); 	//初始化P33_4推挽输出

    IfxPort_setPinState(&MODULE_P33,5,IfxPort_State_high);		// 设置P33_5输出高电平
    IfxPort_setPinState(&MODULE_P33,4,IfxPort_State_high);		// 设置P33_4输出高电平


void blink_Led(void)
{
    IfxPort_setPinState(&MODULE_P33,5,IfxPort_State_low);		// 设置P33_5输出低电平
    IfxPort_setPinState(&MODULE_P33,4,IfxPort_State_low);		// 设置P33_4输出低电平
    waitTime(IfxStm_getTicksFromMilliseconds(IFXSTM_DEFAULT_TIMER,1000));	// 延时1000ms  

    IfxPort_setPinState(&MODULE_P33,5,IfxPort_State_high);
    IfxPort_setPinState(&MODULE_P33,4,IfxPort_State_high);
    waitTime(IfxStm_getTicksFromMilliseconds(IFXSTM_DEFAULT_TIMER,1000));
}

.h 代码:

#ifndef LED_H_
#define LED_H_

void led_Init(void);
void blink_Led(void);

#endif

主函数调用:

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

#include "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);
    led_Init();
    
    while(1)
    {
        blink_Led();
    }
}

测试现象:

2个led间歇1000ms闪烁

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小爪.exe

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值