📄 fangdao.lst
字号:
C51 COMPILER V7.50 FANGDAO 05/02/2007 00:52:35 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE FANGDAO
OBJECT MODULE PLACED IN fangdao.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE fangdao.C BROWSE DEBUG OBJECTEXTEND
line level source
1 #include <fangdao.h>
2 uchar data int_case; //中断标志
3 #define MAX_TM 97 //一个号码暂时定为(12手机号码)*6=72+(ALARM2T:05)*2=20=92
4 uchar idata uart_buff[MAX_TM]; //通信程序中的缓冲
5 uchar data send_count,receive_count;
6 data uchar AT_Command_Type; //当前发送的命令类型
7 data uchar AT_Command_Status; //命令发出以后的返回参数
8
9 uchar idata para_temp[MAX_TM-2];
10 //uchar idata key_temp[MAX_TM];
11 uchar data read_tmp; ///读电话本号参数
12 //uchar num_tmp; ///写电话本号参数
13 uchar num_tmp1; ///读短信号码参数
14 //uchar PHONE_TMP;
15 uchar TMP_BUF; // 万用 值
16 uchar sms_tmp; ///参数代码
17 uchar tel_tmp;
18 uchar tel_tmp1; ///读电话码地址
19 data uchar system_tep ; ///报警功能开启与关闭参数
20 uchar data system_server ; //系统状态
21 uint data timercount; //50MS定时器,
22 uchar data timer_1S_cnt;
23 uchar data timer_100S_cnt;
24 uchar data timer_200S_cnt;
25 uchar data sync_count; //用于TC35控制的计数器
26 //uchar data Pick_count ;
27 //uchar data Ring_count;
28 #define _Nop() _nop_()
29 //位变量
30 bit ring_pin_flag; //振铃脚状态
31 bit pickup_pin_flag; //摘机脚状态
32 bit txd_rxd_bit;
33 bit INT_TMP1;
34 bit INT_TMP2;
35 bit at_send_bit;
36 bit sbc_bit;
37 //bit Hookoff_bit;
38 //bit Hookoff_bit1;
39
40 void Int_Timer0(void) interrupt 1 using 3
41 {
42 1
43 1
44 1 TH0 = 0xB8;
45 1 TL0 = 0x00; //20ms的时钟基准
46 1 timercount++;
47 1 timer_1S_cnt++;
48 1 if(timer_1S_cnt==50) //50&200=10000S
49 1 { timer_100S_cnt++;
50 2 timer_1S_cnt=0;
51 2 timer_200S_cnt++;//IO_SBT=~IO_SBT;
52 2 LED_INT0=~LED_INT0;
53 2 }
54 1 if(timer_100S_cnt==60)
55 1 { //timer_200S_cnt++;
C51 COMPILER V7.50 FANGDAO 05/02/2007 00:52:35 PAGE 2
56 2 timer_100S_cnt=0;
57 2 //IO_SBT=~IO_SBT;
58 2
59 2 }
60 1
61 1 //2.摘挂机事件
62 1 IO_HKS=1;
63 1 if((pickup_pin_flag!=IO_HKS))
64 1 {
65 2
66 2 if(IO_HKS==0)
67 2 {
68 3 //int_case|=INT_HANGOFF;
69 3 //int_case&=~INT_PICKUP;
70 3 INT_TMP1=0;
71 3 system_server=SYS_RING;
72 3 }
73 2 else
74 2 { system_server=SYS_SMSR;INT_TMP1=1;}
75 2 pickup_pin_flag=IO_HKS;
76 2
77 2 }
78 1
79 1 IO_RING=1;
80 1 if((ring_pin_flag!=IO_RING))
81 1 {
82 2
83 2 if(IO_RING==0)
84 2 {
85 3 //int_case|=INT_RINGOFF;
86 3 //int_case&=~INT_RING;
87 3 INT_TMP2=0;
88 3 system_server=SYS_RING;
89 3 }
90 2 else { system_server=SYS_SMSR; INT_TMP2=1; }
91 2 ring_pin_flag=IO_RING;
92 2 }
93 1
94 1
95 1
96 1
97 1 }
98 /*****************************************************************************
99 * TC35 的命令列表,与中断服务程序 *
100 *****************************************************************************/
101 void Int_Uart(void) interrupt 4 using 3 //串口的中断程序
102 {
103 1 if(TI)//数据模式与命令方式共用
104 1 {
105 2 TI=0;
106 2
107 2 if(send_count>=MAX_TM-1) send_count=0;
108 2
109 2 if((uart_buff[send_count]==0)) //应该检测命令结束代码,检测到时结束通信
110 2 {
111 3 at_send_bit=1;
112 3 send_count=0xff;
113 3 uart_buff[0]=0; //清除接收缓冲区
114 3 receive_count=0; return;
115 3 }
116 2 else
117 2 { if(uart_buff[send_count]<=0xB0)
C51 COMPILER V7.50 FANGDAO 05/02/2007 00:52:35 PAGE 3
118 3 SBUF=uart_buff[send_count++];
119 3
120 3 if((uart_buff[send_count]==0)) //应该检测命令结束代码,检测到时结束通信
121 3 { at_send_bit=1;
122 4 send_count=0xff;
123 4 uart_buff[0]=0; //清除接收缓冲区
124 4 receive_count=0; return;
125 4 }
126 3 }
127 2
128 2
129 2 receive_count=0;
130 2 }
131 1
132 1 else
133 1 if(RI) //命令方式
134 1 {
135 2 RI=0;
136 2 if(at_send_bit==0) return;
137 2 if((send_count==0xff)&&(receive_count<MAX_TM))//没有发送时才能进行接收
138 2 { //所有的命令返回都是处于 0x0A [Result] 0x0D 之间,其他命令,不会出现这种情况
139 3
140 3 uart_buff[receive_count++]=SBUF;
141 3
142 3 }
143 2 else
144 2 {
145 3 //ACC=SBUF;
146 3 return;
147 3 }
148 2
149 2
150 2 if(receive_count>=MAX_TM-1)
151 2 {
152 3 if(AT_Command_Type==SMS_CMGR) receive_count=0;
153 3 else
154 3 { receive_count=0;
155 4 AT_Command_Status=COMMAND_OK;
156 4 return;
157 4 }
158 3 receive_count=0;
159 3 }
160 2
161 2 if((receive_count==2)&&(uart_buff[1]==0x0d))//没有包含为其他信息的命令返回
162 2 { //接收到一个命令回应,可能为,0-OK 1-CONNECT 2-RING 3-NO CARRIER 4-ERROR
163 3 //只返回OK
164 3
165 3 // uart_buff[receive_count]=0;
166 3 if(uart_buff[0]=='0')
167 3 {
168 4 AT_Command_Status=COMMAND_OK; txd_rxd_bit=1;
169 4 }
170 3 else if(uart_buff[0]=='4'||uart_buff[0]=='3')
171 3 { AT_Command_Status=COMMAND_ERROR;}
172 3 else AT_Command_Status=COMMAND_UNKNOW;
173 3 txd_rxd_bit=1;
174 3 uart_buff[receive_count]=0;
175 3 return;
176 3 }
177 2
178 2 else if((uart_buff[receive_count-1]==0x0d)
179 2 &&(receive_count>=3)
C51 COMPILER V7.50 FANGDAO 05/02/2007 00:52:35 PAGE 4
180 2 &&(uart_buff[receive_count-3]==0x0a)
181 2 &&((uart_buff[receive_count-2]=='0')))
182 2 { ///可能是包含为其他信息的命令返回
183 3 uart_buff[receive_count]=0;//RECEIV OK ANSWER, with some message
184 3 AT_Command_Status=COMMAND_OK; txd_rxd_bit=1;
185 3 // if(uart_buff[receive_count-2]=='0')
186 3 // {AT_Command_Status=COMMAND_OK;}
187 3 // else{ AT_Command_Status=COMMAND_WAIT; receive_count=0;}
188 3 }
189 2
190 2 else if(AT_Command_Type==SMS_CMGS&&uart_buff[3]=='>')
191 2 { AT_Command_Status=COMMAND_OK; txd_rxd_bit=1;
192 3 return;
193 3 }
194 2
195 2
196 2 }//End of if(RI)
197 1 }
198 /*********************************************************************
199 * C51中字符串函数的扩充 *
200 *********************************************************************/
201
202 uchar strsearch(uchar *ptr2)//查字符串*ptr2在*ptr1中的位置
203 //本函数是用来检查字符串*ptr2是否完全包含在*ptr1中
204 //返回: 0 没有找到
205 // 1-255 从第N个字符开始相同
206 {
207 1 //、 uchar max_length;
208 1 uchar i,j,k;
209 1 uchar flag;
210 1 if(ptr2[0]==0) return(0);
211 1 //max_length=strlen(ptr)+1;
212 1 flag=0;
213 1 for(i=0,j=0;i<99;i++)
214 1 {
215 2 if(uart_buff[i]==ptr2[j])
216 2 {//第一个字符相同
217 3 for(k=i;k<70;k++,j++)
218 3 {
219 4 if(ptr2[j]==0)//比较正确
220 4 return(i+1); //返回值是整数,不含0
221 4 if(uart_buff[k]!=ptr2[j]) break;
222 4 }
223 3 j=0;
224 3 }
225 2 }
226 1 return(0);
227 1 }
228
229 //============================================
230 //========== 读写短信程序
231 //====================================================
232 void read_sms()
233 { uchar i,r;
234 1
235 1 for(r=1;r<20;r++)
236 1 {
237 2 if(r<=7)
238 2 {
239 3 P0=(0x80>>r);
240 3 }
241 2 else
C51 COMPILER V7.50 FANGDAO 05/02/2007 00:52:35 PAGE 5
242 2 {P0=(0x80>>r-8);}
243 2
244 2 timer_200S_cnt=0; while(timer_200S_cnt<1) system_sleep;
245 2
246 2 if(system_server==SYS_RING) return;
247 2 num_tmp1=r;
248 2 if(READ_TEL(r)!=1) //读一个短信 at+cmgr=1-19 读指令
249 2 {
250 3 BELL=1;
251 3 if(system_server==SYS_RING) return;
252 3 timer_200S_cnt=0; while(timer_200S_cnt<2&&(AT_Command_Status==COMMAND_WAIT)) system_sleep;
253 3 if(strsearch("+CMTI:")) return;
254 3 continue;
255 3 }
256 2 BELL=1;
257 2 para_temp[3]=0x00;
258 2 if(i=strsearch("START")) //控制系统开启
259 2 {
260 3 system_tep=1;
261 3 system_server=SYS_START; return;
262 3
263 3 }
264 2 //--------------------//参数查询命令--为三个语音\三个短信\二个定时时长----------------------------------
------------
265 2 else if(i=strsearch("PASST")) //参数查询命令
266 2 {
267 3
268 3 system_server=SYS_PARA;
269 3 return;
270 3
271 3 }
272 2 else
273 2 {
274 3
275 3
276 3 para_temp[0]=(num_tmp1/10)+0x30;para_temp[1]=(num_tmp1%10)+0x30; para_temp[2]=0x0d;para_temp[3]=0x00
-;
277 3 Send_AT_Command(SMS_CMGD);
278 3 timer_200S_cnt=0; while(timer_200S_cnt<3&&(AT_Command_Status==COMMAND_WAIT)) system_sleep;
279 3 return;
280 3
281 3 }
282 2
283 2 return;
284 2
285 2 }
286 1
287 1
288 1
289 1
290 1 }
291
292
293 void send_sms() //发送短信
294 { uchar j=1,i=1,k;
295 1 Send_AT_Command(SIM_ID);
296 1 timer_200S_cnt=0; while(timer_200S_cnt<1&&(AT_Command_Status==COMMAND_WAIT)) system_sleep;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -