tc397+示例代码
时间: 2024-01-17 08:03:07 浏览: 179
TC397是英飞凌(Infineon)公司推出的一款高性能微控制器。它具有强大的处理能力和丰富的外设接口,适用于各种复杂的应用场景。下面是一个使用TC397的示例代码,演示了如何使用ASCLIN模块的串口功能控制LED灯:
```c
#include <stdio.h>
#include <stdlib.h>
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "IfxPort.h"
#include "IfxAsclin_Asc.h"
#define ASC_TX_BUFFER_SIZE 64
#define ASC_RX_BUFFER_SIZE 64
uint8 ascTxBuffer[ASC_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];
uint8 ascRxBuffer[ASC_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];
IfxAsclin_Asc asc;
void initSerialPort()
{
IfxAsclin_Asc_Config ascConfig;
IfxAsclin_Asc_initModuleConfig(&ascConfig, &MODULE_ASCLIN0);
ascConfig.baudrate.baudrate = 115200;
ascConfig.baudrate.oversampling = IfxAsclin_OversamplingFactor_16;
ascConfig.interrupt.txPriority = 1;
ascConfig.interrupt.rxPriority = 2;
ascConfig.interrupt.erPriority = 0;
ascConfig.txBuffer = &ascTxBuffer[0];
ascConfig.txBufferSize = ASC_TX_BUFFER_SIZE;
ascConfig.rxBuffer = &ascRxBuffer[0];
ascConfig.rxBufferSize = ASC_RX_BUFFER_SIZE;
IfxAsclin_Asc_initModule(&asc, &ascConfig);
}
void sendString(const char *str)
{
while (*str != '\0')
{
while (!IfxAsclin_Asc_write(&asc, *str))
{
}
str++;
}
}
int main(void)
{
IfxCpu_enableInterrupts();
initSerialPort();
while (1)
{
sendString("Hello, world!\r\n");
IfxScuWdt_clearSafetyEndinitInline(IfxScuWdt_getSafetyWatchdogPasswordInline());
IfxPort_togglePin(&MODULE_P33, 0);
IfxScuWdt_setSafetyEndinitInline(IfxScuWdt_getSafetyWatchdogPasswordInline());
wait(1000000);
}
return 0;
}
```
这段代码初始化了ASCLIN模块的串口功能,并通过串口发送"Hello, world!"字符串。同时,每隔一段时间会切换LED灯的状态。
阅读全文