#include "reg51.h"
#include "intrins.h"
#include "stdio.h"
#include "math.h"
#include "stdlib.h"
#include "string.h"
#include "absacc.h"
#define uint unsigned int
#define uchar unsigned char
uchar code SMS_send[]="AT+CMGS=";
uchar code SMS_send_AT[]="AT";
uchar code GMS[]="AT+CMGF=1";
uchar code SMS_PDU[]="AT+CSQ";
uchar Byte_num[]="\"+86**************\"";
uchar code Sms2_Pdu[]="warning";
uchar date;
void delay2(uint n) //延时
{
unsigned int i,j;
for(i=0;i<n;i++);
for(j=0;j<123;j++);
}
void Print_Char(uchar dat) //发送一个字符
{
ES = 0;
TI=0;
SBUF = dat;
while(!TI);
TI = 0;
ES = 1;
}
void Print_Str(uchar *str) //一个字节
{
while(*str!='\0')
{
Print_Char(*str++);
}
}
void Ini_UART() //初始化 设置波特率9600
{
PCON&=0x00;
SCON=0x50;
TMOD=0x20;
TL1=0xfd;
TH1=0xfd;
TF1=1;
ET0=1;
TR1=1;
ES=1;
EA=1;
}
void GSM_PDU()
{
Print_Str(SMS_send_AT);
Print_Str("\r\n");
delay2(5000);delay2(5000);delay2(5000);delay2(5000);delay2(5000);
Print_Str(SMS_PDU);
Print_Str("\r\n");
delay2(1000);delay2(5000);delay2(5000);delay2(5000);delay2(5000);delay2(5000);delay2(5000);
Print_Str(GMS);
Print_Str("\r\n");delay2(5000);delay2(5000);delay2(5000);delay2(5000);delay2(5000);
ES=1;
delay2(6000);
}
void GSM_PDU_SMS()
{
Print_Str(SMS_send);
Print_Str(Byte_num);
Print_Str("\r\n");
delay2(900);
delay2(5000);delay2(5000);delay2(5000);delay2(5000);delay2(5000);
Print_Str(Sms2_Pdu);
delay2(500);delay2(5000);delay2(5000);delay2(5000);delay2(5000);
Print_Char(0x1a);
delay2(5000);
delay2(5000);
Print_Str("\r\n");
}
void main()
{
Ini_UART();
GSM_PDU();
GSM_PDU_SMS();
}
void inter() interrupt 4
{
date = SBUF;
if(RI)
RI = 0;
}
|