《GPRS-GSM程序.doc》由会员分享,可在线阅读,更多相关《GPRS-GSM程序.doc(89页珍藏版)》请在金锄头文库上搜索。
1、/=GPRS MODULE PROGRAM=/=FROM 2003.9.=/=by cfj=#include/#include#include#include#include#include#include#define Uint unsigned int#define _3NOP() _NOP();_NOP();_NOP();#define _4NOP() _NOP();_NOP();_NOP();_NOP();#define _5NOP() _NOP();_NOP();_NOP();_NOP();_NOP();#define Estart_Addr 0 /0 EEprom起始地址#defi
2、ne Work_Mode_Addr Estart_Addr+6 /6 工作模式设置:1字节#define MAPN_Addr Work_Mode_Addr+1 /7 移动网关接入点名称:20字节ASCI#define DSC_Ip_Addr MAPN_Addr+20 /27 数据服务中心IP地址:12字节ASC#define DSC_Port_Addr DSC_Ip_Addr+12 /39 数据中心端口:5字节ASCII#define Net_Protocol_Addr DSC_Port_Addr+5 /44 网络数据传输协议#define Terminal_SIM_Addr Net_Prot
3、ocol_Addr+1 /45 终端SIM#define Beat_Addr Terminal_SIM_Addr+11 /56 心跳周期地址#define PassWord_Addr Beat_Addr+1 /57 设置密码#define SCA_SIM_Addr PassWord_Addr+6 /63 短信服务中心号码#define DSC_SIM_Addr SCA_SIM_Addr+11 /74 数据中心号码#define BackUp_Addr DSC_SIM_Addr+11 /85 备用#define Set_Crc BackUp_Addr+4 /89 CRC校验码#define Es
4、tart2_Addr Estart_Addr+100/*/函数:main()/功能:主函数/输入参数:/输出参数:/=/常量定义/=char *AT=ATr;/AT命令用于检测GPRS是否存在或开机。char AT_Echo12=A,T,E,=,0,V,=,1,&,D,1,0X0D;/命令码不返回。/char *AT_Echo=ATE=0V=1&D1r;/命令码不返回。char *AT_O=ATOr;/从命令状态返回到数据状态。char *AT_3Plus=+ATr;char *AT_W=AT&Wr; /保存设置。char *AT_ActivateIp=AT*E2IPA=1,1r;char O
5、penIp11=A,T,*,E,2,I,P,O,=,1,;char *AT_CloseIp=AT*E2IPCr;/关闭GPRS通道char *AT_CMGF=AT+CMGF=0r;/短信PDU MODEchar Terminal_Command19=0x68,0x0d,0x0d,0x68,0x4a,0x99,0x99,0x07,0x00,0x0b,0x80,0x30char Echo_Array=0X2F,0X00,0X07,0XFF,0XFF,0XFD,0XA3,0X03;/设置正确信号char Alarm_Switch_Echo=0X2F,0X00,0X08,0XFF,0XFF,0XCE,
6、0XEC,0X8F,0X14;char Data_Switch_Echo=0X2F,0X00,0X08,0XFF,0XFF,0XCD,0XEC,0XDA,0X47;/=/函数定义/=void Port_Initial(void);void Delay(Uint);void First_Wr_EEprom(void);void Variable_Initial(void);void Turn_On_Gprs(void);void Turn_Off_Gprs(void);/打开GPRS电源void USART0_Initial(void);void USART1_Initial(void);voi
7、d Timer_Initial(void);void Data_Cmnd_Snd(Uint L,char *Temp_Pointer,char Sport,Uint);void Gprs_At_Command(Uint,char *Pcommand,Uint WTime);void Rx1Data_Judge_Trasmit(void);void Rx0Data_Judge_Trasmit(void);/extern void EWEN_93lc66(void);extern void Start_93lc66(char Op_Code);extern char Rd_Data(char St
8、art_Addr,char Data_Len,Uint *Pointer);extern void Wr_Data(char Start_Addr,char Data_Len,Uint *Pointer);void Cal_Crc(char *Pointer,Uint L);/计算返回CRC值。char Read_Parameters_Initial(char);/从EEPROM中读取工作参数、初始化。void WorkMode_Initial_Log(void);extern void Construct_PDU_SMS(char UDL,char *User_Data);/构造SMS内容。
9、extern void Echo_SMS_Master(char);void Asci_To_Hex(char *Pointer,Uint);extern void Echo_Sms_Mobile(void);void Echo_Rx0(char *Pointer,char Lenth);extern void Mobile_SMS_Get(char);extern void Mobile_SMS_Set(char);extern void Encode7Bit(char);extern void Decode8Bit(char);extern char ReturnHex(char);voi
10、d Heart_Beat(void);void Read_Delete_SMS(void);void Feed_WatchDog(void);void Gprs_Mode_SMS(Uint);void Judge_SMS_Counter(void);void Data_Status(void);void Connect_Master_Station(void);extern void Waiting_Result(Uint Wresult_Time);extern void ZheJiang_Protocol_Down(Uint);extern void ZheJiang_Protocol_U
11、p(Uint);void Inqury_Signal(void);/=/全局变量定义/=char VIO;Uint Tx1_Snd_Lenth,Tx1_Pointer,Rx1_Pointer; /发送长度、发送指针、接收指针Uint Tx0_Snd_Lenth,Tx0_Pointer,Rx0_Pointer; /发送长度、发送指针、接收char *Pointer0,*Pointer1;char Command_Data_Status;char Rx1_Start_Flag; /串口接收开始标志Uint Rx1_Time_Counter;/串口接收时间长度char Rx1_TimeOut_Fla
12、g;/接收超时标志char Rx0_Start_Flag; /串口接收开始标志char Rx0_Time_Counter;/串口接收时间长度char Rx0_TimeOut_Flag;/接收超时标志Uint Wait_Result_Time;char Wait_Result_TimeOut;char Flash_Timer_Len; /CPU正常运行指示灯。char Led1_Flash;Uint Heart_Beat_Interval;/自动检测IP连接的间隔时间char Heart_Beat_Flag; /自动检测标志char nMinute_Beat_Flag;char Heart_Be
13、at_Time;char AT_OpenIp035;char Rx1_Data_Buffer360;/GPRS串口数据缓冲区char Rx0_Data_Buffer256;/终端数据缓冲区char Terminal_SIM12;/终端手机号码。char Center_SIM12; /短信通信手机号码。char Data_Center_Sim12;/数据中心手机号码。char SCA_SIM4; /短信服务中心号码Uint Temp_iArray100;/临时缓冲区:整数char Temp_cArray200;/临时缓冲区:字符char SMS_TPDU300;char User_Data140;char PassWord6;char AT_CGDCONT40;char AT_Set_Ok;Uint PDU_Len;char Retry_Counter;char AT_Test_Flag;char IpConnect_Flag;char R