GSM SIM900A Modem
/*
* Project name:
GSM SIM900 MODEM
* Copyright
(c) Researchdesignlab.com
* Description:
* Test configuration:
MCU: AT89S52
Dev.Board: 8051
Oscillator: 11.0592 MHz
Software: Keil uVision3
*/
#include"reg51.h"
#include"string.h"
unsigned char SCI_ReceiveByte( void );
unsigned char uart_rd;
void TRANSMIT(unsigned char *string);
void transmit_byte(unsigned char byte);
void DELAY();
sbit SENSOR=P1^0;
sbit POWER_KEY=P2^0;
void main()
{
POWER_KEY=0;
DELAY();
TMOD=0X20;
TH1=0XFD;
SCON=0X50;
TR1=1;
DELAY();
while(1)
{
DELAY();
DELAY();
DELAY();
if(SENSOR==1)
{
POWER_KEY=1;
DELAY();
DELAY();
DELAY();
POWER_KEY=0;
uart_rd=0;
while(uart_rd!='C')
{
uart_rd = SCI_ReceiveByte();
}
uart_rd=0;
while(uart_rd!='a')
{
uart_rd = SCI_ReceiveByte();
}
uart_rd=0;
while(uart_rd!='l')
{
uart_rd = SCI_ReceiveByte();
}
uart_rd=0;
while(uart_rd!='l')
{
uart_rd = SCI_ReceiveByte();
}
DELAY();
DELAY();
DELAY();
TRANSMIT("AT");
transmit_byte(13);
transmit_byte(10);
DELAY();
DELAY();
DELAY();
TRANSMIT("AT+CMGF=1");
transmit_byte(13);
transmit_byte(10);
DELAY();
DELAY();
DELAY();
TRANSMIT("AT+CMGS=\"7795003031\"");
transmit_byte(13);
transmit_byte(10);
DELAY();
DELAY();
DELAY();
TRANSMIT("SENSOR ACTIVATED");
transmit_byte(26);
uart_rd=0;
while(uart_rd!='K')
{
uart_rd = SCI_ReceiveByte();
}
POWER_KEY=1;
DELAY();
DELAY();
DELAY();
POWER_KEY=0;
DELAY();
DELAY();
DELAY();
DELAY();
DELAY();
DELAY();
}
DELAY();
DELAY();
DELAY();
}
}
void DELAY()
{
unsigned int X=60000000;
while(X--);
}
void transmit_byte(unsigned char byte)
{
SBUF=byte;
while(!TI);
TI=0;
}
void TRANSMIT(unsigned char *string)
{
while(*string)
transmit_byte(*string++);
}
unsigned char SCI_ReceiveByte( void )
{
unsigned char byte;
while(RI!=1);
byte = SBUF;
RI=0;
return byte;
}