本帖最后由 pkjapan 于 2018-12-23 22:48 编辑
串口输出超过128就会变成0x3f,比如打印一个累计的unsigned char变量,到了0x7f 往后就变成0x3f了 郁闷啊 按理应该是 0x80 啊
这两种都没法输出unsigned char
拿到串口打不出0x7f以上的数?
void USART_Transmit(USART_TypeDef *USARTx,uint16_t ch_data)
{
// Loop until the end of transmission
while (USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET)
{
;
}
USART_SendData(USARTx, (uint16_t)ch_data);
}
void USART4_Transmit(char ch_data)
{
// Loop until the end of transmission
while (USART_GetFlagStatus(UART4, USART_FLAG_TC) == RESET)
{
;
}
USART_SendData(UART4, (char)ch_data);
}
void Usart4_Init(unsigned int baud)
{
GPIO_InitTypeDef gpioInitStruct;
USART_InitTypeDef usartInitStruct;
NVIC_InitTypeDef nvicInitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
//PC10 TXD
gpioInitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
gpioInitStruct.GPIO_Pin = GPIO_Pin_10;
gpioInitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &gpioInitStruct);
//PC11 RXD
gpioInitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
gpioInitStruct.GPIO_Pin = GPIO_Pin_11;
gpioInitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &gpioInitStruct);
usartInitStruct.USART_BaudRate = baud;
usartInitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //无硬件流控
usartInitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //接收和发送
usartInitStruct.USART_Parity = USART_Parity_No; //无校验
usartInitStruct.USART_StopBits = USART_StopBits_1; //1位停止位
usartInitStruct.USART_WordLength = USART_WordLength_8b; //8位数据位
USART_Init(UART4, &usartInitStruct);
USART_Cmd(UART4, ENABLE); //使能串口
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE); //使能接收中断
nvicInitStruct.NVIC_IRQChannel = UART4_IRQn;
nvicInitStruct.NVIC_IRQChannelCmd = ENABLE;
nvicInitStruct.NVIC_IRQChannelPreemptionPriority = 0;
nvicInitStruct.NVIC_IRQChannelSubPriority = 0;
NVIC_Init(&nvicInitStruct);
}
void USART_SendData(USART_TypeDef* USARTx, uint16_t Data)
{
/* Check the parameters */
assert_param(IS_USART_ALL_PERIPH(USARTx));
assert_param(IS_USART_DATA(Data));
/* Transmit Data */
USARTx->DR = (Data & (uint16_t)0x01FF);
}
疯了啊???????
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
找到问题了,原因是用了1.2版本的XCOM 换成2.0版本的就能显示了,想想我都经历了什么???
一周热门 更多>