📄 zhongcai.lst
字号:
C51 COMPILER V7.50 ZHONGCAI 03/17/2008 20:44:52 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE ZHONGCAI
OBJECT MODULE PLACED IN ZhongCai.OBJ
COMPILER INVOKED BY: C:\Program Files\Keil\C51\BIN\C51.EXE ZhongCai.c BROWSE DEBUG OBJECTEXTEND
line level source
1 //#include <SM89516A.h>
2 #include <reg52.h>
3 #include <string.h>
4 #include <math.h>
5 #include <intrins.h>
6 #include <stdio.h>
7 #include "MyRam.h"
8 #include "ComRam.h"
9
10 #define uchar unsigned char
11 #define uint unsigned int
12
13 /**************************************公共RAM区地址分配*****************************************/
14 //公共RAM区从机采集数据包存储开始地址.
15 #define ComSlaveDataStart1 0x0000 //000H~2FFH 公共RAM区从机1的数据的开始地址.
16 #define ComSlaveLenAdd1 0x02FE //公共RAM区从机1数据字节数的存贮地址.
17
18 #define ComSlaveDataStart2 0x0300 //300H~5FFH 公共RAM区从机2的数据的开始地址.
19 #define ComSlaveLenAdd2 0x05FE //公共RAM区从机2数据字节数的存贮地址。
20
21 #define ComSlaveDataStart3 0x0600 //600H~8FFH 公共RAM区从机3的数据的开始地址.
22 #define ComSlaveLenAdd3 0x08FE //公共RAM区从机3数据字节数的存贮地址。
23
24 #define ComSlaveDataStart4 0x0900 //900H~BFFH 公共RAM区从机4的数据的开始地址.
25 #define ComSlaveLenAdd4 0x0BFE //公共RAM区从机4数据字节数的存贮地址。
26
27 #define ComSlaveDataStart5 0x0C00 //C00H~EFFH 公共RAM区从机5的数据的开始地址.
28 #define ComSlaveLenAdd5 0x0EFE //公共RAM区从机5数据字节数的存贮地址。
29
30 /*******从机的报警区********/
31 #define ComAlarmStart1 0x1000 //1000H-10FDH 公共RAM区从机1报警的起始地址。
32 #define ComAlarmLenAdd1 0x10FE //10FEH-10FFH 公共RAM区从机1报警数据总长度的存储地址。
33 #define ComAlarmStart2 0x1100 //1100H-10FDH 公共RAM区从机2报警的起始地址。
34 #define ComAlarmLenAdd2 0x11FE //11FEH-11FFH 公共RAM区从机2报警数据总长度的存储地址。
35 #define ComAlarmStart3 0x1200 //1200H-12FDH 公共RAM区从机3报警的起始地址。
36 #define ComAlarmLenAdd3 0x12FE //12FEH-12FFH 公共RAM区从机3报警数据总长度的存储地址。
37 #define ComAlarmStart4 0x1300 //1300H-13FDH 公共RAM区从机4报警的起始地址。
38 #define ComAlarmLenAdd4 0x13FE //13FEH-13FFH 公共RAM区从机4报警数据总长度的存储地址。
39 #define ComAlarmStart5 0x1400 //1400H-14FDH 公共RAM区从机5报警的起始地址。
40 #define ComAlarmLenAdd5 0x14FE //14FEH-14FFH 公共RAM区从机5报警数据总长度的存储地址。
41
42 //公共RAM区从机命令数据包存放开始地址.
43 #define ComOrderStart 0x1500 //1500H~4FFFH 公共RAM区发给从机命令的起始地址。
44 #define ComLenOrder 0x4FFE //公共RAM区从机命令字节数的存贮RE认为》256N。
45 #define ComNewOrderFlag 0x4FFD //公共RAM区有新从机命令的标识位。
46
47 //公共RAM区从机时间命令数据包存放开始地址.
48 #define ComTimeStart 0x5000 //5000H~50FFH 公共RAM区日期和时间的其实地址。
49 #define ComLenTimer 0x50FE //公共RAM区时间字节数存贮地址。
50
51 //公共RAM区输出数据包存放开始地址.
52 #define ComOutputStart 0x5100 //5100H~6FFFH 公共RAM区发给输出单片机的起始地址。
53 #define ComLenOutput 0x6FFE //公共RAM区输出字节数存贮地址。
54
55 //公共RAM区从机使能数据包存放开始地址.
C51 COMPILER V7.50 ZHONGCAI 03/17/2008 20:44:52 PAGE 2
56 #define ComSlaveEnable 0x7500 //公共RAM区从机使能数据包存贮地址.
57 #define ComLenSlaveEnable 0x7510 //公共RAM区从机使能数据包状态标识存贮地址.
58 #define ComSlaveEnableNewFlag 0x7511 //公共RAM区从机使能数据包状态标识存贮地址.
59 /**************************************公共RAM区地址分配*****************************************/
60
61 /**************************************服务器命令数据包接收信息**********************************/
62 //接收状态。
63 #define InitState 0 //开始接收状态。
64 #define CommandState 1 //命令包状态。
65 #define DataState 2 //数据状态。
66
67 //数据包头及数据包长度。
68 #define StartFlag 0x2A //包开始标识。
69
70 #define CmdWs 0xA1 //外设参数数据包。
71 #define LenCmdWs 0x0E //外设参数数据包长度。
72
73 #define CmdSlave 0xA2 //从机参数数据包。
74 #define LenCmdSlave 0x08 //从机参数数据包长度。
75
76 #define CmdTime 0xA3 //时间同步数据包。
77 #define LenCmdTime 0x09 //时间同步数据包长度。
78
79 #define CmdAlarm 0xA4 //联动配置表数据包。
80 #define LenCmdAlarm 0x05 //联动配置表数据包长度。
81
82 #define CmdWsControl 0xA5 //外设控制数据包。
83 #define LenCmdWsControl 0x05 //外设控制数据包长度。
84
85 #define CmdChannelPara 0xA6 //通道参数数据包。
86 #define LenCmdChannelPara 0x09 //通道参数数据包长度。
87
88 #define CmdGetChannelPara 0xA7 //取通道参数数据包。
89 #define LenCmdGetChannelPara 0x05 //取通道参数数据包长度。
90
91 #define CmdSlaveEnable 0xA8 //从机使能数据包。
92 #define LenCmdSlaveEnable 0x07 //从机使能数据包。
93
94 #define CmdSendSlave 0xB1 //提交从机数据数据包。
95 /**************************************服务器命令数据包接收信息**********************************/
96
97 #define LenCmdTime 0x09
98 #define LEN 40
99 #define MAX 200
100 #define Main 0x00
101 #define Output 0x01
102 #define ZhongCai 0x02
103 #define Slave1 0x03
104 #define Slave2 0x04
105 #define Slave3 0x05
106 #define Slave4 0x06
107 #define Slave5 0x07
108
109 uchar FlagEnableReaded = 1; //读到A8数据包标识。
110 uchar TimeCnt = 0; //定时器中断计数器。
111 uchar LenSlaveEnableReaded = 0; //读到公共RAM区从机使能数据包的长度。
112 uchar SlaveEnableRcv[7] = {0,0,0,0,0,0,0}; //5个从机的使能标识。
113 uchar FlagCurrent = ZhongCai; //当前使用IIC权的资源标识。
114
115 /**************************************IIC使用权用已分配标识*****************************************/
116 uchar FlagMainEnable = 0; //当没有读到从机配置数据包时的主机IIC使用权标识。
117 uchar NewFlagSlaveEnable = 0; //从机使能数据包的更新标识。
C51 COMPILER V7.50 ZHONGCAI 03/17/2008 20:44:52 PAGE 3
118
119 bit FlagSlave1Enable = 0;
120 bit FlagSlave2Enable = 0;
121 bit FlagSlave3Enable = 0;
122 bit FlagSlave4Enable = 0;
123 bit FlagSlave5Enable = 0;
124 /**************************************IIC使用权用已分配标识*****************************************/
125 bit FlagTime0 = 0;
126
127 uint TimeCount = 0;
128
129 sbit P12 = P1^2; //从单片机1IIC使用权使用完信号返回标识。
130 sbit P13 = P1^3; //从单片机2IIC使用权使用完信号返回标识。
131 sbit P14 = P1^4; //从单片机3IIC使用权使用完信号返回标识。
132 sbit P15 = P1^5; //从单片机4IIC使用权使用完信号返回标识。
133 sbit P16 = P1^6; //从单片机5IIC使用权使用完信号返回标识。
134 sbit P17 = P1^7; //主单片机IIC使用权使用完信号返回标识。
135 sbit P36 = P3^6; //输出单片机IIC使用权使用完信号返回标识。
136
137 sbit P20 = P2^0; //通过p2.0,p2.1,p2.2三线来分配IIC使用权。
138 sbit P21 = P2^1; //000-从机1;001-从机2;010-从机3;011-从机4;
139 sbit P22 = P2^2; //100-从机5;101-主机;110-输出单片机;111-仲裁机。
140
141 #define DelayTime 2
142
143 /*****************************************************************************************
144 功能:ClearComRam
145 描述:清零字节数存储地址
146 参数:address---需要清零的地址
147 返回:无
148 *****************************************************************************************/
149 void ClearComRam(uint address)
150 {
151 1 uchar temp[2];
152 1 temp[0]=0x00;
153 1 temp[1]=0x00;
154 1 ComWriteBytes(address,temp,2);
155 1 }
156
157 /****************************************************************************************
158 功能:Delay
159 描述:延时函数
160 参数:t
161 返回:无
162 ****************************************************************************************/
163 void Delay(uint t)
164 {
165 1 while(t!=0)
166 1 t--;
167 1 }
168
169 void Time0Initial()
170 {
171 1 TR0=0;
172 1 TH0=0xFF; //50ms
173 1 TL0=0xFF;
174 1 // TH0=0x3C; //50ms
175 1 // TL0=0xB0;
176 1 TR0=1;
177 1 }
178
179
C51 COMPILER V7.50 ZHONGCAI 03/17/2008 20:44:52 PAGE 4
180 /*********************************************************************************************************
-**
181 功能:InitSerialCom
182 描述:串口初始化
183 参数:无
184 返回:无
185 **********************************************************************************************************
-**/
186 void InitSerialCom(void)
187 {
188 1 SCON = 0x50; //SCON: serail mode 1, 8-bit UART, enable ucvr
189 1 TMOD |= 0x21; //TMOD: timer 1, mode 2, 8-bit reload
190 1 PCON |= 0x80; //SMOD=1;
191 1 TH1 = 0xF3; //Baud:4800 fosc=12MHz
192 1 IE |= 0x93; //Enable Serial Interrupt
193 1 TR1 = 1; // timer 1 run
194 1 IT0 = 0;
195 1 // TI=1;
196 1 }
197
198 /*********************************************************************************************************
-**
199 功能:SendCharCom
200 描述:向串口发送一个字符
201 参数:t
202 返回:无
203 **********************************************************************************************************
-**/
204 void SendCharCom(unsigned char ch)
205 {
206 1 SBUF=ch;
207 1 while(TI==0);
208 1 TI=0;
209 1 }
210
211 /*********************************************************************************************************
-**
212 功能:SendStringCom
213 描述:向串口发送一个字符串,strlen为该字符串长度
214 参数:str---要发送的字符串指针 strlen---字符串长度
215 返回:无
216 **********************************************************************************************************
-**/
217 void SendStringCom(unsigned char *str,unsigned int strlen)
218 {
219 1 unsigned int k=0;
220 1 while( (k < strlen) && (strlen > 0) )
221 1 {
222 2 SendCharCom(*(str + k));
223 2 k++;
224 2 }
225 1 }
226
227
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -