?? gsm.c
字號:
Serial1_Inter_Open();
}
void clear_database(void)
{
UINT i,j;
for(i=0;i<8;i++)
for(j=0;j<256;j++)
PHONE_number[i][j][0]=0;
}
void rec_success_for_PC(void) //告訴PC接受數(shù)據(jù)成功,可以發(fā)下一個了
{
UCHAR data lenth,commandcode;
commandcode =0x13;
lenth=1; //數(shù)據(jù)長度
TxBuf1[0]=0x32;
send_to_module1(commandcode,lenth);
}
void rec_err_for_PC(void) //告訴PC接受數(shù)據(jù)失敗,重發(fā)所有
{
UCHAR data lenth,commandcode;
commandcode =0x13;
lenth=1; //數(shù)據(jù)長度
TxBuf1[0]=0x33;
send_to_module1(commandcode,lenth);
}
//=======================================
void led1_open()
{ led1=1; }
void led1_close()
{ led1=0; }
void led2_open()
{ led2=1; }
void led2_close()
{ led2=0; }
void led3_open()
{
led3=1;
}
void led3_close()
{
led3=0;
}
void laba_close()
{
bell=1;
}
void laba_ring_1_time()
{
UCHAR data delay;
bell=0;
for(delay=0;delay<60;delay++)
Delay10ms();
bell=1;
}
void laba_ring_3_times()
{
UCHAR data times,delay;
for(times=0;times<3;times++)
{
bell=0;
for(delay=0;delay<30;delay++)
Delay10ms();
bell=1;
for(delay=0;delay<30;delay++)
Delay10ms();
}
}
//===================================
//***************延時1秒***********
void Delay_1S(void)
{
UCHAR idata i;
for(i=0;i<100;i++) Delay10ms();
//WDT_RST();
}
//=================================
//********延時子程序*********
//*********************************
void Delay10ms()
{
UINT idata i;
for(i=0;i<10000;i++);
}
void start_timer0(void)
{
timer0_counter=0;
CKCON &= 0xF7; //設(shè)置定時器0為系統(tǒng)時鐘12分頻T0M=0
TH0=0x00;
TL0=0x00;
TMOD = 0x01; //設(shè)置定時器0為模式1(定時器1為模式0)
TCON &= 0xDF; //清定時器0溢出中斷標志TF0
ET0=1; //允許定時器0溢出中斷
TCON |=0x10; //開啟定時器0
}
void close_timer0(void)
{
timer0_counter=0;
TCON &=0xEF;
ET0=0;
}
void time0(void) interrupt 1
{
UCHAR idata i; //發(fā)生error
if(timer0_counter++>250)
deal_with_error();
// RSTSRC |= 0x02; // 重起
}
void deal_with_error(void)
{
led1_open();
led2_open();
led3_open();
while(1);
}
//*********************************sms函數(shù)****************************************
void start_GSM(void)
{
UINT idata i;
// led2_close();
led2_open();
for(i=0;i<5;i++) Delay_1S();
power_down();
start_tc35();
// led2_open();
Delay_1S();
for(i=0;i<10;i++) Delay_1S();
AT_SEND();
Delay_1S();
Signal_test();
Delay_1S();
AT_cmgf();
Delay_1S();
//{
//AT_cmgs();
//SEND_sms(49);
//}
led2_close();
}
void start_tc35(void)
{
Delay_1S();
Delay_1S();
Delay_1S();
Delay_1S();
Delay_1S();
Delay_1S();
Delay_1S();
Delay_1S();
Delay_1S();
IGT=0;
Delay_1S();
IGT=1;
}
void AT_SEND(void)
{
UCHAR idata i,error_counter;
error_counter=0;
while(1)
{
TI0=0;
RI0=0;
for(i=0;i<5;i++)
rec[i]=0x00;
start_timer0();
for(i=0;i<3;i++)
{
SBUF0=GSMCommand0[i];
while(!TI0);
TI0=0;
// while(!RI0);//不接收返回的數(shù)據(jù)
// rec[i]=SBUF0;
// RI0=0;
}
// RI0=0;
for(i=0;i<9;i++)
{
while(!RI0);
rec[i]=SBUF0;
RI0=0;
}
close_timer0();
if(rec[5]=='O'&&rec[6]=='K') break;
else if(error_counter++<10) Delay_1S();
else deal_with_error();
}
}
//***********Signal_test函數(shù)開始**********
void Signal_test(void)
{
UCHAR idata i,error_counter;
error_counter=0;
while(1) // AT+CSQ
{
TI0=0;
RI0=0;
start_timer0();
for(i=0;i<7;i++)
{
SBUF0 = GSMCommand1[i];
while(!TI0);
TI0 = 0;
// while(!RI0);
// rec[i] = SBUF0;
// RI0 = 0;
}
for(i=0;i<28;i++) //only receive part data (10)
{
while(!RI0);
rec[i] = SBUF0;
RI0 = 0;
}
close_timer0();
if(rec[15]!= '9'&& rec[16]!= '9')break;
else if(error_counter++<10) Delay_1S();
else deal_with_error();
}
Delay_1S();
RI0=0;
}
//***********Signal_test 函數(shù)結(jié)束*********
//***********AT+cmgf函數(shù)開始*************
void AT_cmgf(void)
{
UCHAR idata i;
while(1) // AT+CSQ
{
TI0=0;
RI0=0;
for(i=0;i<10;i++)
{
SBUF0 = GSMCommand2[i];
while(!TI0); TI0 = 0;
// while(!RI0);
// rec[i] = SBUF0;
// RI0 = 0;
}
/*
for(i=0;i<16;i++)
{
while(!RI0);
rec[i] = SBUF0;
RI0 = 0;
}
if(rec[12]== 'O'&& rec[13]== 'K')break;
*/
break;
Delay_1S();
}
Delay_1S();
RI0=0;
TI0=0;
}
//***********AT+cmgf函數(shù)結(jié)束*************
//發(fā)送完CMGS命令后會收到16個數(shù)據(jù),數(shù)據(jù)的最后兩個字節(jié)是3E和20時表示正常。
//***********AT+cmgs函數(shù)開始*************
void AT_cmgs(void)
{
UCHAR idata i;
while(1) // AT+cmgs
{
TI0=0;
RI0=0;
for(i=0;i<12;i++)
{
SBUF0 = GSMCommand3[i];
while(!TI0); TI0 = 0;
// while(!RI0);
// rec[i] = SBUF0;
// RI0 = 0;
}
for(i=0;i<16;i++)
{
while(!RI0);
rec[i] = SBUF0;
RI0 = 0;
}
if(rec[14]== 0x3E&& rec[15]== 0x20)
break;
// Delay_1S();
}
// Delay_1S();
for(i=0;i<50;i++); //延時一段時間
RI0=0;
TI0=0;
}
//***********AT+cmgs函數(shù)結(jié)束*************
//========sms有關(guān)的函數(shù)結(jié)束===================
void power_down(void)
{
PD=1; //bell ring
Delay_1S();
Delay_1S();
Delay_1S();
Delay_1S();
PD=0;
}
//發(fā)送GSMhead[],Phone_number,GSM_set[],GSM_sms[],0x1A;
//***********SEND_sms函數(shù)開始*************
void SEND_sms(UCHAR idata FID)
{
UCHAR idata i,temp;
// while(1)
{
TI0=0;
RI0=0;
for(i=0;i<12;i++)
{
SBUF0 = GSMhead[i];
while(!TI0); TI0 = 0;
}
for(i=0;i<12;i++)
{
// SBUF0 = PHONE_number[i];
SBUF0 = PHONE_number[0][FID][i+1];
while(!TI0);
TI0 = 0;
}
for(i=0;i<6;i++)
{
SBUF0 = GSM_set[i];
while(!TI0); TI0 = 0;
}
for(i=0;i<26;i++)
{
SBUF0 = GSM_sms[i];
while(!TI0); TI0 = 0;
}
SBUF0=0x1A;
while(!TI0); TI0 = 0; //發(fā)送信息結(jié)束
/*
for(i=0;i<75;i++)
{
while(!RI0);
rec[i] = SBUF0;
RI0 = 0;
}
if(rec[72]== 'O'&& rec[73]== 'K')break;
*/ Delay_1S();
}
// Delay_1S();
for(i=0;i<255;i++); //延時一段時間
RI0=0;
TI0=0;
}
//***********SEND_sms函數(shù)結(jié)束*************
//========sms有關(guān)的函數(shù)結(jié)束===================
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -