|
|
|
|
#include "Sim900a.h"
|
|
|
|
|
|
|
|
|
|
void DelaySec(int sec)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i , j= 0;
|
|
|
|
|
for(i=0; i<sec; i++)
|
|
|
|
|
{
|
|
|
|
|
for(j=0; j<65535; j++)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SIM900aAnswer(const char *restrict)//<EFBFBD>ȴ<EFBFBD>SIM900a<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
u16 len,t;
|
|
|
|
|
printf(restrict);
|
|
|
|
|
DelaySec(2);
|
|
|
|
|
if(USART_RX_STA&0x8000)
|
|
|
|
|
{
|
|
|
|
|
len=USART_RX_STA&0x3fff;//<EFBFBD>õ<EFBFBD><EFBFBD>˴ν<EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
for(t=0;t<len;t++)
|
|
|
|
|
{
|
|
|
|
|
if(USART_RX_BUF[t]=='O'&&USART_RX_BUF[t+1]=='K')
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
USART_RX_STA=0;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SIM900aSendPhone(const char *restrict)//<EFBFBD>ȴ<EFBFBD>SIM900a<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
u16 len,t;
|
|
|
|
|
printf(restrict);
|
|
|
|
|
DelaySec(2);
|
|
|
|
|
if(USART_RX_STA&0x8000)
|
|
|
|
|
{
|
|
|
|
|
len=USART_RX_STA&0x3fff;//<EFBFBD>õ<EFBFBD><EFBFBD>˴ν<EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
for(t=0;t<len;t++)
|
|
|
|
|
{
|
|
|
|
|
if(USART_RX_BUF[t]==0x3E)
|
|
|
|
|
{
|
|
|
|
|
USART_RX_STA=0;
|
|
|
|
|
memset(USART_RX_BUF,0,USART_REC_LEN);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
USART_RX_STA=0;
|
|
|
|
|
memset(USART_RX_BUF,0,USART_REC_LEN);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int SIM900aSendPhoneAnswer(const char *restrict)//<EFBFBD>ȴ<EFBFBD>SIM900a<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
u16 len,t;
|
|
|
|
|
printf(restrict);
|
|
|
|
|
DelaySec(2);
|
|
|
|
|
USART_SendData(USART1, 0x1a);
|
|
|
|
|
DelaySec(2);
|
|
|
|
|
if(USART_RX_STA&0x8000)
|
|
|
|
|
{
|
|
|
|
|
len=USART_RX_STA&0x3fff;//<EFBFBD>õ<EFBFBD><EFBFBD>˴ν<EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
for(t=0;t<len;t++)
|
|
|
|
|
{
|
|
|
|
|
if(USART_RX_BUF[t]=='O'&&USART_RX_BUF[t+1]=='K')
|
|
|
|
|
{
|
|
|
|
|
USART_RX_STA=0;
|
|
|
|
|
memset(USART_RX_BUF,0,USART_REC_LEN);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
USART_RX_STA=0;
|
|
|
|
|
memset(USART_RX_BUF,0,USART_REC_LEN);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SIM900aInit(void)//SIM900a<EFBFBD>ij<EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
SIM900aAnswer("AT+CMGF=1\r\n");
|
|
|
|
|
USART_RX_STA=0;
|
|
|
|
|
|
|
|
|
|
SIM900aAnswer( "AT+CSCS=\"GSM\"\r\n");
|
|
|
|
|
USART_RX_STA=0;
|
|
|
|
|
|
|
|
|
|
SIM900aAnswer("AT+CSMP=17,167,0,240\r\n");
|
|
|
|
|
//SIM900aAnswer("AT+CSMP=17,167,2,25\r\n");
|
|
|
|
|
USART_RX_STA=0;
|
|
|
|
|
|
|
|
|
|
SIM900aAnswer("AT+CMGD=1\r\n");
|
|
|
|
|
USART_RX_STA=0;
|
|
|
|
|
|
|
|
|
|
delay_ms(1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SIM900aSend(char* str)
|
|
|
|
|
{
|
|
|
|
|
SIM900aAnswer("AT+CMGS=\"11111111111\"\r\n");
|
|
|
|
|
USART_RX_STA=0;
|
|
|
|
|
DelaySec(2);
|
|
|
|
|
SIM900aAnswer(str);
|
|
|
|
|
USART_SendData(USART1,0x1a);
|
|
|
|
|
USART_RX_STA=0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|