Joke Collection Website - Public benefit messages - 5 1 what is the simplest program for connecting a single chip microcomputer with sim900a?

5 1 what is the simplest program for connecting a single chip microcomputer with sim900a?

/************************************************************

Program description:

After the program runs, if the gprs module finds the signal of the service provider, it will call the designated phone.

1. Connect your own 5 1 serial port of single chip microcomputer 1 to tx rx gnd of GSM.

2. Find the #define in front of the program, modify the SCM configuration according to the instructions, and then compile the program.

download a program

3. Press the module reset button to start the module, wait for the signal light to blink slowly, and reset the microcontroller.

4. Wait for the transmission to succeed

*************************************************************/

# include & ltREGX52。 H & gt

# Define uchar unsigned characters

# Define uint unsigned integer

//The following is the LED configuration on the board. Replace Px_x with your own corresponding foot.

# define LED 1_ON P 1_0 = 0.

# define led 1 _ OFF p 1 _ 0 = 1

# define LED2_ON P 1_ 1 = 0.

# define led 2 _ OFF p 1 _ 1 = 1

# define LED3_ON P 1_2 = 0.

# define led 3 _ OFF p 1 _ 2 = 1

# define LED4_ON P 1_3 = 0.

# define led 4 _ OFF p 1 _ 3 = 1

//The following is the crystal oscillator size of your 5 1 single chip microcomputer.

# define FOSC _ 1 10592m

//#define FOSC_ 12M

//The following is the content sent to the mobile phone after the phone is turned on, and the number sent is modified in the program.

uchar SMS _ text【】=“ 123“;

//Note that whether the signal is received or sent, it will enter the interrupt service program.

/* Initialize the program (it must be used, otherwise it cannot be sent or received), and the second program will use the timer 1*/

Void serial inti()// initializer (must be used, otherwise it cannot be sent or received)

{

TMOD = 0x 20; //Timer 1 Working mode 2:8-bit automatic overload timer

# ifdeffosc _ 12m// Set different values according to the size of the crystal oscillator here to initialize the serial port.

th 1 = 0x F3; //Load the initial value at baud rate of 2400.

TL 1 = 0x F3;

# Otherwise

th 1 = 0x FD; //Load the initial value at a baud rate of 9600.

TL 1 = 0x FD;

# endif//SOC _/kloc-end of 0/2m

tr 1 = 1; //Turn on the timer

SM0 = 0; //Set the working mode of serial communication (10 is one transmission with variable baud rate, which is controlled by the overflow rate of timer 1).

sm 1 = 1; //(ditto) In this mode, once the timer overflows, one bit of data will be sent.

REN = 1; //serial receive enable bit (set sm0sm 1 before turning on serial enable)

EA = 1; //Open host interrupt

ES = 1; //Open serial port interrupt

}

/* Serial communication is interrupted and will enter */

Invalid serial interrupt () interrupt 4

{

//a = SBUF;

P2 = SBUF;

RI = 0; //The reception interrupt signal is cleared, indicating that reception will continue.

//flag = 1; //symbol for entering an interrupt

}

void UART 1 send(uchar c)

{

SBUF = c;

And (! TI); //Wait for the transmission completion signal (TI= 1) to appear.

TI = 0;

}

//Serial port sends char array continuously, and stops when it encounters the termination number /0.

void UART 1 sends(uchar * str)

{

while(* str! ='\0')

{

SBUF = * str

And (! TI); //Wait for the transmission completion signal (TI= 1) to appear.

TI = 0;

str++;

}

}

//The delay function is about 1s, but it is not allowed when the delay is large. ...

Invalid delay time (middle second)

{

uint i,j = 0;

for(I = 0; I & ltseci++)

{

for(j = 0; j & lt65535; j++)

{

}

}

}

void main()

{

uchar I = 0;

led 1 _ OFF;

LED2 _ OFF

LED3 _ OFF

LED4 _ OFF

serial inti();

while( 1)

{

led 1 _ ON;

LED2 _ OFF

UART 1 sends(“AT+CMGF = 1 \ r“);

Dreisek (3); //Delay for 3 seconds

UART 1 sends(“AT+CSCS =“GSM“\ r“);

Dreisek (3); //Delay for 3 seconds

UART 1 sends(“AT+CSMP = 17, 167,0,250 \ r“); //Device SMS mode (auto-saving mode of mobile phone)

//UART 1 sends(“AT+CSMP = 17, 167,0,240 \ r“); //Device SMS mode (non-auto-saving mode of mobile phone)

Dreisek (3); //Delay for 3 seconds

UART 1 sends(“AT+CMGS =“ 18332563682“\ r“);

Dreisek (5); //Delay for 3 seconds

UART 1 sends(SMS _ text);

UART 1 send(0x 1a);

LED2 _ ON

led 1 _ OFF;

Dreisek (15); //Delay for 20 seconds

}

}

//You can connect p3.0 and p3. 1.