TC264学习(1)

GPIO学习
就是给自己看的,基于LQ的例程学习

/* GPIO模式 */
#define PIN_MODE_OUTPUT          IfxPort_Mode_outputPushPullGeneral    /*!< 推挽输出  */
#define PIN_MODE_OUTPUT_OD       IfxPort_Mode_outputOpenDrainGeneral   /*!< 开漏输出  */
#define PIN_MODE_INPUT           IfxPort_Mode_inputNoPullDevice        /*!< 浮空输入  */
#define PIN_MODE_INPUT_PULLUP    IfxPort_Mode_inputPullUp              /*!< 上拉输入  */
#define PIN_MODE_INPUT_PULLDOWN  IfxPort_Mode_inputPullDown            /*!< 下拉输入  */
/* GPIO 中断触发模式 */
#define PIN_IRQ_MODE_RISING             IfxPort_InputMode_pullDown     /*!< 上升沿(下拉)触发中断 */
#define PIN_IRQ_MODE_FALLING            IfxPort_InputMode_pullUp       /*!< 下降沿(上拉)触发中断 */
#define PIN_IRQ_MODE_RISING_FALLING     IfxPort_InputMode_noPullDevice /*!< 双边沿(开漏)触发中断 */
/** GPIO外部中断 组0中断服务函数优先级   范围:1-255   数字越大 优先级越高  注意优先级不要重复 */
#define PIN_INT0_PRIORITY    100

/** GPIO外部中断 组0中断归哪个内核管理? 范围:0:CPU0   1:CPU1   3:DMA*/
#define PIN_INT0_VECTABNUM    0

/** GPIO外部中断 组1中断服务函数优先级   范围:1-255   数字越大 优先级越高  注意优先级不要重复 */
#define PIN_INT1_PRIORITY     101

/** GPIO外部中断 组1中断归哪个内核管理? 范围:0:CPU0   1:CPU1   3:DMA*/
#define PIN_INT1_VECTABNUM    0

/** GPIO外部中断 组2中断服务函数优先级   范围:1-255   数字越大 优先级越高  注意优先级不要重复 */
#define PIN_INT2_PRIORITY     102

/** GPIO外部中断 组2中断归哪个内核管理? 范围:0:CPU0   1:CPU1   3:DMA*/
#define PIN_INT2_VECTABNUM    0

/** GPIO外部中断 组3中断服务函数优先级   范围:1-255   数字越大 优先级越高  注意优先级不要重复 */
#define PIN_INT3_PRIORITY     103

/** GPIO外部中断 组3中断归哪个内核管理? 范围:0:CPU0   1:CPU1   3:DMA*/
#define PIN_INT3_VECTABNUM    0

*  函数名称:
* void PIN_InitConfig(GPIO_Name_t pin, IfxPort_Mode mode, uint8 output)
*  功能说明:GPIO初始化函数
*  参数说明:pin      : 管脚标号    lq_gpio.h中定义
*          mode     : GPIO 模式   lq_gpio.h中的宏定义中选择
*          output   : 输出模式时,输出电平 1:高电平  0:低电平
*  函数返回:无
*  修改时间:2020310*  举    例:
*  PIN_InitConfig(P00_0, PIN_MODE_OUTPUT, 1); //P00_0初始化推挽输出 高电平
*  函数名称:uint8 PIN_Read(GPIO_Name_t pin)
*  功能说明:读取GPIO电平函数
*  参数说明:pin      : 管脚标号    lq_gpio.h中定义*
*  函数返回:无
*  修改时间:2020310*  举    例:uint8_t pinState = PIN_Read(P00_0);  //读取P00_0 的电平状态
*  函数名称:void PIN_Write(GPIO_Name_t pin, uint8 output)
*  功能说明:设置GPIO输出状态
*  参数说明:pin      : 管脚标号    lq_gpio.h中定义*
*          output   : 输出模式时,输出电平 1:高电平  0:低电平
*  函数返回:无
*  修改时间:2020310*  举    例:PIN_Write(P00_0, 1);//P00_0置为高电平
*  函数名称:void PIN_Dir(GPIO_Name_t pin, uint8 mode)
*  功能说明:设置GPIO 输入输出方向
*  参数说明:pin      : 管脚标号    lq_gpio.h中定义
*            mode     : GPIO 模式   lq_gpio.h中的宏定义中选择
*  函数返回:无
*  修改时间:2020310*  举    例:PIN_Dir(P00_0, 1);//P00_0设置为输出
*  函数名称:void PIN_Dir(GPIO_Name_t pin, uint8 mode)
*  功能说明:GPIO电平翻转函数,使用前请先初始化
*  参数说明:pin      : 管脚标号    lq_gpio.h中定义*
*  函数返回:无
*  修改时间:2020310*  举    例:PIN_Reverse(P00_0); //翻转P00_0管脚的电平状态
举    例:PIN_Exti(P20_0, PIN_IRQ_MODE_FALLING);//配置P20_0 下降沿触发中断

备 注:TC264只有15个固定的GPIO支持外部中断 这15个固定GPIO分为4组,每组只能选择其中一个作为外部中断管脚使用
0:P15_4 P33_7 P15_5
1:P14_3 P15_8
2:P10_2 P02_1 P00_4 P20_0 P11_10
3:P10_3 P14_1 P02_0 P20_9 P15_1
外部中断服务函数在LQ_GPIO.c中 中断优先级配置在LQ_GPIO.h中 可以自行修改

例子

//也不知道龙邱为啥不用它写好的例程,反而都用底层的
void GPIO_init(void)
{

    // 配置 P10.1 为输出口,驱动LED灯    管脚组为P10  索引为管脚5  模式为上拉输出
    IfxPort_setPinMode(&MODULE_P10, 5,  IfxPort_Mode_outputPushPullGeneral);
    // 配置 P33.4 为输出口,驱动LED灯    管脚组为P10  索引为管脚6  模式为上拉输出
    IfxPort_setPinMode(&MODULE_P10, 6,  IfxPort_Mode_outputPushPullGeneral);

	IfxPort_setPinHigh(&MODULE_P10, 5);//设置为高电平
	IfxPort_setPinLow (&MODULE_P10, 6);//设置为低电平

}


void Test_GPIO(void)
{
	GPIO_init(); //GPIO P10.5和P10.6
	PIN_Exti(P20_0, PIN_IRQ_MODE_FALLING);//配置P20_0 下降沿触发中断
	while(1)
	{
		//IfxPort_togglePin(&MODULE_P10, 5);   //电平翻转
		//delayms(500);                        //延时等待
		IfxPort_togglePin(&MODULE_P10, 6);     //电平翻转
		delayms(500);                          //延时等待
	}
}
发布了85 篇原创文章 · 获赞 33 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_44146373/article/details/105372956
tc