EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / about receive and transfer program code in 89S51

about receive and transfer program code in 89S51

|

Microcontroller › 8051 › about receive and transfer program code in 89S51

  • This topic has 2 replies, 2 voices, and was last updated 10 years, 4 months ago by JDQQ8051.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • December 2, 2015 at 7:25 pm #4137
    JDQQ8051
    Participant

    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:

    *************************************************************************************
    // UART
    void uart_Init(void)  // Baud 9600
    {
            SCON = 0x50;  // Set Mode (8-bit UART) ; Mode1,SM1=1,REN=1 
            TMOD = 0x20;  // Set Mode (8-bit timer with reload);Timer-1,Mode2
            TH1 = 0xFD;     // Baud 9600,B11.0592MHZ
            TR1 = 1;           // Start Timer 1 Running
    }
    *************************************************************************************
    // module define type
    bit DHT11_READ(unsigned char data[5]); // Temperture
     
    float BH1750_READ(); // Ambient Light
    *************************************************************************************
     
    Paragraph Two:
    *************************************************************************************
    // receive char from mobile device.
    while(RI==0);
    cmd=SBUF;
     
    switch(cmd)
    {
      case 0x41:      //A=ASCII
        Heater(0);     //heater on/off
        delay(1000);
        RI=0;
        break;
      case 0x42:      //B=ASCII
        Heater(1);
        delay(1000);
        RI=0;
        break;
      case 0x43:      //C=ASCII
        Fan(0);         //fan on/off
        delay(1000);
        RI=0;
        break;
      case 0x44:      //D=ASCII
        Fan(1);
        delay(1000);
        RI=0;   
        break;
    }
    *************************************************************************************
     
    Paragraph Three:
    *************************************************************************************
    //change type to ASCII
    void 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 value 
     delay(100);
    DataDHT_TX((int)Data[0]); // read humidity
    delay(100);
    *************************************************************************************
    //change type to ASCII
    void 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 #13547
    Ashutosh Bhatt
    Participant

    you r having blue tooth, LCD, IIC, but i dont understand what u want to do actually

    December 3, 2015 at 2:05 pm #13554
    JDQQ8051
    Participant

    I need show the value to my cell phone and LCD.

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Getting into an LED bulb April 21, 2026
  • understanding of resonance in time domain April 21, 2026
  • Beginner Questions About CNC Machines – G-code, Control Systems & Accuracy April 21, 2026
  • A Must-Watch Video Showing Dangerous Construction of Cheap Lithium-Ion Cells April 21, 2026
  • S1MJ ? April 20, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise