Microcontroller › 8051 › about receive and transfer program code in 89S51
- This topic has 2 replies, 2 voices, and was last updated 9 years ago by JDQQ8051.
-
AuthorPosts
-
December 2, 2015 at 7:25 pm #4137JDQQ8051Participant
hi all, I need use mobile device control my 8051, this 8051 function can be receive and transfer value.
I use bluetooth (HC-05) UART in 8051. this LCD and module on I2c.
sorry so more question, I need to support plz.
question 1:
I make the LED to extra receive, this function can be run. but, I add this function in my 8051 can't be run. I don't know what happen.
(see the Paragraph Two code)
question 2:
I need transfer value to mobile device, I set the type to ASCII, can run. (DHT11_READ)
but, I use this function set my Ambient Light, can't be run.
(see the Paragraph Three code)
question 3:
I wanna to transfer temperature value to mobile drive, this program can use cell phone set the value to control the Heater and Fan. but, my code can't correct in 8051, so, how should I do?
(see the Paragraph Four code)
this's my code.
Paragraph One:
*************************************************************************************// UARTvoid uart_Init(void) // Baud 9600{SCON = 0x50; // Set Mode (8-bit UART) ; Mode1,SM1=1,REN=1TMOD = 0x20; // Set Mode (8-bit timer with reload);Timer-1,Mode2TH1 = 0xFD; // Baud 9600,B11.0592MHZTR1 = 1; // Start Timer 1 Running}*************************************************************************************// module define typebit DHT11_READ(unsigned char data[5]); // Temperturefloat BH1750_READ(); // Ambient Light*************************************************************************************Paragraph Two:*************************************************************************************// receive char from mobile device.while(RI==0);cmd=SBUF;switch(cmd){case 0x41: //A=ASCIIHeater(0); //heater on/offdelay(1000);RI=0;break;case 0x42: //B=ASCIIHeater(1);delay(1000);RI=0;break;case 0x43: //C=ASCIIFan(0); //fan on/offdelay(1000);RI=0;break;case 0x44: //D=ASCIIFan(1);delay(1000);RI=0;break;}*************************************************************************************Paragraph Three:*************************************************************************************//change type to ASCIIvoid DataDHT_TX(unsigned char Y) //temperture{unsigned char buf_Y[2];unsigned int i;buf_Y[0]=(Y/10)%10+0x30;buf_Y[1]=(Y%10)+0x30;for(i=0;i<2;i++){SBUF=buf_Y;while(TI==0);TI=0;}}// use the function in main()DataDHT_TX((int)Data[2]); // read temperture valuedelay(100);DataDHT_TX((int)Data[0]); // read humiditydelay(100);*************************************************************************************//change type to ASCIIvoid DataBH1750_TX(unsigned char X) //// Ambient Light{unsigned char buf_X[4];unsigned int i;buf_X[0]=(X/100)+0x30;buf_X[1]=(X%100)/10+0x30;buf_X[2]=(X/10)%10+0x30;buf_X[3]=(X%10)+0x30;for(i=0;i<4;i++){SBUF=buf_X;while(TI==0);TI=0;}}*************************************************************************************Paragraph Four code:*************************************************************************************
dhtbuf[2] => temperature value.
First try.
// only case 1, program can complete, correct in 8051.
// use case1 and case 2, program complete, incorrect in 8051.
unsigned char c;
unsigned char *str=dhtbuf;
while(c=*str++)
{
switch(c)
{
case 0:
case 1:
if(dhtbuf[2]>=33)
{
Heater(0);
Fan(1);
delay(500);
} if(dhtbuf[2]==28) break;
case 2:
if(dhtbuf[2]<=23)
{
Heater(1);
Fan(0);
delay(500);
} if(dhtbuf[2]==28) break;
}
}
Sencond try.// only first statement, program can complete, correct in 8051.
// use two statement, program complete, incorrect in 8051.
if(dhtbuf[2]>=33)
{
Heater(0);
Fan(1);
delay(500);
} if(dhtbuf[2]==28) break;
else if(dhtbuf[2]<=23)
{
Heater(1);
Fan(0);
delay(500);
} if(dhtbuf[2]==28) break;*************************************************************************************December 3, 2015 at 10:46 am #13547Ashutosh BhattParticipantyou r having blue tooth, LCD, IIC, but i dont understand what u want to do actually
December 3, 2015 at 2:05 pm #13554JDQQ8051ParticipantI need show the value to my cell phone and LCD.
-
AuthorPosts
- You must be logged in to reply to this topic.