📄 func_shi.lst
字号:
175
176 /*********************************************************************
177 Receivebyte Function
178 *********************************************************************/
179 char receive_con()
C51 COMPILER V7.50 FUNC_SHI 12/31/2004 22:02:01 PAGE 4
180 {
181 1 char count = 0;
182 1
183 1 for (count=0;count<8;count++)
184 1 {
185 2 bytedata <<= 1;
186 2 scl = 1; // scl high
187 2 delay_nop();
188 2 if (sda)
189 2 {
190 3 bytedata |= 0x01;
191 3 }
192 2 scl = 0; // scl low
193 2 delay_nop();
194 2 }
195 1 return (bytedata);
196 1 }
197
198 /*********************************************************************
199 Sendbyte Function
200 *********************************************************************/
201 bit send_con(char bytedata)
202 {
203 1 char count = 0;
204 1
205 1 scl = 0;
206 1 delay_nop();
207 1 for (count=0;count<8;count++)
208 1 {
209 2 //sda = 0; // sda low
210 2 if (bytedata & 0x80)
211 2 sda = 1; // sda high
212 2 else
213 2 sda = 0;
214 2 delay_nop();
215 2 bytedata <<= 1; // bytedata left shift
216 2
217 2 // Generate SCLK
218 2 scl = 1; // scl high
219 2 //_nop_ ();
220 2 delay_nop();
221 2 scl = 0; // scl low
222 2 delay_nop();
223 2 }
224 1 delay_nop();
225 1
226 1 // Readback ack
227 1 sda = 1; // sda high
228 1 delay_nop();
229 1 scl = 1; // scl high
230 1 delay_nop();
231 1 ack = sda; // Read ack
232 1 // Ack = 0 => Acknowledge
233 1 // Ack = 1 => No Acknowledge
234 1 delay_nop();
235 1 scl = 0; // scl low
236 1 delay_nop();
237 1 return (ack);
238 1 }
239
240 /*********************************************************************
241 Acknowledge Function
C51 COMPILER V7.50 FUNC_SHI 12/31/2004 22:02:01 PAGE 5
242 *********************************************************************/
243 void ack_con()
244 {
245 1 sda = 0; // sda low
246 1 delay_nop();
247 1 scl = 1; // scl high
248 1 _nop_ ();
249 1 delay_nop();
250 1 scl = 0; // scl low
251 1 delay_nop();
252 1 sda = 1; // sda high
253 1 delay_nop();
254 1 }
255
256 /*********************************************************************
257 Not Acknowledge Function
258 *********************************************************************/
259 void nack_con()
260 {
261 1 // Acknowledge active
262 1 sda = 0; // sda low
263 1 delay_nop();
264 1 scl = 1; // scl high
265 1 delay_nop();
266 1 //Stop active
267 1 sda = 1; // sda high
268 1 delay_nop();
269 1 scl = 0; // scl low
270 1 delay_nop();
271 1 }
272 /*********************************************************************
273 Start Function
274 *********************************************************************/
275 void start_con()
276 {
277 1 sda = 1; // sda high
278 1 delay_nop();
279 1 scl = 1; // scl high
280 1 delay_nop();
281 1 sda = 0; // sda low
282 1 delay_nop();
283 1 scl = 0; // scl low
284 1 delay_nop();
285 1 }
286
287 /*********************************************************************
288 Stop Function
289 *********************************************************************/
290 void stop_con()
291 {
292 1 bit end = 0; // A Flag => 0:Repeat stop motion
293 1 // 1:Complete stop motion
294 1 while (end == 0)
295 1 {
296 2 scl = 0; // scl low
297 2 delay_nop();
298 2 sda = 0; // sda low
299 2 delay_nop();
300 2 scl = 1; // scl high
301 2 delay_nop();
302 2 sda = 1; // sda high
303 2 delay_nop();
C51 COMPILER V7.50 FUNC_SHI 12/31/2004 22:02:01 PAGE 6
304 2 if (sda == 1) // Check the device response
305 2 {
306 3 end = 1; // Set "Complete" Flag
307 3 }
308 2 }
309 1 }
310
311 /*********************************************************************
312 Delay Function
313 Machine cycle = 24x2 + 12x3 = 84
314 Crystal Frequency = 20 MHz
315 Delay Time: 4.2us
316 *********************************************************************/
317 void delay_nop()
318 {
319 1 //_nop_ ();
320 1 //_nop_ ();
321 1 //_nop_ ();
322 1 }
323 /********************************************************************
324 Delay x ms Function
325 Crystal Frequency = 20 MHz
326 Delay Time: count x 1ms
327 ********************************************************************/
328 void DelayXms(unsigned char count)
329 {
330 1 unsigned char i,j;
331 1 for (i = 0;i < count;i++)
332 1 {
333 2 for (j = 0;j < 0xc8;j++)
334 2 {
335 3 _nop_();
336 3 }
337 2 }
338 1 }
339
340
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 512 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 1 23
IDATA SIZE = ---- ----
BIT SIZE = 1 3
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -