0.png (38.76 KB, 下載次數: 103)
下載附件
2015-12-9 16:51 上傳
SIM300 GPRS單片機源程序.rar
(131.81 KB, 下載次數: 55)
2015-12-9 16:50 上傳
點擊文件名下載附件
- /**************************************************************************
- * *
- * SIM300實現電話呼叫和GPRS *
- * *
- * 功能:實現任意的電話呼叫(號碼從鍵盤輸入) *
- * 實現呼入電話的接聽 *
- * 實現GPRS連接和發送固定的GPRS信息 *
- * 版本: V1.0 (2010/07/23) *
- * 網站: *
- * 郵箱: hificat@163.com *
- * 來源: 杭州晶控電子有限公司 HANGZHOU KinCony ELECTRONICS CO.,LTD *
- *【版權】Copyright(C) 杭州晶控電子 www.hificat.com All Rights Reserved *
- *【聲明】此程序僅用于學習與參考,引用請注明版權和作者信息! *
- * *
- *************************************************************************/
- #include <SIM300.h>
- //#include <reg51.h>
- #include <string.h>
- unsigned char q=0;
- unsigned char count=0;
- unsigned char number[15];//"13185077790";
- unsigned char num=0;
- void main(void)
- {
- sys_init();
- BELL_UP();
- LCD_init();
- LCD_clear();
- start();
- Start_GSM();
- GSM_init();
- clear_SystemBuf();
- while(strsearch("Call Ready",SystemBuf)==0);
- BELL_UP();
- do
- {
- LCD_clear();
- clear_SystemBuf();
- sendstring(AT_COPS);
- LCD_write_english_string( 4,2,"searching>");
- Delay_ms(3000);
- LCD_write_english_string( 4,2,"searching->");
- Delay_ms(3000);
- LCD_write_english_string( 4,2,"searching-->");
- Delay_ms(3000);
- LCD_write_english_string( 4,2,"searching--->");
- Delay_ms(3000);
- }while((strsearch("MOBILE",SystemBuf)==0)&&(strsearch("UNICOM",SystemBuf)==0));//檢測服務商信息
-
- BELL_UP();
- LCD_clear();
- if(strsearch("MOBILE",SystemBuf)!=0)LCD_write_chinese_string(16,2,12,4,6,0);//顯示服務商??
- if(strsearch("UNICOM",SystemBuf)!=0)LCD_write_chinese_string(16,2,12,4,10,0);//顯示服務商??
- LCD_write_english_string(0,0,"KinCony");
- ET0=1; //T0 中斷
- for(num=0;num<15;num++)
- {
- number[num]=0;
- }num=0;
- while(1)
- {
- do
- {
- scan();
- if(strsearch("RING",SystemBuf)!=0)
- {
- clear_SystemBuf();
- LCD_write_english_string(0,5,"CALL<---------");
- do
- {
- ET0=0;
- BELL_UP();
- if(scan()==12)
- {
- sendstring(ATA);
- LCD_write_english_string(0,5," ");
- LCD_write_english_string(0,5,"connet call...");
- break;
- }
- }while((scan()!=14)&&(strsearch("NO CARRIER",SystemBuf)==0));
- clear_SystemBuf();
- LCD_write_english_string(0,5," ");
- ET0=1;
- }
- }
- while(jump==0);
- LCD_set_XY(count,5);
- if ((scan()>=0)&&(scan()<=9)||scan()==-6||scan()==-13) //數字鍵
- {
- if(count<84)
- count+=6;
- LCD_write_char(scan()+48);
- number[num]=scan()+0x30;
- num++;
- }
- else if(scan()==12)//退格鍵
- {
- if(count>0)
- {
- count-=6;
- num--;
- number[num]=0;
- LCD_set_XY(count,5);
- LCD_write_char(32);
- LCD_set_XY(count,5);
- }
- }
- else if(scan()==15)//撥號鍵
- {
- unsigned char call[20]="ATD";
- strcat(call,number);//13185077790
- strcat(call,";");
- sendstring(call);
- clear_SystemBuf();
- ET0=0;
- while(1)
- {
- LCD_write_english_string(0,5,"CALL--------->");
- if(scan()==14) //掛機鍵
- {
- sendstring(ATH);
- for(num=0;num<15;num++)
- {
- number[num]=0;
- }
- num=0;
- LCD_write_english_string(0,5," ");
- count=0;
- ET0=1;
- break;
- }
- }
- }
- else if(scan()==14) //掛機鍵
- {
- sendstring(ATH);
- for(num=0;num<15;num++)
- {
- number[num]=0;
- }
- num=0;
- LCD_write_english_string(0,5," ");
- count=0;
- }
- else if(scan()==13)//GPRS演示程序(gprs連接一次發送消息然后斷開)
- {
- ET0=0;
- sendstring(AT_CIPCLOSE);Delay_ms(5000);
- sendstring(AT_CIPSHUT); Delay_ms(5000);
- sendstring(AT_CDSNORIP);Delay_ms(5000);
- sendstring(AT_CIPHEAD); Delay_ms(5000);
- sendstring(AT_CIPSTART);
- Delay_ms(5000);
- Delay_ms(5000);
- LCD_write_english_string(0,5," ");
- LCD_write_english_string(0,5,"connet gprs...");
- Delay_ms(5000);
- Delay_ms(5000);
- LCD_write_english_string(0,5," ");
- LCD_write_english_string(0,5,"gprs ok! ");
- sendstring(AT_CIPSEND);
- Delay_ms(5000);
- Delay_ms(5000);
- sendstring("Welcome to HANGZHOU KinCony ELECTRONICS!");
- Delay_ms(5000);
- Delay_ms(5000);
- LCD_write_english_string(0,5," ");
- LCD_write_english_string(0,5,"gprs sending..");
- sendchar(0x1a);
- Delay_ms(5000);
- Delay_ms(5000);
- LCD_write_english_string(0,5," ");
- LCD_write_english_string(0,5,"gprs send ok ");
- Delay_ms(5000);
- Delay_ms(5000);
- LCD_write_english_string(0,5," ");
- sendstring(AT_CIPCLOSE);Delay_ms(5000);
- sendstring(AT_CIPSHUT); Delay_ms(5000);
- ET0=1;
- }
- delayms(800);delayms(800);delayms(800);
- jump=0;
- }
- }
- /********************************************************************************************************
- ** 函數名稱 Int_Timer0()
- ** 函數功能 定時器中斷位,是整個程序的心跳,如果停止,程序會死機
- *********************************************************************************************************/
- void Int_Timer0(void) interrupt 1 using 3
- {
- TH0 = 0xB8;
- TL0 = 0x00; //20ms的時鐘基準
- timer_1S_cnt++;
- timercount++;
-
- if(timer_1S_cnt==50) //20×50=1000M
- {
- timer_10S_cnt++;
- timer_1S_cnt=0;
- timer_S_cnt++;
- LED_S0=~LED_S0;
- Signal();
- } //1秒=1000毫秒
- if(timer_10S_cnt==60) //60S
- {
- timer_10S_cnt=0;
-
- }
- }
復制代碼 |