We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am new to microcontrollers and this is a program I wrote in order to interface AT89s52 to the hc05 Bluetooth module .The desired output is not obtained what is going wrong here?
#include<stdio.h> #include<reg51.h> sbit x=P2^0; sbit y=P2^1; sbit z=P2^2; char read[5]; void uart() { SCON=0x50; TMOD=0x20; TH1=0xFd; TR1=1; } void feedback() { if(x==1) {SBUF='A' while(TI!); TI=0; SBUF='H' while(TI!); TI=0; } if(y==1) {SBUF='B' while(!TI); TI=0; SBUF='H' while(!TI); TI=0; } if(z==1) {SBUF='C' while(!TI); TI=0; SBUF='H' while(!TI); TI=0; } } void main() { char i,j; x=y=z=0; i=3; j=0; uart(); while(!RI&&i>0) { read[j]=SBUF; RI=0; j++; } if(read[0]=='O'||read[0]=='o'&&read[1]=='N'||read[1]=='n') { switch(read[2]) { case'A': case'a': x=1; break; case'B': case'b': y=1; break; case'C': case 'c': z=1; break; default : SBUF='N'; while(!TI) TI=0; SBUF='O'; while(!TI) TI=0; } } if(read[0]=='O'||read[0]=='o'&&read[1]=='F'||read[1]=='f') { switch(read[2]) { case'A': case'a': x=0; break; case'B': case'b': y=0; break; case'C': case 'c'; z=0; break; default : } } feedback(); }
Did you really have to start a whole new thread?
Could you not have continued in your original thread: http://www.keil.com/forum/62978 ?
So what output, exactly, did you desire?
And what did you actually get?
And what have you done to investigate the problem?
Your code layout is a mess. People will be more inclined to look at well-presented code.
That code, as presented, has at least 6 flat-out syntax errors, so it wouldn'nt even compile.
On top of that it has other logic faults that would make it do rather a different thing than you apparently to want it to:
* It falls off the end of main * it fails to check the number of characters received * it fails to wait for anything before blindly assuming the other side is done talking to it * it contains numerous operator precedence errors