📄 main.lst
字号:
C51 COMPILER V7.09 MAIN 01/12/2007 09:30:14 PAGE 1
C51 COMPILER V7.09, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c ROM(COMPACT) OPTIMIZE(9,SPEED) BROWSE MODP2 DEBUG OBJECTEXTEND PREPR
-INT
line level source
1 /* //////////////////////////////////////////////////////////////////////////
2 // main.c - source file for lme2200 AMR
3 //
4 // 家电智能控制统一主机程序(根据UPLM2200 API协议设定)
5 // Copyright 2006, Leaguer MicroElectronics Co., Ltd
6 // www.leaguerme.com
7 //
8 // 软件修改说明在页底,敬请留意
9 //////////////////////////////////////////////////////////////////////////// */
10 #include <REG922.H>
11
12 #include "timer.h"
13 #include "sart.h"
14 #include "plc.h"
15 #include "wr_flash.h"
16
17
18 #define uint unsigned int
19 #define uchar unsigned char
20
21 /*============================版本号========================================*/
22 #define Version1 0x01 //版本号1
23 #define Version2 0x01 //版本号2
24 /*=============================================================================*/
25
26 #define AMR_OS_C 0 //本协议的控制字在第一位
27 #define AMR_OS_L 5 //本协议的长度值在第五位
28
29 #define S2400 40
30 #define S1200 50
31 #define S600 80
32
33 uchar code ADSS[4];
34 uchar plc_frame[18];
35 uchar code mcu_pc[5]= {0xfe,0xfe,0xfe,0xfe,0x68};
36 uchar code tx_buf[] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x1
-1,0x12};
37 uchar code master = 0;
38
39 extern idata uchar amr_frame[]; // AMR frame buffer
40 extern idata uchar wet;
41
42 uchar CRC;//电力网收到CRC的值
43 extern bit timeout_40s;
44 extern bit delay_tx;
45 extern bit packet_recved;
46 extern bit packet_recving;
47 extern bit t1_enable;
48 bit reply;
49 bit adss_ok;
50 bit CRC_switch;//CRC开关
51 void proc_amr_frame(uchar frame[]);
52 void amr_send_frame(uchar buf[]);
53 void return_inf(uchar frame,uchar inf_buf[],uchar dat);
C51 COMPILER V7.09 MAIN 01/12/2007 09:30:14 PAGE 2
54 void uart_tx_mode(uchar i_buf[]);
55 void rx_return(bit y,uchar R_data[]);
56 int plc_send(uchar frame[]);
57 void return_data();
58 void adss_crc(uchar buf[]);//地址校验
59
60 //void w_flsh(uchar dat,uchar dat1);
61
62 /*=============================================================================*/
63 /* 主程序 */
64 /*=============================================================================*/
65 main() {
66 1
67 1 uchar l;
68 1 uchar buf[2];
69 1 P0M1 = 0x80; // 这是为第二版电力载波的小模块,发射部分是安捷伦的810方案 -IO口的定义
70 1 P0M2 = 0x41;
71 1 P1M1 = 0x7c;
72 1 P1M2 = 0x80;
73 1
74 1 Rxok = 0;
75 1 timer0_init(242, 10); // 1ms * 10 = 10ms
76 1 // plc_init(SMOD_SYNC);
77 1 uart_init(); //<--------------串口初始化
78 1 //relay_init();
79 1 wdt_init();//<----------------看门狗初始化
80 1 clr_wdt();
81 1 plc_power_on();
82 1
83 1 for(l = 0;l < 18;l ++)
84 1 plc_frame[l] = 0;
85 1 clr_wdt();
86 1 timeout_40s = 0;
87 1 setup_t2(4000, timeout_t2); //原10S
88 1
89 1 setup_t1(30, disable_t1); //定时LED为300ms
90 1 plc_getframe(plc_frame); //查收8300的数据
91 1
92 1 FLASH_ReadNByte(0x1c00,buf, 2);
93 1 if(buf[0]!= 0){
94 2 write_reg(REG_WR_33, buf[0]);
95 2 write_reg(REG_WR_3c, buf[1]);
96 2 }
97 1 // FLASH_ReadNByte(0x1b05,buf, 2);
98 1 // master_slave = (bit)buf[0];
99 1
100 1
101 1 while (1) { // the forever loop
102 2
103 2 if (uart_recved()) { // AMR frame recved from meter
104 3 disable_t2();//<-------------------------------关40秒定时
105 3 if (recv_amr_frame()) { //uart_sendblock(amr_frame,4);
106 4 clr_wdt();
107 4 // uart_sendblock(amr_frame, amr_frame[5]+6); //串口送至PC
108 4 proc_amr_frame(amr_frame); //最多26个字节
109 4 clr_wdt();
110 4 }
111 3 }
112 2
113 2 if (packet_recving) {//收到电力线上的数据
114 3 disable_t2();//<-------------------------------关40秒定时
115 3 while (!plc_recved()) { clr_wdt();}// wait until packet is recved
C51 COMPILER V7.09 MAIN 01/12/2007 09:30:14 PAGE 3
116 3 packet_recving = 0; // reset it
117 3 plc_getframe(plc_frame);// read packet data
118 3 clr_wdt();
119 3 setup_t4(40, timeout_t4);delay_tx = 1; /*-延迟返回初始化-不可小于35*/
120 3 CRC = read_crc(); //取CRC的值
121 3 if (CRC == 0) { // check CRC21
122 4 Rxok = 0; clr_wdt();
123 4 t1_enable = 1;
124 4 adss_crc(plc_frame); //LED定时300ms
125 4 if(adss_ok==1){;//地址校验)//地址是否对
126 5 adss_ok = 0;
127 5 amr_send_frame(plc_frame); //数据发入串口
128 5 while(delay_tx)clr_wdt(); /*-延迟返回------*/
129 5 //Rx_Command_Reply(plc_frame[0]);//测试回复控制
130 5 //if(reply){
131 5 //Remote_Replies(plc_frame);//测试回复
132 5 clr_wdt();
133 5 //}
134 5 }}
135 3 if(CRC_switch){ //CRC开关
136 4 rx_return(0,plc_frame); //数据发入串口
137 4 clr_wdt(); /*-延迟返回------*/
138 4 }
139 3
140 3 setup_t2(4000, timeout_t2); //40S
141 3 }
142 2
143 2 if (timeout_40s)// Auto thres adjustment
144 2 {
145 3 thres_adjust();
146 3 packet_recved = 0; // reset it
147 3 }
148 2
149 2 if(~t1_enable)Rxok = 1;
150 2
151 2 clr_wdt();
152 2 plc_getframe(plc_frame);
153 2 clr_wdt();
154 2 }
155 1 }
156
157 /*=============================================================================*/
158 /*=============================================================================*/
159
160 // Process the received AMR message/cmd from meter
161 /*=============================================================================*/
162
163 void proc_amr_frame(uchar frame[])
164 {
165 1 uchar m_buf[2];
166 1 uchar contror_me;//B7B6 控制字
167 1 uchar command; //B5~B0 命令字
168 1 contror_me = (frame[AMR_OS_C] & 0xc0)>>6; //B7B6 控制字
169 1 command = frame[AMR_OS_C] & 0x3f; //B5~B0 命令字
170 1
171 1 switch (contror_me){
172 2 Rxok = 0;
173 2
174 2 case 0x00:{ uart_tx_mode(frame);}break;//发送到远方模块
175 2
176 2 case 0x01:{//本地设置控制
177 3
C51 COMPILER V7.09 MAIN 01/12/2007 09:30:14 PAGE 4
178 3 switch (command){
179 4 case 0x01:{if(frame[AMR_OS_L] == 0){m_buf[0] = Version1;m_buf[1] = Version2;return_i
-nf(0x61,m_buf,2);}}break;//读版本号
180 4
181 4 case 0x02:{if(frame[AMR_OS_L] == 0){m_buf[0] = read_reg(REG_RD_F3);return_inf(0x62,m
-_buf,1);}}break;//读速率信息
182 4
183 4 case 0x03:{
184 5 if(frame[AMR_OS_L] == 1){
185 6 switch (frame[AMR_OS_L + 1] ){
186 7
187 7 case 0x01:{ w_flsh(0x01,0x04);}break; //设置速率2400bps
188 7
189 7 case 0x02:{ w_flsh(0x02,0x02);}break; //设置速率1200bps
190 7
191 7 case 0x04:{ w_flsh(0x04,0x01);}break; //设置速率 600bps
192 7 }
193 6 m_buf[0] = read_reg(REG_RD_F3);return_inf(0x62,m_buf,1);}}break;//读速率信息
194 4
195 4 case 0x04:{if(frame[AMR_OS_L] == 0)CRC_switch = 1;}break;//读设置接收数据CRC报出
196 4
197 4 case 0x05:{if(frame[AMR_OS_L] == 0)CRC_switch = 0;}break;//读设置接收数据CRC不报出
198 4
199 4 case 0x06:{;}break;
200 4
201 4 case 0x07:{;}break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -