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(); }
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.