heicad 发表于 2022-5-12 20:44 我把MCU拆掉后还是亮的 |
模块只接电源 其他线路完全断开 还亮吗?还亮的话 估计模块坏掉了 |
lhzw2001 发表于 2022-5-12 15:22 那是不是意味着RXD悬空了 |
我的板子也是这样的,我有上拉rxd引脚 |
雪玉寐影 发表于 2022-5-12 13:43 我把单片机拆下来后,RXD是一直亮,但TXD不亮,这不正常吧 |
ffffssss 发表于 2022-5-12 10:57 上电默认高电平! |
这是源代码,没有让他一直亮的地方吧 #include <STC12C5A60S2.H> #define uint unsigned int #define uchar unsigned char #include"1602.h" #include"uart.h" #include"math.h" sbit qh=P2^0; sbit ql=P2^1; sbit JDQ=P2^4; sbit led=P1^4; void init(); void display(); uchar flag,i,k; uint dy,dl,yggl,pl,ydl,gy,wggl,szgl; bit key_flag,dis_flag,clr_flag,send_flag,duan_flag=1; uchar code buf[]={0x01,0x04,0x00,0x00,0x00,0x0a,0x70,0x0d}; uchar code shuju[]={"0123456789"}; void main() { chushihua(); init(); uartInit(); Uart2Init(); dis_flag=1; JDQ=1; while(1) { led=!led; led=!led; if(duan_flag) JDQ=0; if(send_flag) { send_flag=0; sendData(buf); } if(!qh&&!key_flag) { flag++; if(flag==4) flag=0; w_com(0x01); dis_flag=1; key_flag=1; } if(qh&&ql) key_flag=0; if(!ql&&!key_flag) { send(0x01);//清零命令 send(0x42);//清零命令 send(0x80);//清零命令 send(0x11);//清零命令 dis_flag=1; key_flag=1; } for(i=0;i<40;i++) { if(tmp2[i]==0xaa&&tmp2[i+1]==0xf0) { send(0x01); send(0x42); send(0x80); send(0x11); w_com(0x01); for(k=0;k<40;k++) tmp2[k]=0; break; dis_flag=1; key_flag=1; } if(tmp2[i]==0xbb) { JDQ=!JDQ; for(k=0;k<40;k++) tmp2[k]=0; break; } if(tmp1[i]==0x01&&tmp1[i+1]==0x04&&tmp1[i+2]==0x14) { dy=tmp1[i+3]*256+tmp1[i+4];//电压 dl=tmp1[i+5]*256+tmp1[i+6];//电流 yggl=tmp1[i+9]*256+tmp1[i+10];//有功功率 ydl=tmp1[i+13]*256+tmp1[i+14];//用电量 pl=tmp1[i+17]*256+tmp1[i+18];//频率 gy=tmp1[i+19]*256+tmp1[i+20];//功率因素 szgl=(dy/10.0)*(dl/1000.0)*10;//视在功率 if(yggl>=szgl) wggl=0; else wggl=sqrt((szgl/10.0)*(szgl/10.0)-(yggl/10.0*yggl/10.0)); dis_flag=1; send_str("#dy:"); send2(dy/1000+0x30); send2(dy%1000/100+0x30); send2(dy%100/10+0x30); send2('.'); send2(dy%10+0x30); send2('V'); send2('*'); send_str("#dl:"); send2(dl/1000+0x30); send2('.'); send2(dl%1000/100+0x30); send2(dl%100/10+0x30); send2(dl%10+0x30); send2('A'); send2('*'); send_str("#pl:"); send2(pl/100+0x30); send2(pl%100/10+0x30); send2('.'); send2(pl%10+0x30); send_str("Hz"); send2('*'); send_str("#ydl:"); send2(ydl/1000+0x30); send2('.'); send2(ydl%1000/100+0x30); send2(ydl%100/10+0x30); send2(ydl%10+0x30); send_str("kWh"); send2('*'); send_str("#yg:"); send2(yggl/1000+0x30); send2(yggl%1000/100+0x30); send2(yggl%100/10+0x30); send2('.'); send2(yggl%10+0x30); send2('W'); send2('*'); send_str("#wg:"); send2(wggl/100+0x30); send2(wggl%100/10+0x30); send2(wggl%10+0x30); send_str("var"); send2('*'); send_str("#sz:"); send2(szgl/1000+0x30); send2(szgl%1000/100+0x30); send2(szgl%100/10+0x30); send2('.'); send2(szgl%10+0x30); send_str("V.A"); send2('*'); send_str("#gy:"); send2(gy/100+0x30); send2('.'); send2(gy%100/10+0x30); send2(gy%10+0x30); send2('!'); delay(20000); delay(20000); delay(20000); delay(20000); delay(20000); /*for(k=0;k<40;k++) tmp1[k]=0;*/ break; } } if(dis_flag) { display(); dis_flag=0; } if(qh&&ql) key_flag=0; } } void init() { TMOD=0x01; TH0=0x3c; TL0=0xb0; EA=1; ET0=1; TR0=1; } void display() { if(flag==0) { w_com(0x80); w_date('U'); w_date(':'); w_date(shuju[dy/1000]); w_date(shuju[dy%1000/100]); w_date(shuju[dy%100/10]); w_date('.'); w_date(shuju[dy%10]); w_date('V'); w_com(0x80+0x40); w_date('I'); w_date(':'); w_date(shuju[dl/1000]); w_date('.'); w_date(shuju[dl%1000/100]); w_date(shuju[dl%100/10]); w_date(shuju[dl%10]); w_date('A'); } else if(flag==1) { w_com(0x80); w_date('f'); w_date(':'); w_date(shuju[pl/100]); w_date(shuju[pl%100/10]); w_date('.'); w_date(shuju[pl%10]); w_date('H'); w_date('z'); w_com(0x80+0x40); w_date('Y'); w_date(':'); w_date(shuju[ydl/1000]); w_date('.'); w_date(shuju[ydl%1000/100]); w_date(shuju[ydl%100/10]); w_date(shuju[ydl%10]); w_date('k'); w_date('W'); w_date('h'); } else if(flag==2) { w_com(0x80); w_date('P'); w_date(':'); w_date(shuju[yggl/10000]); w_date(shuju[yggl/1000%10]); w_date(shuju[yggl/100%10]); w_date(shuju[yggl/10%10]); w_date('.'); w_date(shuju[yggl%10]); w_date('w'); w_com(0x80+0x40); w_date('Q'); w_date(':'); w_date(shuju[wggl/100]); w_date(shuju[wggl%100/10]); w_date(shuju[wggl%10]); w_date('v'); w_date('a'); w_date('r'); } else if(flag==3) { w_com(0x80); w_date('S'); w_date(':'); w_date(shuju[szgl/1000]); w_date(shuju[szgl%1000/100]); w_date(shuju[szgl%100/10]); w_date('.'); w_date(shuju[szgl%10]); w_date('V'); w_date('.'); w_date('A'); w_com(0x80+0x40); w_date('c'); w_date('o'); w_date('s'); w_date(':'); w_date(shuju[gy/100]); w_date('.'); w_date(shuju[gy%100/10]); w_date(shuju[gy%10]); } } uchar count; void timer()interrupt 1 { TH0=0x3c; TL0=0xb0; count++; if(count==20) { count=0; send_flag=1; } } |
lkc8210 发表于 2022-5-12 10:43 RXD引脚接的不是单片机的RXD引脚吗 |
如果你的单片机的TxD脚正输出高电平 Led会亮是正常的 |