📄 3201demo.lst
字号:
C51 COMPILER V7.06 3201DEMO 04/06/2007 19:20:26 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE 3201DEMO
OBJECT MODULE PLACED IN 3201DEMO.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 3201DEMO.C BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*******************************************************************************************
2 *
3 * Copyright Fuxing Xiaocheng elctronic COMPANY
4 *
5 * All Rights Reserved
6 *
7 *
8 * NAME: 3201DEMO.C
9 *
10 * ABSTRACT:PLC DEMO SEND AND RECEIVE PROGRAM SUIT FX
11 *
12 * 1. Receive the Command sended by the PC then send it by PLC
13 * 2. Receive the responsion sended by RU then send it to PC by com
14 * 3. Apply to the fx
15 * 4. Have compatible with 3200 and compatible with 3105
16 * when the FUNC_LED lighted means PL3201 work in the function of PL3200 and
17 * when the FUNC_LED extinguished means PL3201 work in the function of PL3105
18 * 4. CPU :PL3201
19 * 5. the baud rate : 2400BPS none
20 * 6. the most amount of effective byte by PLC received is 100
21 *
22 * EDITION:1.0
23 *
24 * AUTHOR: lxw
25 *
26 * TITME: 2006-3-2
27 *
28 *
29 *******************************************************************************************/
30
31 #include "PL3200.h"
32 #define LIMIT_3105 0x30 // lxw载波序列捕获门限
33 #define LIMIT_3200 0x70 // lxw载波序列捕获门限
34
35 #define uchar unsigned char
36 #define uint unsigned int
37
38 //I/O 口设置
39
40 sbit RS_RLED = P0^4; // 串口接收指示灯D3
41 sbit PLC_TLED = P0^5; // 载波发送指示灯D4
42 sbit PLC_RLED = P1^2; // 载波接收指示灯D5
43 sbit RS_TLED = P0^2; // 串口发送指示灯D6
44 sbit FUNC_LED = P0^3; // 载波通讯方式,亮:3200模式;灭:3105模式D2
45
46 sbit function = P1^3; // 载波通讯方式,0:3200模式;1:3105模式D12
47
48 sbit PSK_OUT = P3^7; //
49 sbit Rxd_p30 = P3^0; //
50 sbit Txd_p31 = P3^1; //
51
52 // 全局变量设置
53 uchar data function_now; // 当前的通讯方式,0:3200方式。0xff:为3105模式
54 uchar data function_flage; // time = 6 sec
55
C51 COMPILER V7.06 3201DEMO 04/06/2007 19:20:26 PAGE 2
56 uchar data COM_recv_len; // 串口接收数据长度
57 uchar data COM_State; // the state of com receive
58 uchar data COM_recv_pointer; // 表示串口接收控制变量
59 uchar data COM_send_timer; // 延时时间变量
60
61 uchar data PLC_Rxd_pointer; // 载波接收过程中的字节数
62 uchar data PLC_Rxd_tlen; // PLC 接收total len
63 uchar bdata PLC_data; // 发送字节缓冲
64 uchar data PLC_send_pointer; // 载波发送字节计数
65 uchar data PLC_timer; // 载波发送延时计数器
66 uchar data PLC_total_len; // 载波发送字节长度+8
67 uchar data PLC_Rxd_timer; // 载波发送延时时间变量
68 uchar data PLC_Rxd_tdata; // PLC_recieve cusion
69
70 uchar data WDI; // 软狗变量
71
72 // 位变量
73 bit bdata PLC_Rxd_flag; // 载波有接收标志
74 bit bdata PLC_Rxd_state; // 载波接收控制变量
75 bit bdata PLC_Rxd_OK; // 载波接收完成标志
76 bit bdata PLC_sending; // 载波正在发送标志
77
78 uchar xdata PLC_recv_buf[250]; // 载波接收缓冲区
79 uchar xdata COM_recv_buf[250]; // 串口接收缓冲区
80
81 uchar xdata R_T_buf_bak[250]; // 通讯数据备份
82
83 /**************************************************************************************
84 *
85 * FUNCTION: timeint0
86 *
87 * DESCRIPTION: 定时器0中断程序;
88 * 50 ms 发生一次中断
89 * 对延时变量进行减1处理
90 *
91 * PARAMETERS: none
92 *
93 * RETURNED: none
94 *************************************************************************************/
95 void timeint0 ( void ) interrupt 1
96 {
97 1 if ( COM_send_timer!=0 )
98 1 {
99 2 COM_send_timer--; // 串口发送延时
100 2 }
101 1
102 1 if ( PLC_Rxd_timer>0 )
103 1 {
104 2 PLC_Rxd_timer--;
105 2 }
106 1 else
107 1 {
108 2 PLC_Rxd_timer=0;
109 2 PLC_RLED=1; // turn off the lamp of receiving
110 2 PLC_Rxd_state=0; // resume receive state
111 2 }
112 1
113 1 if ( PLC_timer>0 ) //增加载波发送延时控制lxw2006-3-2
114 1 PLC_timer--;
115 1
116 1 if ( function_flage ) function_flage--;
117 1 else
C51 COMPILER V7.06 3201DEMO 04/06/2007 19:20:26 PAGE 3
118 1 {
119 2 function_flage=10;
120 2 if ( function ) //载波方式管脚判断
121 2 function_now = function_now *2 + 1; //function_now=0xff为3105方式lxw2006-2-10
122 2 else
123 2 function_now = function_now *2; //function_now=0为3200方式lxw 2006-2-10
124 2 }
125 1
126 1 TH0=0x63; // 置定时器计数 50ms 中断一次 ( 12MHz )
127 1 TL0=0xcc;
128 1
129 1 if ( WDI == 0x9a )
130 1 {
131 2 WDT_RST=0xa1; // 清看门狗
132 2 WDI=0;
133 2 }
134 1 }
135 /**************************************************************************************
136 *
137 * FUNCTION: txdbyte
138 *
139 * DESCRIPTION: 一字节串口发送函数
140 *
141 * PARAMETERS:
142 * in: dachar——要发送的1字节数据
143 * out: none
144 *
145 *
146 * RETURNED: none
147 *
148 *************************************************************************************/
149 void txdbyte ( uchar dachar ) // 单片机串口发送
150 {
151 1 SBUF=dachar;
152 1 COM_send_timer=10; // 500毫秒钟发送不成功退出
153 1
154 1 while ( !TI )
155 1 {
156 2 if ( COM_send_timer == 0 )
157 2 break;
158 2 }
159 1 TI=0;
160 1 }
161 /**************************************************************************************
162 *
163 * FUNCTION: PLC_int
164 *
165 * DESCRIPTION: 载波中断收、发程序
166 *
167 * PARAMETERS:
168 *
169 * out: PLC_Rxd_OK=1 载波接收成功
170 * R_T_buf_bak[] 载波接收成功的数据
171 *
172 * RETURNED: none
173 *************************************************************************************/
174 void PLC_int ( void ) interrupt 7
175 {
176 1 uchar data i;
177 1 uchar data state; // 载波通讯状态
178 1 uchar data SSC_adr_bak;
179 1
C51 COMPILER V7.06 3201DEMO 04/06/2007 19:20:26 PAGE 4
180 1 SSC_adr_bak=SSC_ADR; //PRTECT
181 1 SSC_ADR=0x00; //选择载波状态寄存器
182 1
183 1 state= SSC_DAT;
184 1 // if ( ( state&0x80 ) == 0x0 )
185 1 // return;
186 1 if ( ( state&0x01 ) == 1 ) //载波发送状态
187 1 { // 载波发送
188 2 if ( ( PLC_send_pointer < PLC_total_len ) &&
189 2 ( PLC_send_pointer < 240 ) )
190 2 {
191 3 SSC_BUF=R_T_buf_bak[PLC_send_pointer]; //发送下一个字节
192 3 PLC_send_pointer+=1;
193 3 }
194 2 else
195 2 { //发送完成
196 3 PLC_sending=0; // 清正在发送标志
197 3 PLC_data=0;
198 3 PLC_TLED=1; // 发送指示灯灭
199 3 }
200 2 }
201 1 else
202 1 { // 载波接收
203 2 PLC_Rxd_timer=20; // 最大字节接收延时时间为1S
204 2 if ( ( state&0x04 ) == 0x04 ) //如果接收的是祯头标志
205 2 {
206 3 if ( PLC_Rxd_state == 0 ) //如果处于等待接收状态
207 3 {
208 4 PLC_Rxd_tdata=SSC_BUF; //接收第一个字节,并准备接收后面的字节
209 4 PLC_recv_buf[0]=PLC_Rxd_tdata;
210 4 PLC_Rxd_pointer=1; //lxw2006-3-2 17:07
211 4 PLC_Rxd_tlen =60;
212 4 PLC_Rxd_state=1;
213 4 PLC_RLED=0; //接收指示灯亮
214 4 }
215 3 else // translate to rec
216 3 {
217 4 PLC_Rxd_state=0;
218 4 SSC_ADR=0X0;
219 4 SSC_DAT=0X0;
220 4 }
221 3 }
222 2 else
223 2 {
224 3 if ( PLC_Rxd_state == 1 ) // 如果已经接收了祯头,继续接收后续字节
225 3 {
226 4 PLC_Rxd_tdata=SSC_BUF;
227 4 PLC_recv_buf[PLC_Rxd_pointer]=PLC_Rxd_tdata;
228 4 if ( PLC_Rxd_pointer == 0x04 ) // 接收到了载波字节个数
229 4 {
230 5 PLC_Rxd_tlen=PLC_Rxd_tdata+7; // 加7的意思是3个地址码+1个控制码+1个长度码+2个校验
-码
231 5 if ( PLC_Rxd_tlen>100 )
232 5 PLC_Rxd_tlen=100; // 接收字节长度限制
233 5 }
234 4 PLC_Rxd_pointer+=1;
235 4 if ( PLC_Rxd_pointer>=PLC_Rxd_tlen )
236 4 {
237 5 PLC_Rxd_OK=1;
238 5 PLC_RLED=1; //接收完毕灯灭
239 5 PLC_Rxd_state=0;
240 5 for ( i=0 ; i< ( PLC_Rxd_tlen+1 ) ; i++ )
C51 COMPILER V7.06 3201DEMO 04/06/2007 19:20:26 PAGE 5
241 5 {
242 6 R_T_buf_bak[i]=PLC_recv_buf[i];
243 6 }
244 5 SSC_ADR=0X0; // translate to rec
245 5 SSC_DAT=0X0;
246 5 }
247 4 }
248 3 else // translate to rec
249 3 {
250 4 PLC_Rxd_state=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -