- 打卡等级:初来乍到
- 打卡总天数:2
- 最近打卡:2024-11-30 15:45:42
已绑定手机
新手上路
- 积分
- 43
|
发表于 2024-12-24 15:32:18
|
显示全部楼层
这就上传
//========================================================================
// 函数: void UART_config(void)
// 描述: AD初始化
// 参数: None.
// 返回: None.
// 版本: V1.0, 2020-09-28
//========================================================================
void UART_config(void)
{
COMx_InitDefine COMx_InitStructure; //结构定义
P1_MODE_IO_PU(GPIO_Pin_0|GPIO_Pin_1); //P1.0,P1.1 设置为准双向口
COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //模式, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART_9bit_BRTx
// COMx_InitStructure.UART_BRT_Use = BRT_Timer2; //选择波特率发生器, BRT_Timer2 (注意: 串口2固定使用BRT_Timer2, 所以不用选择)
COMx_InitStructure.UART_BaudRate = 9600ul; //波特率, 110 ~ 115200
COMx_InitStructure.UART_RxEnable = ENABLE; //接收允许, ENABLE或DISABLE
UART_Configuration(UART2, &COMx_InitStructure); //初始化串口2 USART1,USART2,USART3,USART4
NVIC_UART2_Init(ENABLE,Priority_1); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
UART2_SW(UART2_SW_P10_P11);
}
void TX2_write2buff(u8 dat) //写入发送缓冲,指针+1
{
S2BUF = dat;
COM2.B_TX_busy = 1; //标志忙
while(COM2.B_TX_busy);
}
void UART2_ISR_Handler (void) interrupt UART2_VECTOR
{
if(RI2)
{
CLR_RI2();
if(COM2.B_RX_OK == 0)
{
RX2_Buffer[COM2.RX_Cnt++] = S2BUF;
if(COM2.RX_Cnt >= 8)
{
UsartData.u8_RecFlag = 1;
COM2.RX_Cnt = 0;
}
COM2.RX_TimeOut = TimeOutSet2;
}
}
if(TI2)
{
CLR_TI2();
COM2.B_TX_busy = 0;
// if(COM2.TX_read != COM2.TX_write)
// {
// S2BUF = TX2_Buffer[COM2.TX_read];
// if(++COM2.TX_read >= COM_TX2_Lenth) COM2.TX_read = 0;
// }
// else COM2.B_TX_busy = 0;
}
} |
|