问答

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

logan0279

TA的家园币:112  

  • 从 STC8H1Kxx 升级到 STC8A8K64D4 串口乱码

    本帖最后由jrcsh于2021-12-1403:09编辑从8H1Kxx升级到8A8K64D4代码复制过去发现串口乱码,花了一个晚上排查出是配置了P1口引起P3口的串口乱码,有其他人也遇到这样吗?以下代码主要引用至厂家例程://#include"reg51.h"#include"STC8HX.h"#include"intrins.h"#defineFOSC11059200UL#defineBRT(65536-FOSC/115200/4)//s/frAUXR=0x8e;//sfrT2H=0xd6;//sfrT2L=0xd7;bitbusy;charwptr;charrptr;charbuffer[16];charaaa;voidDelay100ms()//@11.0592MHz{unsignedchari,j,k;_nop_();_nop_();i=5;j=52;k=195;do{do{while(--k);}while(--j);}while(--i);}voidUartIsr()interrupt4{if(TI){TI=0;busy=0;}if(RI){RI=0;buffer[wptr++]=SBUF;wptr&=0x0f;}}voidUartInit(){SCON=0x50;T2L=BRT;T2H=BRT>>8;AUXR=0x15;wptr=0x00;rptr=0x00;busy=0;}voidUartSend(chardat){while(busy);busy=1;SBUF=dat;}voidUartSendStr(char*p){while(*p){UartSend(*p++);}}voidmain(){P1M1=0x00;//设置P1强推P1M0=0xf0;//8H1kf0UartInit();ES=1;EA=1;UartSendStr("UartTest!\r\n");while(1){aaa++;if(aaa>10){aaa=0;UartSendStr("UartTest!#\r\n");}Delay100ms();UartSendStr("UartTest!\r\n");if(rptr!=wptr){UartSend(buffer[rptr++]);rptr&=0x0f;}}}下载视频

    stc

    2021-12-13 9