问答

汇集网友智慧,解决技术难题

21ic问答首页 - TAG -
  • 请问STC8H8K64U逐飞科技例程的串口发送的和收到的为什么不同

    [i=s] 本帖最后由 学电子的小峰源 于 2022-1-20 11:57 编辑 [/i] 官方例程函数内容肯定是没有写错的,但是为什么发送0x1E我收到的却是80?怎么才能收到正确的数值呢? 主函数: [img]http://uphotos.**/1642649509/pics/1642650142527090.png[/img]void main() { DisableGlobalIRQ(); //¹Ø±Õ×ÜÖÐ¶Ï board_init(); //uart_init(DEBUG_UART,DEBUG_UART_BAUD,DEBUG_UART_RX_TX_PIN); //UART1ÒÑÔÚboard_init Öгõʼ»¯£¬²¨ÌØÂÊ115200 EnableGlobalIRQ(); //¿ªÆô×ÜÖÐ¶Ï while(1) { uart_putchar(DEBUG_UART,0x1E); delay_ms(100); } } 串口发送数据的函数 [img]http://uphotos.**/1642649509/pics/1642650186348277.png[/img] [img]http://uphotos.**/1642649509/pics/1642650201305291.png[/img] //------------------------------------------------------------------------------------------------------------------- // [url=home.php?mod=space&uid=247401]@brief[/url] ´串口字节输出 // @param uart_n 串口模块号(USART_1,USART_2,USART_3,USART_4) // @param dat 需要发送的字节 // [url=home.php?mod=space&uid=266161]@return[/url] void // Sample usage: uart_putchar(UART_1,0xA5); //串口1发送0xA5 //------------------------------------------------------------------------------------------------------------------- void uart_putchar(UARTN_enum uart_n,uint8 dat) { switch(uart_n) { case UART_1: while (busy[1]); busy[1] = 1; SBUF = dat; break; case UART_2: while (busy[2]); busy[2] = 1; S2BUF = dat; break; case UART_3: while (busy[3]); busy[3] = 1; S3BUF = dat; break; case UART_4: while (busy[4]); busy[4] = 1; S4BUF = dat; break; } } 宏定义 #define DEBUG_UART UART_1 #define DEBUG_UART_BAUD 115200 #define DEBUG_UART_RX_PIN UART1_RX_P30 #define DEBUG_UART_TX_PIN UART1_TX_P31 #define DEBUG_UART_TIM TIM_2 [img]http://uphotos.**/1642649509/pics/1642650230742208.png[/img] 串口界面如图 [img]http://uphotos.**/1642649509/pics/1642650247141560.png[/img]

    stc STC8 STC8H8K64U 单片机 逐飞

    1361浏览量 1回复量 关注量