📄 comm.lst
字号:
C51 COMPILER V6.02 COMM 07/15/2004 11:07:07 PAGE 1
C51 COMPILER V6.02, COMPILATION OF MODULE COMM
OBJECT MODULE PLACED IN C:\COMM_D\COMM.OBJ
COMPILER INVOKED BY: C:\COMP51\C51.EXE C:\COMM_D\COMM.C DB SB OE
stmt level source
1 /* ---------------------------------------------------------- */
2 /* */
3 /* IC卡加油机键盘通讯子模块 */
4 /* 负责与PSAM卡、用户卡、加油机主板通讯 */
5 /* 最后修改日期:2002年4月21日 */
6 /* */
7 /* ---------------------------------------------------------- */
8
9 #include "c:\comm_d\comm.h"
10
11
12
13 void send(unsigned char offset,unsigned char len)
14 {
15 1 register unsigned char counter=0;
16 1 bit tem;
17 1 //ES=0;
18 1 DIRECTION=1; // 置数据传送方向为发送
19 1 is_send=1; // 置发送标志
20 1 PT0=1; // 置定时器0中断为高优先级
21 1 ET0=1; // 允许定时器0中断
22 1 while(counter<len) // 未发完len字节
23 1 {
24 2 TL0=0x84; // 定时器0工作在模式2,晶振为14.31818M,定时溢出频率为9600(实际为9622)
25 2 TH0=0x84; // 用仿真器时用0x97
26 2 TR0=1; // 启动定时器0
27 2 com_cur=0; // 当前发送起始位
28 2 com_tem=send_buf[offset+counter]; // 从外部读入要发送的字节
29 2 com_tem1=0xe;
30 2 ACC=com_tem;
31 2 com_tem1|=P; // 取校验位
32 2 com_tem1=com_tem1<<1;
33 2 tem=com_tem&0x80; // 取d7
34 2 com_tem1|=tem; // 把d7放在com_tem1的D0位
35 2 com_tem=com_tem<<1; // com_tem存起始位(0)+d0~d6
36 2 while(com_cur<13); // 等待本字节发送完成
37 2 //dog();
38 2 counter++;
39 2 TR0=0; // 关定时器0
40 2 }
41 1 ET0=0; // 禁止定时器0中断
42 1 dog();
*** WARNING C206 IN LINE 42 OF C:\COMM_D\COMM.C: 'dog': missing function-prototype
43 1 //comm_status=0;
44 1 //ES=1;
45 1 }
46
47 unsigned char recv(unsigned char offset,unsigned char len)
48 {
49 1 register unsigned char timer=0;
50 1 //ES=0;
51 1 DIRECTION=0; // 8888
52 1 is_send=0; // 置接收标志
53 1 IE0=0; // 清外部中断0触发标志
54 1 IT0=1; // 置为沿触发
C51 COMPILER V6.02 COMM 07/15/2004 11:07:07 PAGE 2
55 1 PX0=1; // 置外部中断0为高优先级
56 1 EX0=1; // 允许外部中断0
57 1 is_over=0;
58 1 is_err=0;
59 1 com_tem1=offset; // 初始化接收指针
60 1 com_limit=offset+len;
61 1 while(!is_over && timer<100) // 等待接收结束,2s超时
62 1 {
63 2 com_delay();
64 2 dog();
65 2 timer++;
66 2 }
67 1 EX0=0; // 禁止外部中断0
68 1 ET0=0; // 禁止定时器0中断
69 1 TR0=0; // 关定时器0
70 1 //comm_status=0;
71 1 dog();
72 1 //ES=1;
73 1 if(is_err)return 1; // 校验位错
74 1 else if(is_over)return 0; // 成功返回
75 1 else return 2; // 超时
76 1 }
77
78 void com_delay()
79 {
80 1 register unsigned int i;
81 1
82 1 for(i=0;i<3409;i++)
83 1 {
84 2 if(is_over)break;
85 2 dog();
86 2 }
87 1 }
88
89
90 /* 中断服务程序 */
91
92 void ic_timer0() interrupt 1 // 定时器0
93 {
94 1 if(is_send) // 发送
95 1 {
96 2 if(com_cur<8) // 发送com_tem字节
97 2 {
98 3 com_sda=com_tem&0x1; // 发送最低位
99 3 com_tem=com_tem>>1; // 右移1位
100 3 }
101 2 else // 发送com_tem1
102 2 {
103 3 com_sda=com_tem1&0x1;
104 3 com_tem1=com_tem1>>1;
105 3 }
106 2 com_cur++;
107 2 }
108 1 else // 接收
109 1 {
110 2 if(com_cur<8) // 收数据位
111 2 {
112 3 com_tem=com_tem>>1;
113 3 if(com_sda)com_tem|=0x80;
114 3 }
115 2 else if(com_cur==8) // 收校验位
116 2 {
C51 COMPILER V6.02 COMM 07/15/2004 11:07:07 PAGE 3
117 3 ACC=com_tem;
118 3 if(P!=com_sda) // 校验错
119 3 {
120 4 is_err=1;
121 4 is_over=1;
122 4 }
123 3 }
124 2 else // 停止位
125 2 {
126 3 rekk[com_tem1]=com_tem;
127 3 com_tem1++;
128 3 if(com_tem1<com_limit) // 未收完
129 3 {
130 4 ET0=0; // 禁止定时器0中断
131 4 TR0=0; // 关定时器0
132 4 IE0=0;
133 4 EX0=1; // 允许外部中断0
134 4 }
135 3 else is_over=1; // 收完
136 3 }
137 2 com_cur++;
138 2 }
139 1 }
140
141 void ic_int0() interrupt 0 // 外部中断0
142 {
143 1 EX0=0; // 禁止外部中断0
144 1 TL0=0x74; // 第一次定时为1.5个9600BAUD
145 1 TH0=0x84;
146 1 TF0=0; // 清定时器0中断触发标志
147 1 PT0=1; // 置定时器0中断为高优先级
148 1 ET0=1; // 允许定时器0中断
149 1 com_tem=0;
150 1 com_cur=0;
151 1 TR0=1; // 启动定时器0
152 1 }
153 void key_dlu()
154 {
155 1 unsigned int k;
156 1 for(k=0;k<2400;k++);
157 1 {
158 2 dog();
159 2 }
160 1 }
161 unsigned int get_CRC(unsigned char xdata *buffer,unsigned int length)
162 {
163 1 register unsigned int i,j;
164 1 unsigned char data tem[2];
165 1 bit lsb0,lsb1;
166 1 //ES=0;
167 1 tem[0]=0; // 初始化CRC寄存器为0
168 1 tem[1]=0;
169 1 for(i=0;i<length;i++)
170 1 {
171 2 tem[1]^=buffer[i]; // 输入数据与CRC寄存器低字节异或
172 2 for(j=0;j<8;j++)
173 2 {
174 3 lsb0=tem[0]&1; // 取高字节的最低位
175 3 tem[0]=tem[0]>>1;
176 3 lsb1=tem[1]&1; // 取低字节的最低位
177 3 tem[1]=tem[1]>>1;
178 3 if(lsb0)tem[1]|=0x80;
C51 COMPILER V6.02 COMM 07/15/2004 11:07:07 PAGE 4
179 3 if(lsb1) // 最低位为1,CRC寄存器与0xa001异或
180 3 {
181 4 tem[0]^=0xa0;
182 4 tem[1]^=0x01;
183 4 }
184 3 }
185 2 dog();
186 2 }
187 1 //comm_status=0;
188 1 //ES=1;
189 1 return(*(unsigned int *)tem);
190 1 }
191 unsigned long bcdtohex(unsigned char xdata *bcd,unsigned char xdata bcd_num)
*** WARNING C258 IN LINE 191 OF C:\COMM_D\COMM.C: 'bcd_num': mspace on parameter ignored
192 {
193 1
194 1 unsigned long xdata tem;
195 1 register unsigned char i;
196 1 tem=0;
197 1 //ZK_CS=1;
198 1
199 1 for(i=bcd_num;i>0;i--)
200 1 {
201 2 // tem=tem*100+(bcd[bcd_num-i]/16)*10+bcd[bcd_num-i]%16;
202 2 tem=tem*100;
203 2 tem=tem+(bcd[bcd_num-i]/16)*10;
204 2 tem=tem+bcd[bcd_num-i]%16;
205 2 dog();
206 2 }
207 1
208 1 return tem;
209 1
210 1 }
211 unsigned char * hextobcd(unsigned long xdata hexb)
*** WARNING C258 IN LINE 211 OF C:\COMM_D\COMM.C: 'hexb': mspace on parameter ignored
212 {
213 1 //unsigned long xdata hex_temp=0;
214 1 unsigned char xdata char_temp[4]={0,0,0,0};
215 1 // hex_temp=hexb;
216 1 //ZK_CS=1;
217 1 char_temp[1]=hexb/100000;
218 1 char_temp[1]<<=4;
219 1 hexb=hexb-hexb/100000*100000;
220 1 char_temp[1]=char_temp[1]|hexb/10000;
221 1
222 1 hexb=hexb-hexb/10000*10000;
223 1 char_temp[2]=hexb/1000;
224 1 char_temp[2]<<=4;
225 1 hexb=hexb-hexb/1000*1000;
226 1 char_temp[2]=char_temp[2]|hexb/100;
227 1
228 1 hexb=hexb-hexb/100*100;
229 1 char_temp[3]=hexb/10;
230 1 char_temp[3]<<=4;
231 1 hexb=hexb-hexb/10*10;
232 1 char_temp[3]=char_temp[3]|hexb;
233 1
234 1 return char_temp;
235 1 }
236 /*******************************************************************
237 向有子地址器件读取多字节数据函数
238 函数原型: bit ISendStr(uchar sla,uchar suba,ucahr *s,uchar no);
C51 COMPILER V6.02 COMM 07/15/2004 11:07:07 PAGE 5
239 功能: 从启动总线到发送地址,子地址,读数据,结束总线的全过程,从器件
240 地址sla,子地址suba,读出的内容放入s指向的存储区,读no个字节。
241 如果返回1表示操作成功,否则操作有误。
242 注意: 使用前必须已结束总线。
243 ********************************************************************/
244 unsigned char IRcvStr(unsigned char sla,unsigned char suba,unsigned char no)
245 {
246 1 unsigned char i;
247 1 unsigned char *s;
248 1 Start_I2c(); /*启动总线*/
249 1 SendByte(sla); /*发送器件地址*/
250 1 if(ack==0)return(0);
251 1 SendByte(suba); /*发送器件子地址*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -