📄 rtu.lst
字号:
C51 COMPILER V7.06 RTU 06/25/2008 15:44:08 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE RTU
OBJECT MODULE PLACED IN RTU.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\c51.exe RTU.C DB OE
stmt level source
1 //********************************************************************************************************
-******************
2 #include <c8051F020.h>
3 #include <stdio.h>
4 #include "HEAD.H"
5 //********************************************************************************************************
-******************
6 void RTU_Data(void)
7 {
8 1 xdata unsigned int temp1,temp2;
9 1 xdata unsigned int addres,bytes;
10 1
11 1 temp1 = CRC16(DatPocket,0,DatLong-2);
12 1 temp2 = DatPocket[DatLong-1];
13 1 temp2|= DatPocket[DatLong-2]<<8; // 解析校验码
14 1 if(temp1==temp2) // 校验码正确
15 1 {
16 2 if(DatPocket[0] == DeviceNum) // 检测设备地址号
17 2 {
18 3 LED2_ON;
19 3 addres = DatPocket[2]; // 解析地址
20 3 addres <<= 8;
21 3 addres &= 0xFF00;
22 3 addres |= DatPocket[3];
23 3 bytes = DatPocket[4]; // 解析数据量
24 3 bytes <<= 8;
25 3 bytes &= 0xFF00;
26 3 bytes |= DatPocket[5];
27 3 // 得到地址和数据量
28 3 if(DatPocket[1] == 0x03) // 读取寄存器数据
29 3 {
30 4 Read_RTU_4(addres,bytes);
31 4 }
32 3 else if(DatPocket[1] == 0x06) // 设置单寄存器
33 3 {
34 4 Write_RTU_4(addres,bytes);
35 4 }
36 3 else if(DatPocket[1] == 0x08) // 设置单寄存器
37 3 {
38 4 DatPocket[0]=DeviceNum;
39 4 DatPocket[1]=0x08;
40 4 DatPocket[2]=NowWellNum;
41 4 Pocket(DatPocket,3);
42 4 Com_Send_String(DatPocket,5,ComFlag);
43 4 }
44 3 else if(DatPocket[1] == 0x09) // 设置单寄存器
45 3 {
46 4 DateUpLoadFlag=DatPocket[2];
47 4 //UpLoadWellDateTure(DatPocket[2]);
48 4 }
49 3 LED2_OFF;
50 3 }
51 2 }
52 1 DatLong=0x00; // 串口数据指针清零
53 1 }
C51 COMPILER V7.06 RTU 06/25/2008 15:44:08 PAGE 2
54 //********************************************************************************************************
-******************
55 void Write_RTU_4(unsigned int firstadress,unsigned int bytes)
56 {
57 1 RTUaddress4[firstadress*2]=bytes>>8;
58 1 RTUaddress4[firstadress*2+1]=bytes;
59 1
60 1 // 修改时间
61 1 if(firstadress<3)
62 1 {
63 2 if(firstadress==0x00)
64 2 {
65 3 DS1302_Write_Byte(0x8e,0x00); // 停止计时
66 3 DS1302_Write_Byte(0x88,bytes); // month
67 3 DS1302_Write_Byte(0x8c,bytes>>8); // year
68 3 DS1302_Write_Byte(0x8e,0x80); // 开始计时
69 3 }
70 2 if(firstadress==0x01)
71 2 {
72 3 DS1302_Write_Byte(0x8e,0x00); // 停止计时
73 3 DS1302_Write_Byte(0x84,bytes); // hour
74 3 DS1302_Write_Byte(0x86,bytes>>8); // day
75 3 DS1302_Write_Byte(0x8e,0x80); // 开始计时
76 3 }
77 2 if(firstadress==0x02)
78 2 {
79 3 DS1302_Write_Byte(0x8e,0x00); // 停止计时
80 3 DS1302_Write_Byte(0x80,0x00); // sec
81 3 DS1302_Write_Byte(0x82,bytes>>8); // min
82 3 DS1302_Write_Byte(0x8e,0x80); // 开始计时
83 3 }
84 2 }
85 1
86 1 // DAC输出
87 1 if(firstadress==14)
88 1 {
89 2 DAC_OUT_1(RTUaddress4[28]<<8 | RTUaddress4[29]);
90 2 }
91 1 if(firstadress==15)
92 1 {
93 2 DAC_OUT_2(RTUaddress4[30]<<8 | RTUaddress4[31]);
94 2 }
95 1
96 1
97 1 Com_Send_String(DatPocket,DatLong,ComFlag);
98 1 }
99 //********************************************************************************************************
-******************
100 void Read_RTU_4(unsigned int firstadress,unsigned int bytess)
101 {
102 1 xdata unsigned char i;
103 1
104 1 DatPocket[0]=DeviceNum;
105 1 DatPocket[1]=0x03;
106 1 DatPocket[2]=2*bytess;
107 1 for(i=0;i<2*bytess;i++)
108 1 {
109 2 DatPocket[3+i]=RTUaddress4[2*firstadress+i];
110 2 }
111 1 Pocket(DatPocket,3+2*bytess);
112 1 Com_Send_String(DatPocket,5+2*bytess,ComFlag);
113 1 }
C51 COMPILER V7.06 RTU 06/25/2008 15:44:08 PAGE 3
114 //********************************************************************************************************
-******************
115 void Pocket(unsigned char * Data,unsigned char D_Long)
116 {
117 1 xdata unsigned int temp0;
118 1
119 1 temp0 = CRC16(Data,0,D_Long);
120 1 Data[D_Long+1]= temp0;
121 1 Data[D_Long] = temp0>>8;
122 1 }
123 //********************************************************************************************************
-******************
124 unsigned int CRC16(unsigned char *buf,int start,int cnt)
125 {
126 1 xdata int i,j;
127 1 xdata unsigned int temp=0,flag=0,temp1=0;
128 1
129 1 temp = 0xFFFF;
130 1 for (i=start; i<cnt; i++)
131 1 {
132 2 temp = temp ^ buf[i];
133 2 for (j=1; j<=8; j++)
134 2 {
135 3 flag = temp & 0x0001;
136 3 temp = temp >> 1;
137 3 if (flag)
138 3 temp = temp ^ 0xA001;
139 3 }
140 2 }
141 1 // Reverse byte order.
142 1 temp1 = temp >> 8;
143 1 temp = (temp << 8) | temp1;
144 1 temp &= 0xFFFF;
145 1
146 1 return(temp);
147 1 }
148 //********************************************************************************************************
-******************
149 //THE END
150 //********************************************************************************************************
-******************
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 959 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- 21
PDATA SIZE = ---- ----
DATA SIZE = ---- 17
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -