串口调试助手通信调试原理图PCB及使用手册【简要说明】一、尺寸:长170mmX宽72mmX高18mm二、主要芯片:单片机,MAX485,MAX232三、工作电压:6V至40V,功耗小于1W四、特点:1、具有稳压电路,输入电压广,具有电源指示灯。2、具有485通信和232通信及TTL通信。3、具有数码管数据显示,蜂鸣器提示音4、波特率可调分别是240048009600192005、采用大按键,机械寿命长。6、单片机编程,提供源代码7、可发送20组数据8、具有系统复位按键9、端子采用螺旋压接端子10、工作温度-40度至+70度11、工作湿度40%~80%RH12、板子静态功耗小于1W13、具有续流保护14、具有电磁抗干扰能力15、板子稳定工作可靠16、板子可安装在DIN导轨上面使用说明:【标注说明】【功能描述】【原理图】【PCB图】【元件清单】【应用举例】【应用举例2】例如:将下面一组数据通过串口发送给电脑。波特率是9600,电脑用串口助手显示出来。数据是:A0B2CCFFEFD89088第一步:板子供电,串口连接电脑,查看串口号。如下图:我的电脑--属性--硬件---设备管理器---端口设备。第二步:打开串口助手,设置对应的串口号和十六进制显示。如下图:第三步:从发送板,按下下面一组数据,数据是:A0B2CCFFEFD89088数据按完之后,按发送键“S2”,如果数据输入错误,可以按”S1”按键清零,重新输入。如果要发送多遍,重复按“S2”按键。单遍发送如下图。【源代码程序】/*一次最多发送20组数据,大于这个数据就不再发送*/#includeSTC12C5A60S2.H#defineucharunsignedchar#defineuintunsignedint/**************************************************************/unsignedcharT0RH=0;//T0重载值的高字节unsignedcharT0RL=0;//T0重载值的低字节externvoidUartDriver();//串口驱动函数,监测数据帧的接收,调度功能函数,需在主循环中调用externvoidConfigUART(unsignedintbaud);//串口配置函数,baud-通信波特率externvoidConfigUART1(unsignedintbaud1);//串口配置函数,baud-通信波特率externvoidUartRxMonitor(unsignedcharms);//串口接收监控,由空闲时间判定帧结束,需在定时中断中调用,ms-定时间隔externvoidSendString(char*s);externvoidUartWrite(unsignedchar*buf,unsignedcharlen);//串口数据写入,即串口发送函数,buf-待发送数据的指针,len-指定的发送长度externvoidfengming();ucharzh[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};ucharjieshou[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};ucharjj=0;/*****************************************************************/sbitout0=P2^0;sbitout1=P2^1;sbitout2=P2^2;sbitout3=P2^3;sbitin0=P2^4;sbitin1=P2^5;sbitin2=P2^6;sbitin3=P2^7;sbitsmgk=P3^6;sbitboma1=P1^1;sbitboma2=P1^0;bitd1=1;bitd2=1;sbitin4=P1^6;sbitin5=P1^5;ucharcodexianshi[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xbf};uchardangqianzhuangtai[4][4]={{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}};voidt0()interrupt1{uchari;staticucharlie=0;staticucharsao[2]={1,1};staticucharsaomiaobaocun[4][4]={{0xff,0xff,0xff,0xff},{0xff,0xff,0xff,0xff},{0xff,0xff,0xff,0xff},{0xff,0xff,0xff,0xff}};TH0=0xfc;TL0=0x67;UartRxMonitor(1);//串口接收监控sao[0]=(sao[0]1)|in4;sao[1]=(sao[1]1)|in5;saomiaobaocun[lie][0]=(saomiaobaocun[lie][0]1)|in0;saomiaobaocun[lie][1]=(saomiaobaocun[lie][1]1)|in1;saomiaobaocun[lie][2]=(saomiaobaocun[lie][2]1)|in2;saomiaobaocun[lie][3]=(saomiaobaocun[lie][3]1)|in3;if(sao[0]==0x00){d1=0;}elseif(sao[0]==0xff){d1=1;}if(sao[1]==0x00){d2=0;}elseif(sao[1]==0xff){d2=1;}for(i=0;i4;i++){if((saomiaobaocun[lie][i]&0x0f)==0x00){dangqianzhuangtai[lie][i]=0;}elseif((saomiaobaocun[lie][i]&0x0f)==0x0f){dangqianzhuangtai[lie][i]=1;}}lie++;lie=lie&0x03;switch(lie){case0:out1=1;out2=1;out3=1;out0=0;break;case1:out0=1;out2=1;out3=1;out1=0;break;case2:out0=1;out1=1;out3=1;out2=0;break;case3:out0=1;out1=1;out2=1;out3=0;break;}}voidmain(){uchari,j;bitq1=1;bitq2=1;ucharqianyicizhuangtai[4][4]={{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}};smgk=0;TMOD=0x01;TH0=0xfc;TL0=0x67;TR0=1;EA=1;ET0=1;P0=xianshi[16];//ConfigUART(9600);//配置波特率为9600while(1){UartDriver();//调用串口驱动if((boma1==0)&&(boma2!=0)){ConfigUART(2400);//配置波特率为1200}if((boma2==0)&&(boma1!=0)){ConfigUART(4800);//配置波特率为4800}if((boma1==0)&&(boma2==0)){ConfigUART(9600);//配置波特率为9600}if((boma1!=0)&&(boma2!=0)){ConfigUART1(19200);//配置波特率为19200}if(d1!=q1){q1=d1;if(d1==0){if((jj!=0)&&(jj=2)){zh[0]=jieshou[0]|jieshou[1];UartWrite(zh,1);fengming();}if((jj2)&&(jj=4)){zh[0]=jieshou[0]|jieshou[1];zh[1]=jieshou[2]|jieshou[3];UartWrite(zh,2);fengming();}if((jj4)&&(jj=6)){zh[0]=jieshou[0]|jieshou[1];zh[1]=jieshou[2]|jieshou[3];zh[2]=jieshou[4]|jieshou[5];UartWrite(zh,3);fengming();}if((jj6)&&(jj=8)){zh[0]=jieshou[0]|jieshou[1];zh[1]=jieshou[2]|jieshou[3];zh[2]=jieshou[4]|jieshou[5];zh[3]=jieshou[6]|jieshou[7];UartWrite(zh,4);fengming();}if((jj8)&&(jj=10)){zh[0]=jieshou[0]|jieshou[1];zh[1]=jieshou[2]|jieshou[3];zh[2]=jieshou[4]|jieshou[5];zh[3]=jieshou[6]|jieshou[7];zh[4]=jieshou[8]|jieshou[9];UartWrite(zh,5);fengming();}if((jj10)&&(jj=12)){zh[0]=jieshou[0]|jieshou[1];zh[1]=jieshou[2]|jieshou[3];zh[2]=jieshou[4]|jieshou[5];zh[3]=jieshou[6]|jieshou[7];zh[4]=jieshou[8]|jieshou[9];zh[5]=jieshou[10]|jieshou[11];UartWrite(zh,6);fengming();}if((jj12)&&(jj=14)){zh[0]=jieshou[0]|jieshou[1];zh[1]=jieshou[2]|jieshou[3];zh[2]=jieshou[4]|jieshou[5];zh[3]=jieshou[6]|jieshou[7];zh[4]=jieshou[8]|jieshou[9];zh[5]=jieshou[10]|jieshou[11];zh[6]=jieshou[12]|jieshou[13];UartWrite(zh,7);fengming();}if((jj14)&&(jj=16)){zh[0]=jieshou[0]|jieshou[1];zh[1]=jieshou[2]|jieshou[3];zh[2]=jieshou[4]|jieshou[5];zh[3]=jieshou[6]|jieshou[7];zh[4]=jieshou[8]|jieshou[9];zh[5]=jieshou[10]|jieshou[11];zh[6]=jieshou[12]|jieshou[13];zh[7]=jieshou[14]|jieshou[15];UartWrite(zh,8);fengming();}if((jj16)&&(jj=18)){zh[0]=jieshou[0]|jieshou[1];zh[1]=jieshou[2]|jieshou[3];zh[2]=jieshou[4]|jieshou[5];zh[3]=jieshou[6]|jieshou[7];zh[4]=jieshou[8]|jieshou[9];zh[5]=jieshou[10]|jieshou[11];zh[6]=jieshou[12]|jieshou[13];zh[7]=jieshou[14]|jieshou[15];zh[8]=jieshou[