#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2017
    Posts
    3
    Rep Power
    0

    The Program Wrote for Collecting Temperature


    Hello~
    The expected function of this project:
    1)、the temperature real-time collection between 51 MCU and DS18B20 has been realized.
    2)、The phone sends index to GSM module and phone will receive needed contents after that.(no temperature)
    The help I need now:
    1). How to send collected temperature to GSM module by serials port? ( The MCU in GSM module is STC12C5A60S2 , and there is a RS232 on MCU.)
    2). I have written a sending program ,but I found that the content which sent to phone isn’t belongs to temperature after texting. Can you help me find questions?
    Code:
    ###sending program on 51#####
    void Init(void) 
    {
    SCON = 0x50; 
    TMOD = 0x20;   
    TH1 = 0xFD;  
    TL1 = 0xFD;   
    TR1 = 1;     
    ES = 1;     
    EA = 1;     
    }
    uint get_tmp()    //get temperature data          
    {
      dsreset();
      delay(1);
      tmpwritebyte(0xcc);
      tmpwritebyte(0xbe);  
      a=tmpread();  //low eight
      b=tmpread();  //high eight
      temp=b;
      temp<<=8;            
      temp=temp|a;    
    // temp=0xFC90;//
    /*  if(temp&0x8000)  
      {
            temp=temp-1; 
            temp=~temp;
      }*/
      f_temp=temp*0.0625; 
      temp=f_temp*10+0.5;  
      return temp;
    }
    void main()//just cut program which is relevant to serials port and main function 
    {
    ES=0; 
    SBUF=b;
    while(!TI);
    TI=0;
    SBUF=a;
    while(!TI);
    TI=0;
    ES=1;
    }     // The a, b is original temperature data which collected by temperature sensor
    #######################
    
    ####The receiving data on GSM module######
    void Second_Serial_Port_Initial(void)        //serials port 2 way 1,data 8 ,start bit 1,stop bit 1,Independent baud rate generator is baud rate generator
    {                                                                                
            S2CON = 0x50;                                            //0101,0000 eight UART,variable baud rate,non parity bit,allow to receive
    //        BRT = 220;                                                   //Independent baud rate generator and timer,install 
            BRT = 0xFD;
            AUXR = 0x11;                        
    //        AUXR = 0x14;
            IE2 = 0x01;                                                  //allow serials port2 to interrupt ,ES2=1
            EA = 1;                                                             //switches interrupt
    }
    
    void Second_Serial_Int() interrupt 8
    {
            unsigned char k = 0,flag=1;
            IE2 = 0x00;                                         //close serials port2 interruption,ES2=0
            k = S2CON;
            k = k & 0x01;
            if(k==1)
                    {        
                            S2CON = S2CON & 0xFE;         //1111,1110 clear serials port2 receive interrupt sign bit
                            if((flag==1)||(j!=0))   
                                    {
                                            Rec_2_Buf[j++] = S2BUF;          //save the received characters
                                            flag=0;
                                            if(j>=2)
                                            {
                                                    rxd= Rec_2_Buf[0];//receive b
                                                    rxd<<=8;
                                                    rxd=rxd|Rec_2_Buf[1]; //receive a adn combine with b
                                                    f_rxd=rxd*0.0625; //integer change into floating points type
                                                    j=0;
                                                    flag=1;
                                         }
                                    }
                    }
            else
                    {
                             S2CON = S2CON & 0xFD;         //1111,1101 clear serials port2 receive interrupt sign bit
                    }
            IE2 = 0x01;                                         //allow serials port2 to interrupt,ES2=1
    }
    #######################3333
    Please help me ! Thanks a lot.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    1
    Rep Power
    0
    I knew a engineer who is an expert in this field . and here is the data sheet you are looking for as DS18B20 , you may check at first .

IMN logo majestic logo threadwatch logo seochat tools logo