📄 display.lst
字号:
C51 COMPILER V6.21 DISPLAY 02/20/2008 14:30:37 PAGE 1
C51 COMPILER V6.21, COMPILATION OF MODULE DISPLAY
OBJECT MODULE PLACED IN DISPLAY.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE DISPLAY.C BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include<intrins.h>
2 #include <string.h>
3 #include "REG52.H"
4
5 #define DATA_PORT P0
6 #define LEN P2_0
7 #define BEN P2_1
8 #define DIR P2_2
9 #define HBIT P2_3
10 // To read DIP switch
11 #define ID1 P1_0
12 #define ID2 P1_1
13 #define ID3 P1_2
14 #define ID4 P1_3
15
16
17 #define CBYTE ((unsigned char volatile code *)0)
18 #define DBYTE ((unsigned char volatile idata *) 0)
19
20 idata char rxbuff[14]; //14
21 idata char txbuff[12]; //11
22
23 //union
24 idata union mod_data
25 {
26 float fdata[1];
27 unsigned char regbuff[5];
28 };
29
30 union mod_data a;
31
32 #define ST_RD_03 0x0
33 #define EN_RD_03 0x3
34 #define FN03_SUP 0x01
35
36 #define ST_RD_04 0x0
37 #define EN_RD_04 0x3
38 #define FN04_SUP 0x01
39
40 #define ST_WR_16 0x0
41 #define EN_WR_16 0x3
42 #define FN16_SUP 0x01
43
44 #define EOFTM 0x05
45
46 code unsigned char orl_data[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
47 code unsigned char anl_data[8]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};
48 //--------------------------------------------------------------
49 //BITS
50 //-------------------------------------------------------------
51 //Com1 Related
52 idata bit com1_rec,com1_eof,com1_485dlystart,com1_485dlyend;
53
54 //General
55 idata bit ws,flag,dummy;
C51 COMPILER V6.21 DISPLAY 02/20/2008 14:30:37 PAGE 2
56 idata bit valid_ok,flg_read,flg_analog;
57 idata bit fun_sup,flg_single,flg_wrongfn,fun_support;
58
59
60 //Characters
61 //Com1
62 idata unsigned char com1_txchar,com1_rxchar,com1_rxcnt,com1_txcnt,com1_eofcnt,com1_eoftm;
63 idata unsigned char com1_offset,com1_dirdlycnt,com1_dirdlytm;
64
65 //General Modbus
66 idata unsigned char mod_fn,exc_code,crch,crcl;
67 idata unsigned char mod_txlen,mod_txcnt,rx_dbcnt; // can be removed
68 idata unsigned char mod_srcaddr,mod_destaddr;
69 idata unsigned char start_addr,end_addr,rec_addr,rec_length,addr_offset;
70 idata unsigned int result,poly=40961;
71 idata unsigned char Hbitcnt;
72 //idata unsigned char remainder;
73
74 //ModDrv1
75 idata volatile unsigned char mod1_state,mod1_devid;
76 //
77 idata unsigned int indata;
78 idata bit ndata =0 ; // new data
79 //idata char decnt =0;
80
81 void init(void);
82 void ModSlave1(void);
83 void validate(unsigned char,unsigned char);
84 void read_response(unsigned char,unsigned char,unsigned char);
85 void write_response(unsigned char,unsigned char);
86 void store_data(unsigned char,unsigned char,unsigned char);
87 void store16(unsigned char,unsigned char,unsigned char);
88 void com1_txmode(void);
89 void com1_tx(void);
90 void com1_rxmode(void);
91 void cal_crc(unsigned char);
92 void read3_4(unsigned char,unsigned char,unsigned char);
93 void dly(unsigned int);
94 void TransmitChar(unsigned char );
95 void Output(unsigned char out);
96 /******************************************************************************/
97 /* INTERRUPT0 interrupt service function */
98 /******************************************************************************/
99 /******************************************************************************/
100 /* Timer 0 interrupt service function */
101 /* executes each 250us @ 12 MHz Crystal Clock */
102 /******************************************************************************/
103 void timer0 (void) interrupt 1 using 1{ /* Int Vector at 000BH, Reg Bank 1 */
104 1 // static volatile char i=0;
105 1 // P1_5 = ~P1_5; //power led
106 1 Hbitcnt ++;
107 1 if (Hbitcnt == 250)
108 1 {
109 2 HBIT = ~HBIT;
110 2 Hbitcnt = 0;
111 2 }
112 1
113 1 TH0 = 0xFC; /* set timer period */
114 1 TL0 = 0x65;
115 1 TR0 = 1; /* start timer 0 */
116 1
117 1 if(com1_rec==1)
C51 COMPILER V6.21 DISPLAY 02/20/2008 14:30:37 PAGE 3
118 1 {
119 2 com1_eofcnt--;
120 2 if(com1_eofcnt==0)
121 2 {
122 3 com1_eof=1;
123 3 com1_rec=0;
124 3 }
125 2 }
126 1
127 1 if(com1_485dlystart==1)
128 1 {
129 2 com1_dirdlycnt--;
130 2 if(com1_dirdlycnt==0)
131 2 {
132 3 com1_485dlyend=1;
133 3 com1_485dlystart=0;
134 3 }
135 2 }
136 1 }
137
138 /*------------------------------------------------
139 Received data interrupt.
140 ------------------------------------------------*/
141
142 static void com_isr (void) interrupt 4 using 2
143 {
144 1 if (RI != 0)
145 1 {
146 2 RI = 0;
147 2 rxbuff[com1_rxcnt]=SBUF;
148 2 com1_rec=1;
149 2 com1_rxcnt++;
150 2 com1_eofcnt=com1_eoftm;
151 2 }
152 1 }
153
154 /*------------------------------------------------
155 Received data interrupt.
156 ------------------------------------------------*/
157
158
159 void main(void)
160 {
161 1 unsigned char cnt;
162 1
163 1 for(cnt=0;cnt<9;cnt++)
164 1 {dly(1000);}
165 1 init();
166 1 TransmitChar('V');
167 1 TransmitChar('E');
168 1 TransmitChar('R');
169 1 TransmitChar('1');
170 1
171 1 while(1)
172 1 {
173 2 Output(0x00);
174 2 // TransmitChar(P1 & 0x0f);
175 2 dly(60000);
176 2 Output(0xff);
177 2 dly(60000);
178 2 // ModSlave1();
179 2
C51 COMPILER V6.21 DISPLAY 02/20/2008 14:30:37 PAGE 4
180 2 }
181 1 }
182 void init (void)
183 {
184 1 //idata unsigned char poip;
185 1 // P1_5 = 0; //Power on LED
186 1 LEN = 0;
187 1 BEN = 1;
188 1 P0 = 0x00; ;
189 1 P2 = 0x00; ;
190 1 //TIMER SETTINGS
191 1 TMOD |= 0x21; // timer0 = 16bit, timer1 = auto reload
192 1 TH0 = 0xFC; // Timer 0 1ms
193 1 TL0 = 0x65; //
194 1 TR0 = 1;
195 1 ET0 = 1; // enable timer 0 int
196 1
197 1 //SERIAL PORT 0
198 1 SCON = 0x50; // initilise serial port 0
199 1 ES = 1; //serial int 0
200 1 // TXD = 0;
201 1 // RXD = 0;
202 1
203 1 //TIMER SETTINGS
204 1 TMOD |= 0x21; // timer0 = 16bit, timer1 = auto reload
205 1 TH1 = 0xFD; // Baud rate = 9600
206 1 TL1 = 0xFD;
207 1 ET1 = 0; //Disable timer 1 int
208 1 TR1 = 1; //start timer 1
209 1
210 1
211 1 //ENABLE ALL INTSERRUPTS
212 1 EA = 1; //enable all interrupt
213 1
214 1 //ENABLE VARIABLES REQUIRED IN THE PRG
215 1 com1_rec=0;
216 1 com1_eofcnt=0;
217 1 com1_eoftm=EOFTM;
218 1 com1_eof=0;
219 1 com1_dirdlytm=2;
220 1 com1_485dlystart=0;
221 1 com1_485dlyend=0;
222 1 com1_rxcnt=0;
223 1
224 1
225 1 //poip= //25-3 2006 p1->p0 // Enter device ID
226 1 mod1_devid= ~(P1) & 0x0f ; //(~P1)&0x0f;
227 1 mod1_state=1;
228 1
229 1 //com1_rxmode();
230 1 }
231
232 void TransmitChar(unsigned char asc)
233 {
234 1
235 1 ES = 0;
236 1 SBUF=asc;
237 1 while(!TI);
238 1 TI=0;
239 1 ES=1;
240 1 }
241
C51 COMPILER V6.21 DISPLAY 02/20/2008 14:30:37 PAGE 5
242 void ModSlave1(void)
243 {
244 1 idata unsigned char temp1;
245 1 switch (mod1_state)
246 1 {
247 2 case 1:
248 2 if(com1_eof==1)
249 2 {
250 3 com1_eof=0;
251 3 com1_rxcnt=0;
252 3 temp1=rxbuff[0];
253 3 if(temp1==((~P1)&0x0f))
254 3 {
255 4 mod1_state=2;
256 4 }
257 3 else
258 3 {
259 4 mod1_state=1;
260 4 ES=1;
261 4 }
262 3 }
263 2
264 2 break;
265 2
266 2 case 2:
267 2 validate(rxbuff,txbuff);
268 2 if(valid_ok==1)
269 2 {
270 3 if(flg_read==1)
271 3 {
272 4 read_response(rxbuff,txbuff,a.regbuff);
273 4 }
274 3 else
275 3 {
276 4
277 4 write_response(rxbuff,txbuff);
278 4
279 4 if(mod_fn==16)
280 4 {
281 5 store_data(rxbuff,txbuff,a.regbuff);
282 5
283 5 }
284 4 }
285 3 }
286 2 mod1_state=3;
287 2 com1_offset=0;
288 2 ES=0;
289 2 com1_txcnt=mod_txcnt;
290 2 com1_txmode();
291 2 break;
292 2
293 2 case 3:
294 2 com1_txchar=txbuff[com1_offset];
295 2 mod1_state=4;
296 2 com1_tx();
297 2 break;
298 2
299 2 case 4:
300 2 if(TI==1)
301 2 {
302 3 TI=0;
303 3 mod1_state=3;
C51 COMPILER V6.21 DISPLAY 02/20/2008 14:30:37 PAGE 6
304 3 com1_offset++;
305 3 com1_txcnt--;
306 3 if(com1_txcnt==0)
307 3 {
308 4 com1_dirdlycnt=com1_dirdlytm;
309 4 com1_485dlystart=1;
310 4 mod1_state=5;
311 4 com1_offset=0;
312 4 }
313 3 }
314 2 break;
315 2
316 2 case 5:
317 2 if(com1_485dlyend==1)
318 2 {
319 3 com1_rxmode();
320 3 com1_485dlystart=0;
321 3 com1_485dlyend=0;
322 3 mod1_state=1;
323 3 ES=1;
324 3 }
325 2 break;
326 2
327 2 default:
328 2 break;
329 2 }
330 1 }
331
332 void validate(unsigned char rx_buff,unsigned char tx_buff)
333 {
334 1 unsigned char temp1;
335 1 valid_ok=0;
336 1 flg_read=0;
337 1 flg_analog=0;
338 1 flg_single=0;
339 1 flg_wrongfn=0;
340 1 //mod_devid=DBYTE[rx_buff];
341 1 mod_fn=DBYTE[rx_buff+1];
342 1
343 1 switch(mod_fn)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -