Joke Collection Website - Public benefit messages - 89C51 microcontroller control program for GSM module TC35 (C language)

89C51 microcontroller control program for GSM module TC35 (C language)

#includelt;reg52.hgt;

#includelt;intrins.hgt;

#define uchar unsigned char

#define uint unsigned int

#define RxIn 90 //Define the length of the received array to be 90

uchar code AT[]="AT"; //Handshake signal

uchar code ATE[]="ATE"; //Turn off echo

uchar code AT_CNMI[]="AT CNMI=2, 1"; //Set this set of parameters and display new information directly to Serial port, no storage

uchar code AT_CSCA[]="AT CSCA=\" 8613800571500\""; //Set the service center number

uchar code AT_CMGF[]="AT CMGF =1"; //Set the text message format to text format

uchar code AT_CMGR[]="AT CMGR="; //Read the text message command

uchar code AT_CMGS[] ="AT CMGS=";//Send SMS command

uchar code AT_CMGD[]="AT CMGD=";//Send SMS command

uchar code successfully[]=" Operate Successfully!"; //Send operation success information to the target number

uchar code fail[]="Operate failed, try again!"; //Send operation failure information to the target number

uchar AT_delete[12];

uchar AT_Read[12]; //Used to store and send read SMS instructions

uchar AT_SendNumber[25]; //Used to store and send SMS number command

uchar numberbuf[3]; //Used to save the number of SMS messages

uchar idata SystemBuf[RxIn]; //Storage export reception data

uchar CommandBuf[6]; //Used to store commands

uchar idata state[17]; //Used to store IO port status

uchar idata state1[17]; / /Used to store IO port status

uchar Rx=0;

uint temp; //Record status

uchar temp1; //Used to record P0 port Status

uchar temp2; // Used to record the P2 port status

bit check=0; //Query flag bit

bit receiveready=0; // Receive SMS flag bit

bit sendready=0; //Send SMS ready flag

bit send=0; //Send SMS flag

bit flag =0; //Command flag bit

sbit P3_7=P3^7; //Start GSM startup line to connect to IGT

sbit r

ealy0=P0^0; //Relay 1

sbit key1=P2^0; //Switch 1

sbit key2=P2^1; //Switch 2

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

////////////////////////// ////////////////////////////////////////////////////// //////////////////////////////////////////

/// ////////////////////////////////////////////////////// ////////////////////////////////////////////////////// ////////////

////////////////////////////////// /Function void Delay_ms(uint i); Implementation function: millisecond delay/////////////////////////////////// /

///////////////////////////////////////////// ////////////////////////////////////////////////////// ////////////////////////

///////////////////// ////////////////////////////////////////////////////// ////////////////////////////////////////////////

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

void Delay_ms(uint i)

{

unsigned int j;

for(;igt;0;i--){

for(j=0;jlt;125;j)

{;}

}

}

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

////// ////////////////////////////////////////////////////// ////////////////////////////////////////////////////// ////////

///////////////////////////////////// /////////////////////////////////////////////////

/////////////////////////////////////

//////// ///////////////Function void Start_GSM(void); implementation function: start TC35, turn on TC35//////////////////// ////////////////

//Function details: The P3_7 pin on the microcontroller is connected to the IGT pin of TC35; if you need to start TC35, you must Pin 15 (/IGT) adds a low-level signal with a duration of at least 100ms,

///and the falling edge time of the signal is less than 1ms.

After startup, the signal on pin 15 should remain high.

/////////////////////////////// ////////////////////////////////////////////////////// /////////////////////////////////////

//////// ////////////////////////////////////////////////////// ////////////////////////////////////////////////////// ///////

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

void Start_GSM(void)

{

P3_7=0;

Delay_ms(1000);

P3_7=1;

Delay_ms(1000);

}

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

////////////////// ////////////////////////////////////////////////////// /////////////////////////////////////////////////// p>

//////////////////////////////////////////////// ////////////////////////////////////////////////////// /////////////////////

////////////////////////Function void UART_init; Implementation function: Initialize the serial port////////////////////////////////////////// ////////

///////////////////////////////////// ////////////////////////////////////////////////////// ////////////////////////////////

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

void UART_init (void)

{

TMOD=0x20; //Select timer 1

PCON=0x00 ; ///The baud rate is not doubled

SCON=0x50; //Serial working mode 1 allows serial reception

TH1=0xFD; //Crystal oscillator bit 11.059

2MHZ, select baud rate 9600

TL1=0xFD; //Assign value to the corresponding counter

EA=1; //Total interrupt is enabled

ES =1; //Enable serial interrupt

TR1=1; //Enable timer 1

}

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

/////////////////////////////////////// ////////////////////////////////////////////////////// //////////////////////////////

//////////////// ////////////////////////////////////////////////////// //////////////////////////////////////////////////////

///////////////////////Function void sendchar(uchar ch); implementation function: send one byte of data///// /////////////////////////////////////////////

////////////////////////////////////////////////////// ////////////////////////////////////////////////////// ///////////////

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

void sendchar(uchar ch )

{

SBUF=ch;

while(TI==0);

TI=0;

}

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

////////////////// ////////////////////////////////////////////////////// /////////////////////////////////////////////////// p>

//////////////////////////////////////////////// ////////////////////////////////////////////////////// /////////////////////

////////////////////////Function void sendstring(uchar *p); implementation function: sending characters through the serial port

string///////////////////////////////////////

///// ////////////////////////////////////////////////////// ////////////////////////////////////////////////////// //////////

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

void sendstring(uchar *p)

{

while(*p)

{

sendchar(*p);

p;

}

sendchar(0x0D);

sendchar(0x0A);

}

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

//////////////////////////////////// ////////////////////////////////////////////////////// /////////////////////////////////

///////////// ////////////////////////////////////////////////////// ////////////////////////////////////////////////////// //////

////////////////////Function void receive(void) interrupt 4 using 1; Implementation function: receive data through the serial port /////////////////////////////////

///////////// ////////////////////////////////////////////////////// ////////////////////////////////////////////////////// ///

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

void receive(void) interrupt 4 using 1

{

if(RI)

{

if(Rxlt;RxIn)

{

SystemBuf[Rx ]=SBUF;

Rx ;

}

RI=0;

}

}

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

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

/// ////////////////////////////////////////////////////// ////////////////////////////////////////////////////// ///////////

/////////////////////////////////// ////////////////////////////////////////////////////// //////////////////////////////////////

/////// ////////////Function void GSM_INIT(void); Implementation function: Initialize TC35 module /////////////////////////// //////

//////////////////////////////////////// ////////////////////////////////////////////////////// //////////////////////////////

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

void GSM_INIT(void)

{

LOOP:

Delay_ms(1000);

sendstring (AT);

Delay_ms(1000);

sendstring(ATE);

Delay_ms(1000);

sendstring(AT_CNMI );

Delay_ms(1000);

sendstring(AT_CSCA);

Delay_ms(1000);

for(Rx=0 ; Rxlt; RxIn; Rx )

{

SystemBuf[Rx]=0x00;

}

Rx=0;

p>

sendstring(AT_CMGF);

Delay_ms(1000);

if((SystemBuf[2]=='O')amp;amp;(SystemBuf[3 ]=='K')) //Determine whether the module initialization is successful. If successful, the module will reply "OK" to the microcontroller

{ //If the microcontroller does not receive OK, continue to send initialization instructions/

for(Rx=0; Rxlt; RxIn; Rx)

{

SystemBuf[Rx]=0x00;

}

Rx=0;

}

else

{

for(Rx=0; Rxlt; RxIn; Rx )

{

SystemBuf[Rx]=0x00;

}

Rx=0;

goto LOOP;

}

}

/****** *