# include "SIM900A. H"
#include
Typedef unsigned char uchar;
Typedef unsigned int uint;
//note that both receives the signal and sends out signals will be into the interrupt service routine
/* initialization program (must be used, otherwise unable to send and receive), the second application will use timer 1 */
Void SerialInti (void)//initialization program (must be used, otherwise unable to send and receive)
{
TMOD=0 x21;//timer 1 operation mode 2:8 automatically reload timers
TH1=0 XFD;//load the initial value, baud rate 9600
TL1=0 XFD;
TR1=1;//open the timer
SM0=0;//set the serial communication mode, (10 for a send, baud rate variable, controlled by the timer overflow ratio of 1)
The SM1=1;//(ditto) in this mode, the timer sends a bit data overflow once
REN=1;//serial receiving allowed (first to set up open another serial sm0sm1 allowed)
EA=1;//always interrupt
ES=1;//open the serial port interrupt
}
Void Uart1BYTE uchar (temp)
{
SBUF=temp;
while(! TI);//waiting to send complete signal appears (TI=1)
TI=0;
}
//serial port for sending char array, termination date/0 will stop
Void Uart1Sends uchar * (STR)
{
While (* STR!='\ 0')
{
while(! TI);//waiting to send complete signal appears (TI=1)
TI=0;
Str++;
}
}
//delay function is about 1 s clock
Void DelaySec (int SEC)
{
Uint I, j=0;
for(i=0; i
For (j=0; J<65535; J++)
{
}
}
}
Void SIM900A (void)
{
Uart1Sends (" AT + CSQ \ r \ n ");
DelaySec (1);//delay of 1 second
Uart1Sends (" AT + CMGF=1 \ r \ n ");//text mode
DelaySec (1);//delay of 1 second
Uart1Sends (" AT + CSMP=17167,2,25 \ r \ n ");//set the work mode
DelaySec (1);//delay of 1 second
Uart1Sends (" AT + CSCS=\ "UCS2 " ");//UCS2 code charset
DelaySec (1);
Uart1Sends (" AT + CMGS=\ "00310037003800330032003100370032003000380033 " ");//unicode number
DelaySec (3);
8 b66544aff0179ef6c348d859650 Uart1Sends (" ");//content unicode code
DelaySec (3);//delay 3 seconds
Uart1BYTE (0 x1a);
}
/* this is the main program culvert water warning system, add SIM900A () after the function is cool, not combined with the former running */
# include "ds18b20. H"
# include "the CSB. H"
# include "LCD. H"
#include
# include "is the main. H"
# include "SIM900A. H"
Typedef unsigned char uchar;
Typedef unsigned int uint;
Uint temp1 [3].
Uchar count=0;
Uint a1=0, Threshold1=15, Threshold2=20;
//used port p0.0 p0.1, p0.2, p0.3, p0.4, p0.5, p0.6, p0.7, p2.7, p2.6
//p0.0 p0.1 (ultrasonic) p0.2 ~ p0.5 (LCD) p2.0-2.3 (keys) p0.6 (DS18b20)
Void main (void)
{
Initc ();//ultrasonic initialization
The init ();//LCD initialization
SerialInti ();
While (1)
{
The switch (P2)
{
Case 0 xfe: {Threshold1=Threshold1 + 1; Display1 (); break; }
Case 0 XFD: {Threshold1=Threshold1-1; Display1 (); break; }
Case 0 XFB: {Threshold2=Threshold2 + 1; Display2 (); break; }
Case 0 xf7: {Threshold2=Threshold2-1; Display2 (); break; }
Default: break;
}
While (the count & lt; 3)
{
Temp1=[count] loop ();
count++;
}
A1=(uint) (temp1 temp1 [0] + [1] + temp1 [2])/3;
A1=400 - a1;
Count=0;
If (a1 & gt; Threshold2)
{
SIM900A ();//on the right here, doesn't appear like this, in addition to send wrong, may be the whole program is also influenced by the interrupt,
The display ();
}
Else if (a1 & gt; Threshold1)
{
The display ();//LCD display program
}
The else
{
The display ();
}
Delay (3000);
}
}//0: plus, decrease 1:
Void Serial_interrupt () interrupt 4//serial port interrupt
{
If (RI)
RI=0;//reset interrupt reception, said it would continue to receive
If (TI)
TI=0;
}
/* this program is written on my own to send Chinese messages, lose, but to the Chinese text AT statements for English messages will succeed to receive SMS */
#include
# define uchar unsigned char
# define uint unsigned int
Code char str1 []="AT + CSQ \ r \ n";
Code char str2 []="AT + CSCS=" UCS2 \ \ r \ n ";
Code char str3 []="AT + CMGF=1 \ r \ n";
Code char str4 []="AT + CSMP=17167,2,25";
Code char str5 []="AT + CMGS=" 00310037003800330032003100370032003000380033 \ "\ r \ n";//phone number unicode code
8 b66544aff0179ef6c348d859650 code char str6 []="";//send content unicode code
Code char str7 []="AT + CMGD=1";
Void DelaySec (int SEC)
{
Uint I, j=0;
for(i=0; i
For (j=0; J<65535; J++)
{
}
}
}
Void uart_init (void)
{
TMOD=0 x20;
SCON=0 x40;
TH1=0 XFD;
TL1=0 XFD;
TR1=1;
ES=1;
EA=1;
}
Void sendonebyte (uint c)
{
ES=0;
SBUF=c;
while(! TI);
TI=0;
ES=1;
}
Void main (void)
{
Uint I=0;
uart_init();
while(str1[i]!='\ 0')
{
Sendonebyte (str1 [i++]);
}
DelaySec (1);
i=0;
While (str2 [I]!='\ 0')
{
Sendonebyte (str2 [i++]);
}
DelaySec (1);
i=0;
While (str3 [I]!='\ 0')
{
Sendonebyte (str3 [i++]);
}
DelaySec (1);
i=0;
While (str4 [I]!='\ 0')
{
Sendonebyte (str4 [i++]);
}
DelaySec (1);
i=0;
DelaySec (5);
While (str5 [I]!='\ 0')
{
Sendonebyte (str5 [i++]);
}
DelaySec (1);
i=0;
While (str6 [I]!='\ 0')
{
Sendonebyte (str6 [i++]);
}
DelaySec (1);
i=0;
Sendonebyte (0 x1a);
While (str7 [I]!='\ 0')
{
Sendonebyte (str7 [i++]);
}
DelaySec (1);
i=0;
While (1);
}
Void uart_isr (void) interrupt 4
{
If (RI)
{
RI=0;
}
The else
TI=0;
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull