完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
请问一下,我这个程序编译的时候,没有任何错误,逻辑上也行得通,之前没添加字符转换为数值的时候,单片机接收到数据还可以返回数据的,但是加了后,就没反应了.protues里面用终端可以检测到数据,但是单片机死活没反应。 急啊!!搞了几天了...... #include "AT89X51.h" #include "math.h" #include "head.h" int delay(); ***it RS=0xA0; ***it RW=0xA1; ***it E=0xA2; ***it K1=P2^5; ***it K2=P2^3; ***it Key=P2^6; char SpeedChar[]="SPEED(n/min):"; char StateChar[]="ZS_SPEED:"; char SPEED[3]="050"; char SPEED_R[3]="000"; char js[16]; char fss[16]; unsigned int RunSpeed=50; unsigned int x=0; //int n; //unsigned int M1=0; //unsigned int M2=0; //unsigned int Z=10; unsigned int i2=0; unsigned int n1=0,n2=0; unsigned char a,flag; unsigned char fs,js_a,m,n,kk=0; unsigned int ii; unsigned int k=0; void sendChar(uchar Value); unsigned int fsws=0; main() { TMOD=0x26; EA=1; TH0=0xff; TL0=0xff; ET0=1; TR0=1; IT0=1; EX0=1; //TH1 = 0xfd; TH1 = 0xfd; TL1 = 0xfd; REN = 1; SM0 = 0; SM1 = 1; EA = 1; ES = 1; TR1 = 1; P2_5=0; Key=1; inti_lcd(); DoSpeed(); ShowState(); P1=0x01; while(1){ fas(); if(K2==0){ clock(RunSpeed); P2_4=P2_4^0x01; //P0_0=P0_0^0x01; } } } void SpeedUp() interrupt 1 { if(RunSpeed>=12) RunSpeed=RunSpeed-2; DoSpeed(); P1=0x01; cmd_wr(); ShowState(); } void SpeedDowm() interrupt 0 { if(RunSpeed<=100) RunSpeed=RunSpeed+2; DoSpeed(); P1=0x01; cmd_wr(); ShowState(); } void ser_int (void) interrupt 4 { RI = 0; js[k]=SBUF; flag=1; if(js[k]=='#') { m=0; for(ii=0;ii m=m*10+(js[k]-48); k=0; } else k++; } void fas() { if(flag==1) { ES=0; for(fsws=0;fsws<3;fsws++) { SBUF=SPEED[fsws]; while(!TI); TI=0; } //SBUF=m; ES=1; flag=0; } js_a=js[k]; if(js_a=='Z'){P2_3=1;P2_5=1;} //停止 if(js_a=='A'){P2_3=0;} //启动 if(js_a=='C') //正转 { unsigned char x_js=js_a; if(x_js=='C') { P2_5=0; } } if(js=='B') //反转 { unsigned char y_js=js_a; if(y_js=='B') { P2_5=1; } } if(js_a=='Y') //减速 { if(RunSpeed<=1000) RunSpeed=RunSpeed+2; DoSpeed(); } if(js_a=='E') //加速 { if(RunSpeed>=12) RunSpeed=RunSpeed-2; DoSpeed(); } else { m=RunSpeed; DoSpeed(); } } int delay() { int a; start: RS=0; RW=1; E=0; for(a=0;a<2;a++); E=1; P1=0xff; if(P1_7==0) return 0; else goto start; } void inti_lcd() { P1=0x38; cmd_wr(); delay(); P1=0x01; cmd_wr(); delay(); P1=0x0f; cmd_wr(); delay(); P1=0x06; cmd_wr(); delay(); P1=0x0c; cmd_wr(); delay(); } void cmd_wr() { RS=0; RW=0; E=0; E=1; } void show_lcd(int i) { P1=i; RS=1; RW=0; E=0; E=1; } void ShowState() { int i=0; while(SpeedChar[i]!=' |