问答

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

学电子的小峰源

TA的家园币:10  

  • 请问STC8H8K64U逐飞科技例程的串口发送的和收到的为什么不同

    官方例程函数内容肯定是没有写错的,但是为什么发送0x1E我收到的却是80?怎么才能收到正确的数值呢?主函数:voidmain(){DisableGlobalIRQ();//¹Ø±Õ×ÜÖжÏboard_init();//uart_init(DEBUG_UART,DEBUG_UART_BAUD,DEBUG_UART_RX_TX_PIN);//UART1ÒÑÔÚboard_initÖгõʼ»¯£¬²¨ÌØÂÊ115200EnableGlobalIRQ();//¿ªÆô×ÜÖжÏwhile(1){uart_putchar(DEBUG_UART,0x1E);delay_ms(100);}}串口发送数据的函数//-------------------------------------------------------------------------------------------------------------------//@brief´串口字节输出//@paramuart_n串口模块号(USART_1,USART_2,USART_3,USART_4)//@paramdat需要发送的字节//@returnvoid//Sampleusage:uart_putchar(UART_1,0xA5);//串口1发送0xA5//-------------------------------------------------------------------------------------------------------------------voiduart_putchar(UARTN_enumuart_n,uint8dat){switch(uart_n){caseUART_1:while(busy[1]);busy[1]=1;SBUF=dat;break;caseUART_2:while(busy[2]);busy[2]=1;S2BUF=dat;break;caseUART_3:while(busy[3]);busy[3]=1;S3BUF=dat;break;caseUART_4:while(busy[4]);busy[4]=1;S4BUF=dat;break;}}宏定义#defineDEBUG_UARTUART_1#defineDEBUG_UART_BAUD115200#defineDEBUG_UART_RX_PINUART1_RX_P30#defineDEBUG_UART_TX_PINUART1_TX_P31#defineDEBUG_UART_TIMTIM_2串口界面如图