?? gprs.c
字號:
//*****************************************************************
// function : ds18b20 driver
// editor : zhao wei
// date : 2008-11-24
// description:it is used to driver gprs send temperature data to remote server
//*****************************************************************
#include "..\ucos-ii\includes.h"
#include "..\ucos-ii\datatype.h"
#include "..\44box\44b.h"
#include <string.h>
char *AT_Command[12] = {
"at\r\n", //判斷是否連線
"at+csq\r\n", //判斷信號質量
"at+creg?\r\n", //檢查模塊網絡注冊情況
"at+wopen=1\r\n", //打開OPEN AT協議
"AT+WIPCFG=1\r\n", //啟動TCP協議
"AT+WIPBR=1,6\r\n", //打開GPRS
"at+wipbr=2,6,11,\"CMNET\"\r\n",//設置GPRS APN名稱
"AT+WIPBR=4,6,0\r\n", //啟動GPRS客戶端
"at+wipcreate=2,1,\"219.142.140.11\",34560\r\n",//設置IP和端口號
"at+wipdata=2,1,1\r\n", //連接
"+++\r\n", //返回AT命令狀態
"AT+WIPCLOSE=2,1\r\n" //關閉連接
};
char chEchoData[20] = {0};
//------------------------------------------------------
// function : send command
// input : AT instruction
// output : none
// description: send AT instruction wait for echo if succeed
//------------------------------------------------------
void GPRS_Cmd(char *pt)
{
int i=0;
while(1)
{
if(pt[i] != '\0')
{
Uart_SendByte(pt[i]);
i++;
}
else
{
// Uart_GetString(chEchoData);
break;
}
}
}
//------------------------------------------------------
// function : GPRS initialize
// input : none
// output : none
// description: send AT instruction initialize GPRS communition
//------------------------------------------------------
void GPRS_Init(void)
{
Uart_Select(0); //選擇串口0
Uart_Init(0,9600); //9600N81
Delay(5000);
GPRS_START: //為了方便調試指令,沒有使用循環語句
GPRS_Cmd(AT_Command[0]);
// if(memcmp(chEchoData,"OK",2) != 0)
// goto GPRS_START;
Delay(5000);
GPRS_Cmd(AT_Command[1]);
// if(memcmp(chEchoData,"OK",2) != 0)
// goto GPRS_START;
Delay(5000);
GPRS_Cmd(AT_Command[2]);
// if(memcmp(chEchoData,"OK",2) != 0)
// goto GPRS_START;
Delay(5000);
GPRS_Cmd(AT_Command[3]);
// if(memcmp(chEchoData,"OK",2) != 0)
// goto GPRS_START;
Delay(5000);
GPRS_Cmd(AT_Command[4]);
// if(memcmp(chEchoData,"OK",2) != 0)
// goto GPRS_START;
Delay(5000);
GPRS_Cmd(AT_Command[5]);
// if(memcmp(chEchoData,"OK",2) != 0)
// goto GPRS_START;
Delay(5000);
GPRS_Cmd(AT_Command[6]);
// if(memcmp(chEchoData,"OK",2) != 0)
// goto GPRS_START;
Delay(5000);
GPRS_Cmd(AT_Command[7]);
// if(memcmp(chEchoData,"OK",2) != 0)
// goto GPRS_START;
Delay(5000);
GPRS_Cmd(AT_Command[8]);
// if(memcmp(chEchoData,"OK",2) != 0)
// goto GPRS_START;
Delay(5000);
GPRS_Cmd(AT_Command[9]);
// if(memcmp(chEchoData,"CONNECT",2) != 0)
// goto GPRS_START;
Delay(5000);
}
//------------------------------------------------------
// function : return AT command mode
// input : none
// output : none
// description: return AT mode ,you can input AT command
//------------------------------------------------------
void GPRS_ReturnAT(void)
{
GPRS_Cmd(AT_Command[10]);
Delay(5000);
}
//------------------------------------------------------
// function : GPRS communition close
// input : none
// output : none
// description: close tcp link
//------------------------------------------------------
void GPRS_Close(void)
{
GPRS_START:
GPRS_Cmd(AT_Command[11]);
if(memcmp(chEchoData,"OK",2) != 0)
goto GPRS_START;
Delay(5000);
}
//------------------------------------------------------
// function : send data
// input : string data
// output : none
// description: send data to server
//------------------------------------------------------
void GPRS_SendData(char *pd)
{
// GPRS_Init();
Uart_SendString(pd);
Uart_SendByte(0x1A); //ctrl+z 26
Delay(5000);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -