int32_t main(void)
{
uint16_t timer=0;
uint32_t pclk=0;
volatile uint32_t u32Val = 0;
stc_clk_config_t stcCfg;
stc_uart_config_t stcConfig;
stc_uart_irq_cb_t stcUartIrqCb;
stc_uart_multimode_t stcMulti;
stc_uart_baud_config_t stcBaud;
stc_bt_config_t stcBtConfig;
//警告!!!为防止程序进入低功耗无法调试,请勿删除以下两行代码
SK_SW2_INIT();
// NextStep();
Clk_SwitchTo(ClkRCL);
Clk_SetRCHFreq(ClkFreq22_12Mhz);
Clk_SwitchTo(ClkRCH);
u32Val = Clk_GetHClkFreq();
stcCfg.enClkSrc = ClkRCH;
stcCfg.enHClkDiv = ClkDiv1;
stcCfg.enPClkDiv = ClkDiv1;
Clk_Init(&stcCfg);
DDL_ZERO_STRUCT(stcUartIrqCb);
DDL_ZERO_STRUCT(stcMulti);
DDL_ZERO_STRUCT(stcBaud);
DDL_ZERO_STRUCT(stcBtConfig);
Gpio_InitIOExt(3, 4, GpioDirOut, TRUE, FALSE, TRUE, FALSE);
Gpio_InitIOExt(3, 3, GpioDirOut, TRUE, FALSE, TRUE, FALSE);
Gpio_InitIOExt(3, 2, GpioDirOut, TRUE, FALSE, TRUE, FALSE);
Gpio_SetIO(3, 4, TRUE);
Gpio_SetIO(3, 3, TRUE);
Gpio_SetIO(3, 2, TRUE);
Gpio_InitIOExt(3,1,GpioDirOut,TRUE,FALSE,FALSE,FALSE);
Gpio_InitIOExt(2,7,GpioDirOut,TRUE,FALSE,FALSE,FALSE);
//通道端口配置
Gpio_SetFunc_UART0TX_P31();
Gpio_SetFunc_UART0RX_P27();
//外设时钟使能
Clk_SetPeripheralGate(ClkPeripheralBt,TRUE);//模式0/2可以不使能
Clk_SetPeripheralGate(ClkPeripheralUart0,TRUE);
stcUartIrqCb.pfnRxIrqCb = RxIntCallback;
stcUartIrqCb.pfnTxIrqCb = NULL;
stcUartIrqCb.pfnRxErrIrqCb = ErrIntCallback;
stcConfig.pstcIrqCb = &stcUartIrqCb;
stcConfig.bTouchNvic = TRUE;
stcConfig.enRunMode = UartMode1;//测试项,更改此处来转换4种模式测试
stcMulti.enMulti_mode = UartNormal;//测试项,更改此处来转换多主机模式,mode2/3才有多主机模式
stcConfig.pstcMultiMode = &stcMulti;
stcBaud.bDbaud = 0u;//双倍波特率功能
stcBaud.u32Baud = 2400u;//更新波特率位置
stcBaud.u8Mode = UartMode1; //计算波特率需要模式参数
pclk = Clk_GetPClkFreq();
timer=Uart_SetBaudRate(UARTCH0,pclk,&stcBaud);
stcBtConfig.enMD = BtMode2;
stcBtConfig.enCT = BtTimer;
Bt_Init(TIM0, &stcBtConfig);//调用basetimer1设置函数产生波特率
Bt_ARRSet(TIM0,timer);
Bt_Cnt16Set(TIM0,timer);
Bt_Run(TIM0);
Uart_Init(UARTCH0, &stcConfig);
Uart_EnableIrq(UARTCH0,UartRxIrq);
Uart_ClrStatus(UARTCH0,UartRxFull);
Uart_EnableFunc(UARTCH0,UartRx);
//设置GPIO值(翻转)
while (1)
{
//输出高电平,LED3灭
Gpio_SetIO(3, 4, TRUE);
delay1ms(200);
Uart_SendData(UARTCH0,'A');
//输出低电平,LED3亮
Gpio_SetIO(3, 4, FALSE);
delay1ms(200);
Uart_SendData(UARTCH0,'A');
}
}
|