📄 gsmcs.lst
字号:
C51 COMPILER V7.06 GSMCS 04/12/2009 16:41:11 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE GSMCS
OBJECT MODULE PLACED IN GSMcs.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE GSMcs.c
stmt level source
1 #include "GSMgn.h"
2 #include "GSMhead.h"
3 uchar F=0,chinit,chping,chname;
4
5 sbit LED1=P1^0;
6 sbit LED2=P1^1;
7 sbit LED3=P1^2;
8 sbit LED4=P1^3;
9 sbit LED=P1^4;
10 uint Time,Time1;
11
12 void delay1ms(uint x){
13 1 for(Time=0;Time<x;Time++)
14 1 for(Time1=0;Time1<120;Time1++);
15 1 }
16
17 /*********************************************************************
18 * C51中字符串函数的扩充 *
19 *********************************************************************/
20 uchar strsearch(uchar *ptr2){//查字符串*ptr2在*ptr1中的位置
21 1 //本函数是用来检查字符串*ptr2是否完全包含在*ptr1中
22 1 //返回: 0 没有找到
23 1 // 1-255 从第N个字符开始相同
24 1 uchar i,j,k;
25 1 uchar flag;
26 1 if(ptr2[0]==0) return(0);
27 1 flag=0;
28 1 for(i=0,j=0;i<MAX_TM-2;i++){
29 2 if(uart_buff[i]==ptr2[j]){//第一个字符相同
30 3 for(k=i;k<MAX_TM-2;k++,j++){
31 4 if(ptr2[j]==0)//比较正确
32 4 return(i+1); //返回值是整数,不含0
33 4 if(uart_buff[k]!=ptr2[j]) break;
34 4 }
35 3 j=0;
36 3 }
37 2 }
38 1 return(0);
39 1 }
40
41 /*********************************************************************
42 * AT指令发送程序 *
43 *********************************************************************/
44 uchar Send_AT_Command( uchar type){ //发送AT指令
45 1 //拨号时号码放在phone.number
46 1 //其他用para_temp
47 1 AT_Command_Type=type;
48 1 send_count=0;
49 1 switch(type){
50 2 case RESET_TC35: //复位TC35
51 2 strcpy(uart_buff,"AT+CFUN=1,1");
52 2 break;
53 2 case CHECK_PIN: //检查当前是否要输入PIN码
54 2 strcpy(uart_buff,"AT+CPIN?");
55 2 break;
C51 COMPILER V7.06 GSMCS 04/12/2009 16:41:11 PAGE 2
56 2 case TC35_INIT: //TC35初始化命令
57 2 strcpy(uart_buff,"ATE0V0");
58 2 break;
59 2 //0D 0A 54 43 33 35 0D 0A
60 2 case SIM_ID:
61 2 strcpy(uart_buff,"ATE0V0+CMGF=1+CNMI=2,1");
62 2 break;
63 2 case AT_IPR:
64 2 strcpy(uart_buff,"AT+IPR=9600");
65 2 break;
66 2 case SMSS_ID:
67 2 strcpy(uart_buff,"ATE0V0^SSMSS=1+CNMI=2,1");
68 2 break;
69 2 case SMS_CMGF: //SMS 接收方式,
70 2 strcpy(uart_buff,"ATE0V0+CMGF=0");
71 2 break;
72 2 case PHONE_WRITE: //存电话号码
73 2 strcpy(uart_buff,"AT+CPBW=");
74 2 strcat(uart_buff,para_temp);
75 2 break;
76 2 case PHONE_READ: //读电话本
77 2 strcpy(uart_buff,"AT+CPBR=");
78 2 strcat(uart_buff,&read_tmp);
79 2 uart_buff[9]=0x0d;
80 2 uart_buff[10]=0x0a;
81 2 uart_buff[11]=0x00;
82 2 uart_buff[12]=0x00;
83 2 break;
84 2 case SMS_CMGR: //读一个短信
85 2 strcpy(uart_buff,"AT+CMGR=");
86 2 strcat(uart_buff,para_temp);
87 2 break;
88 2 case SMS_CMGS: //写一个短信
89 2 strcpy(uart_buff,"AT+CMGS=");
90 2 strcat(uart_buff,para_temp);
91 2 break;
92 2 case SMS_CMGD: //删除一个短信
93 2 strcpy(uart_buff,"AT+CMGD=");
94 2 strcat(uart_buff,para_temp);
95 2 break;
96 2 case CMGS_MUB: //发报警短信内容
97 2 strcpy(uart_buff,para_temp);
98 2 break;
99 2 case AT_COMMAND:
100 2 break;
101 2 default:
102 2 receive_count=0;
103 2 return(TRUE);
104 2 }
105 1 ES=1;
106 1 strcat(uart_buff,"\x0d\x00");//在命令后加入CR
107 1 send_count=0; //设置发送指针
108 1 receive_count=0;
109 1 AT_Command_Status=COMMAND_WAIT; //设置接收成功标志
110 1 timer_S_cnt=0;
111 1 txd_rxd_bit=0;
112 1 at_send_bit=0;
113 1 TI=1; //开始发送数据
114 1 RI=0; //清除接收标志
115 1 if (type==TC35_INIT){
116 2 while (timer_S_cnt<6){
117 3 if (AT_Command_Status!=COMMAND_WAIT||txd_rxd_bit==1)
C51 COMPILER V7.06 GSMCS 04/12/2009 16:41:11 PAGE 3
118 3 return(TRUE);
119 3 }
120 2 }
121 1 else if((type==SMS_CMGR)){
122 2 while (timer_S_cnt<6){
123 3 if (AT_Command_Status!=COMMAND_WAIT||txd_rxd_bit==1)
124 3 return(TRUE);
125 3 }
126 2 }
127 1 else if((type==CALL_ID)){
128 2 while (timer_S_cnt<2){
129 3 if (AT_Command_Status!=COMMAND_WAIT||txd_rxd_bit==1)
130 3 return(TRUE);
131 3 }
132 2 }
133 1 else{
134 2 while (timer_S_cnt<6){
135 3 if (AT_Command_Status!=COMMAND_WAIT||txd_rxd_bit==1){
136 4 return(TRUE);
137 4 }
138 3 }
139 2 }
140 1 return(FALSE);
141 1 }
142
143 void Sys_Init(void){//话机启动的初始化程序,包含键盘与定时器,串口等
144 1 //TH0=(65536-46080)/256;//重新装入定时25mS的初值到TH0,TL0 56320
145 1 //TL0=(65536-46080)%256;
146 1 //65536-(11.0592/12)*20MS*1000=To 18432 47104
147 1 //1ms定时
148 1 //11.0592/12 = 0.9216 M (记数频率)
149 1 //1ms记数 921.6次
150 1 //16位 2^16 - x = 922 x=64614 FC66
151 1 //定时器里不断放fc66,不用怀疑51定时器得到的 1ms的精确性吗
152 1 //TH0 = 0xf6;
153 1 //TL0 = 0x50;
154 1 TH0 = 0xB8;
155 1 TL0 = 0x00; //20ms的时钟基准//串口中断
156 1 TI=0;
157 1 RI=0;
158 1 SCON=0x50; //选用方式1
159 1 TMOD=0x20;
160 1 TMOD = (TMOD & 0xf0) | 1;//MODE 1
161 1 TH1=0xfd; //波特率为9600
162 1 TL1=0xfd;
163 1 PCON=0x00; //倍频0x80
164 1 IE = 0xb0; // EA XX ET2 ES ET0 EX0 ET1 EX1 11000000
165 1 TR1=1; //enable TIMER1
166 1 ES=1;
167 1 TR0=1;
168 1 ET0=1;
169 1 ET1=0;
170 1 EA=1;
171 1 timer_1S_cnt=0;
172 1 receive_count=0;
173 1 send_count=0xff; //表示禁止发送,可以接收
174 1 }
175
176 //======================================================================
177 //========================进行SIM卡中的1到20条短信号码的读==============================================
178 //======================================================================
179 uchar READ_TEL(uchar r){ //读短信号码1-20个
C51 COMPILER V7.06 GSMCS 04/12/2009 16:41:11 PAGE 4
180 1 // uchar r;
181 1 para_temp[0]=(r/10)+0x30;para_temp[1]=(r%10)+0x30; para_temp[2]=0x0d;para_temp[3]=0x00;
182 1 para_temp[4]=0x00;para_temp[5]=0x00;para_temp[6]=0x00;para_temp[7]=0x00;
183 1 para_temp[8]=0x00;para_temp[9]=0x00;para_temp[10]=0x00;para_temp[11]=0x00;
184 1 // timer_S_cnt=0; while(timer_S_cnt<1&&(AT_Command_Status==COMMAND_WAIT)) watch_dog_clear;
185 1 Send_AT_Command(SMS_CMGR);
186 1 timer_S_cnt=0;
187 1 //while(timer_S_cnt<1&&(AT_Command_Status==COMMAND_WAIT)) watch_dog_clear;
188 1 send_count=0;
189 1 if(strsearch("CMGR: 0,,0")){ //+CMGR: 0,,0 没有短信返回
190 2 // timer_S_cnt=0; while(timer_S_cnt<1) watch_dog_clear;
191 2 ES=1; //设置发送指针
192 2 receive_count=0;
193 2 send_count=0xff;
194 2 RI=0 ;
195 2 return(FALSE);
196 2 }
197 1 else if(uart_buff[1]==0x0d&&uart_buff[0]==0x34){
198 2 return(FALSE);
199 2 }
200 1 else{
201 2 if(AT_Command_Status==COMMAND_ERROR)
202 2 return(FALSE);
203 2 else return(TRUE);
204 2 }
205 1 }
206
207 //============================================
208 //========== 读写短信程序
209 //====================================================
210 void read_sms(){
211 1 uchar i,r,j,t;
212 1 for(r=1;r<20;r++){
213 2 timer_tmp=0;
214 2 // while(timer_tmp<15) watch_dog_clear;// if(strsearch("+CMTI:")) return; //是否有新短信
215 2 num_tmp1=r;
216 2 if(READ_TEL(r)!=1){ //读一个短信 at+cmgr=1-19 读指令
217 3 if(strsearch("+CMTI:")) return;
218 3 continue;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -