📄 plc.lst
字号:
289 // High-level API function
290
291 /* this function must be called before using any PLC API functions.
292 smod = SMOD_ASYNC or SMOD_SYNC, must be consistant with the hardware
293 smod pin connection.
294
295 int plc_init(uint smod)
296 {
297 cur_smod = smod;
298
299 if (cur_smod == SMOD_ASYNC)
300 uart_init();
C51 COMPILER V7.09 PLC 01/12/2007 09:29:48 PAGE 6
301
302 return 0;
303
304 } */
305 /*=============================================================================*/
306
307 int plc_config(uchar buf[], uint len)
308 {
309 1 // ET0 = 0;
310 1 send_block(buf, len);
311 1 // ET0 = 0;
312 1 return 1;
313 1 }
314
315
316 /*=============================================================================* /
317 int plc_send(uchar frame[])
318 {
319 // ET0 = 0;
320
321 write_txbuffer(frame);
322 send(); // send it!!
323
324 // ET0 = 1;
325
326 return 0;
327 }
328
329 /*=============================================================================*/
330 /*
331 int plc_resend()
332 {
333 ET0 = 0;
334 send(); // send current data in tx buffer
335 ET0 = 1;
336
337 return 0;
338 }
339 */
340
341 /*=============================================================================*/
342
343 int plc_recved()
344 {
345 1 return sync_recved();
346 1 }
347
348 /*=============================================================================*/
349
350 int plc_getframe(uchar *frame)
351 {
352 1 uint res;
353 1
354 1 res = read_buffer(BUF_RD_RXBUF, frame, frame_sz);
355 1
356 1 if (res < 0) return -1;
357 1
358 1 return frame_sz;
359 1
360 1 }
361
362 /* ================================================================* /
C51 COMPILER V7.09 PLC 01/12/2007 09:29:48 PAGE 7
363 /* ================================================================*/
364
365 void thres_adjust(void)
366 {
367 1 timeout_1s = 0;
368 1 rx_adj = 0;
369 1 rx_stop = 1;
370 1 wet = 0;
371 1 set_thres_eb(1);
372 1
373 1 disable_t2();//<-------------------------------关40秒定时
374 1
375 1 while(rx_stop){ //等待到上调
376 2 clr_wdt();
377 2 if(timeout_40s){ //<---------------------------时间到下调
378 3 thres_ea -= DEC_THRES_EA + INC_THRES_EA; //减8
379 3 if (thres_ea < MIN_THRES_EA) {thres_ea = MIN_THRES_EA; plc_power_on();} //最小16;
380 3 timeout_40s = 0;
381 3 set_thres_ea(thres_ea);
382 3 rx_adj = 0;
383 3 }
384 2
385 2 timeout_1s = 0;
386 2 setup_t0(600, ist_count); //定时1s
387 2 while(timeout_1s == 0){clr_wdt();}
388 2 if(wet > 4) {
389 3 thres_ea += INC_THRES_EA;
390 3 if (thres_ea > MAX_THRES_EA) thres_ea = MAX_THRES_EA; //
391 3 rx_adj = 1;
392 3 set_thres_ea(thres_ea);
393 3 }
394 2 if (wet == 4) {
395 3 thres_ea += DEC_THRES_EA;
396 3 if (thres_ea > MAX_THRES_EA){ thres_ea = MAX_THRES_EA; plc_power_on();} //
397 3 rx_adj = 1;
398 3 set_thres_ea(thres_ea);
399 3 rx_stop = 0;
400 3
401 3 }
402 2 else rx_stop = 0;//如果发现rx_busy不在闪,跳出
403 2 wet = 0;
404 2 }
405 1
406 1
407 1 disable_t0(); // 关1秒定时
408 1
409 1 clr_wdt(); //重设看门狗
410 1
411 1 thres_ea += INC_THRES_EA;
412 1 if (thres_ea > MAX_THRES_EA) thres_ea = MAX_THRES_EA;
413 1 set_thres_ea(thres_ea);
414 1 // uart_sendchar(0xf0);
415 1 // uart_sendchar(thres_ea);
416 1 set_thres_eb(thres_ea>>1);
417 1 wet = 0;
418 1 setup_t2(4000, timeout_t2);
419 1 }
420
421 /*=============================================================================*/
422
423
424 void timeout_t3(void)
C51 COMPILER V7.09 PLC 01/12/2007 09:29:48 PAGE 8
425 {
426 1 disable_t3(); //t3_enable = 0;停计数100ms
427 1
428 1 // Test if RX_BUSY is still low
429 1 if (RX_BUSY){wet ++;}
430 1
431 1 else {
432 2 // wet = 0; // recved, clear it
433 2 packet_recved = 1;
434 2 packet_recving = 1;
435 2 }
436 1 }
437
438 /*=============================================================================*/
439
440 void RX_BUSY_ISR (void) interrupt 2 //执行外部中断1
441 {
442 1 // RX_BUSY is low, setup t3 and test RX_BUSY again when timeout.
443 1 setup_t3(10, timeout_t3); //设定100ms秒时间中断次数.
444 1 packet_recving = 0;
445 1 //wet ++;
446 1 }
447
448
449 /*=============================================================================*/
450 void ist_count()/* //计1秒中断次数 */
451 {
452 1 timeout_1s = 1;
453 1 //disable_t0();
454 1 }
455
456 /*=============================================================================*/
457
458 void timeout_t2(void)
459 {
460 1 timeout_40s = 1;
461 1 // disable_t2();
462 1 }
463
464 /*=============================================================================*/
465
466 void timeout_t4(void)
467 {
468 1 delay_tx = 0;
469 1 disable_t4();
470 1 }
471 /*=============================================================================*/
472 /*=============================================================================*/
473
474 // Perform initialization of PLC modem after power on
475 void plc_power_on(void)
476 {
477 1 uint i;
478 1 clr_wdt();
479 1 // Reset LME2200
480 1 // ET0 = 0;
481 1 RST_PLC = 0;
482 1 for (i = 0; i < 3000; i++) {;}
483 1 clr_wdt();
484 1 RST_PLC = 1;
485 1 for (i = 0; i < 100; i++) {;}
486 1 // ET0 = 1;
C51 COMPILER V7.09 PLC 01/12/2007 09:29:48 PAGE 9
487 1 // Configure PLC
488 1 plc_config(plc_setting, sizeof(plc_setting));
489 1 clr_wdt();
490 1 //plc_config(WtFIR,sizeof(WtFIR));
491 1 clr_wdt();
492 1 // Initial threshold measurement & setting
493 1 set_thres_eb(0);
494 1 thres_set = 0;
495 1 thres_ea = 0x05;
496 1
497 1 while (thres_set < 4) {
498 2 wet = 0;
499 2 timeout_1s = 0;
500 2 setup_t0(600, ist_count); //1.6s
501 2 // wait for 1s
502 2 while (timeout_1s == 0) { clr_wdt();}
503 2 disable_t0();//关1S定时
504 2 if (wet > 4) {
505 3 thres_ea += INC_THRES_EA;
506 3 if (thres_ea > MAX_THRES_EA) thres_ea = MAX_THRES_EA;
507 3 set_thres_ea(thres_ea);
508 3 }
509 2 else { thres_set++; }
510 2 }
511 1
512 1 thres_ea += INC_THRES_EA;
513 1 if (thres_ea > MAX_THRES_EA) thres_ea = MAX_THRES_EA;
514 1 set_thres_ea(thres_ea);
515 1 set_thres_eb(thres_ea>>1);
516 1 clr_wdt();
517 1
518 1 packet_recved = 0;
519 1 packet_recving = 0;
520 1 wet = 0;
521 1 }
522 /*=============================================================================*/
523 /*=============================================================================*/
524
525 void w_flsh(uchar dat,uchar dat1)
526 {
527 1 uchar buf[2];
528 1
529 1 write_reg(REG_WR_33, dat);
530 1 write_reg(REG_WR_3c, dat1);
531 1 buf[0] = dat;
532 1 buf[1] = dat1;
533 1 EA = 0;
534 1 FLASH_WriteNByte(0x1c00, buf, 2);
535 1 // FLASH_WriteByte(0x1c05,dat); // (int code *)&plc_setting[5]
536 1 // FLASH_WriteByte(0x1c06,dat1);//(int code *)&plc_setting[23]
537 1 EA = 1;
538 1 }
539
540 /*=============================================================================*/
541 // 家电智能控制统一程序(根据UPLM2200 API协议设定)
542 // 接收应答处理
543 /*=============================================================================* /
544 void Rx_Command_Reply(uchar comm)
545 {
546 uchar Command;
547 Command = comm & 0x3f;
548 switch(Command){ //B5~B0 命令字
C51 COMPILER V7.09 PLC 01/12/2007 09:29:48 PAGE 10
549
550 case 0x01:{reply = 1;}break;
551
552 case 0x02:{reply = 0;}break;
553 }
554 }
555
556 /*=============================================================================*/
557 /*=============================================================================*/
558
559 void Remote_Replies(uchar buf[])//远程测试应答
560 {
561 1 buf[0] = 0xa1;//B7B6 = 10;B5~B0 = 0x21h;
562 1 while(delay_tx)clr_wdt(); /*-延迟返回------*/
563 1 write_txbuffer(buf); //写入2200c
564 1 sync_sendchar(0x7e);
565 1 }
566
567 /*$$$$$$$$$$$$$$$$$$$$$$$$$$$$<<<<<软件说明>>>>>$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$* /
568 软件修改说明在main.c,敬请留意
569 /*$$$$$$$$$$$$$$$$$$$$$$$$$$$$<<<<<软件说明>>>>>$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
570
571
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 887 ----
CONSTANT SIZE = 28 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 29
IDATA SIZE = 5 ----
BIT SIZE = 8 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -