Home > other >  Send text messages, with 51 single-chip microcomputer control SIM A6 modules after the program is ru
Send text messages, with 51 single-chip microcomputer control SIM A6 modules after the program is ru

Time:10-30

# include "reg52. H"
# include "temp. H"
# include "string. H"
# include "stdlib. H"

# define uint unsigned int
# define uchar unsigned char
# define Buf_Max 80
# define TELL 13778386860

/* sbit LSA=P2 ^ 2;
Sbit LSB=P2 ^ 3;
Sbit LSC=P2 ^ 4; */


Sbit led1=P2 ^ 0;
Sbit led2=P2 ^ 1;
Sbit led3=P2 ^ 2;
Sbit led4=P2 ^ 3;
Sbit led5=P2 ^ 4;
Sbit led6=P2 ^ 5;
Sbit led7=P2 ^ 6;
Sbit led8=P2 ^ 7;
Sbit duan=P2 ^ 6;
Sbit wei=P2 ^ 7;
Sbit key=P3 ^ 4;

Uchar flag=0, I=0;
Uchar Rec_Buf [Buf_Max];

/* char num=0;
Uchar DisplayData [8]. */
Uchar code smgduan [10]={x5b x3f 0, 0 x06, 0, 0 x4f, 0 x66, 0 x6d, 0 x7d, 0 x07, 0 x7f, 0 x6f};

Void delayms (uint z)
{
Uint x, y;
For (x=z; X> 0; X -)
For (y=110; Y> 0; Y -);
}


/* void datapros (int temp)/read/temperature processing conversion function
{
Float tp.
If (temp<0)//when the negative temperature
{
DisplayData [0]=0 x40;//-
//because the temperature reading is actually the complement of the temperature, so the minus 1, in reverse of the original code
Temp=temp - 1;
Temp=~ temp;
Tp=temp;
Temp=tp 100 + 0.5 * 0.0625 *;

}
The else
{
DisplayData [0]=0 x00;
Tp=temp;//because data processing has a decimal point temperature is assigned to a floating-point variable
//if the temperature is positive, then the original code is positive complement itself
Temp=tp 100 + 0.5 * 0.0625 *;

}
DisplayData [1]=smgduan temp/10000;
DisplayData [2]=smgduan 10000/1000 [temp %];
DisplayData [3]=smgduan [1000/100] temp % | 0 x80;
DisplayData [4]=smgduan 100/10 [temp %];
DisplayData [5]=smgduan [10] temp %;
}



/* void DigDisplay ()//digital tube display function
{
Uchar q;
For (q=0; Q<6; I++)
{
Switch (I)//person, choose the digital tube light,
{
Case (0) :
LSA=0; LSB=0; LSC=0; break;//show a 0
Case (1) :
LSA=1; LSB=0; LSC=0; break;//show the first bit
Case (2) :
LSA=0; LSB=1; LSC=0; break;//show the second
Case (3) :
LSA=1; LSB=1; LSC=0; break;//show the third
Case (4) :
LSA=0; LSB=0; LSC=1; break;//show 4
Case (5) :
LSA=1; LSB=0; LSC=1; break;//show the fifth
}
P0=DisplayData [5] - q;//send data
Delayms (1);//for a period of time between scanning
P0=0 x00;//blanking
}
} */

Void sinit initialize ()//timer
{
SCON=0 x50;//timer 1 10 UART variable allows the receiving
TMOD=0 x20;//eight heavy load mode automatically
TH1=0 XFD;
TL1=0 XFD;
TR1=1;//start the timer 1
IT1=1;//external interrupt control trigger mode allows
EA=1;//open the total interruption
ES=1;//serial port interrupt allows
EX1=1;//timer T1 interruption allows
}

Void CLR_Buf ()//clear the cache content
{
Uchar k;
For (k=0; K{
Rec_Buf [k]=0;
}
i=0;//receive the string pointer refers back to the starting point of the
}

Bit Hand//uchar * (a) to determine whether a cache containing the specified string function
{
If (STRSTR (Rec_Buf, a).=NULL)
return 1;
The else
return 0;
}

Void Send_ASCII (uchar * b)//send character (ASCII) function
{
EA=0;
For (b; * b!='\ 0'; B++)
{
SBUF=* b;
While (TI!=1);
TI=0;
}
EA=1;
}

Void Send_Hex (uchar c)//send characters (hexadecimal) function
{
EA=0;
SBUF=c;
While (TI!=1);
TI=0;
EA=1;
}

Void Send_message ()
{
CLR_Buf ();

Send_ASCII (" AT + CMGF=1 ");
X0d Send_Hex (0);
X0a Send_Hex (0);
Delayms (1000);
while(! Hand (" OK "));
CLR_Buf ();
Led1=~ led1;

Send_ASCII (" AT + CMGS=TELL ");
X0d Send_Hex (0);
X0a Send_Hex (0);
Delayms (1000);
while(! Hand (& gt; "" ));

Led2=~ led2;

Send_ASCII (" temperature: 28.65 ");
Send_Hex (0 x1a);
Delayms (1000);
while(! Hand (" OK "));
CLR_Buf ();
Led4=~ led4;
}














Void main ()
{
Int the led;
Uchar * j, l;
Char o [5];


Sinit ();
while(! Hand (" OK "))
{
Send_ASCII (" ats ");
X0d Send_Hex (0);
X0a Send_Hex (0);
Delayms (2000);
}
CLR_Buf ();
Led1=0;
Delayms (2000);
Send_ASCII SM (" AT + CPMS=\ "", \ "SM " and \ "SM " ");
X0d Send_Hex (0);
X0a Send_Hex (0);
Delayms (2000);
while(! Hand (" OK "));
Send_ASCII (Rec_Buf);

CLR_Buf ();
Led2=0;

Delayms (2000);
Send_ASCII (" AT + CNMI chief=2, 1 ");
X0d Send_Hex (0);
X0a Send_Hex (0);
Delayms (1000);
while(! Hand (" OK "));
CLR_Buf ();
Led3=0;

Delayms (2000);
Send_ASCII (" AT + CMGF=1 ");
X0d Send_Hex (0);
X0a Send_Hex (0);
Delayms (1000);
while(! Hand (" OK "));
CLR_Buf ();
Led4=0;

Delayms (2000);
Send_ASCII (" AT + CMGD=1, 4 ");
X0d Send_Hex (0);
X0a Send_Hex (0);
Delayms (1000);
while(! Hand (" OK "));
CLR_Buf ();
Led5=0;
While (1)
{
/* datapros (Ds18b20ReadTemp ());//the data processing function
DigDisplay (); Digital tube display function *///

If (STRSTR (Rec_Buf, "+ CMTI")!=NULL)
{
Led6=~ led6;
Delayms (2000);
Send_ASCII (" AT + CMGR=1 ");
X0d Send_Hex (0);
X0a Send_Hex (0);
Delayms (1000);
while(! Hand (" OK "));
Led7=~ led7;
If (STRSTR (Rec_Buf, "open led3")!=NULL)
{
Led3=0;
Send_message ();
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related