📄 main.lst
字号:
C51 COMPILER V8.08 MAIN 01/08/2008 15:03:27 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE src\main.c LARGE OPTIMIZE(0,SPEED) BROWSE INCDIR(.\include) DEBUG OBJECTEXT
-END PRINT(.\main.lst) OBJECT(main.obj)
line level source
1 /////////////////////////////////////
2 // Generated Initialization File //
3 /////////////////////////////////////
4
5 #include "includes.h"
6
7 //接收数据状态机计数器,在以下几种情况下会自动清零:
8 UINT8 getmode = 0;
9 //数据接收BUFFER
10 UINT8 getdatabuf[128];
11 UINT8 *pdatabuf;
12
13 TIMER_PARAMETER TIMER0_PARAMETER;
14 UINT16 delay_num = 0;
15
16 // Peripheral specific initialization functions,
17 // Called from the Init_Device() function
18 void Reset_Sources_Init()
19 {
20 1 WDTCN = 0xDE;
21 1 WDTCN = 0xAD;
22 1 }
23
24 void Timer_Init()
25 {
26 1 CKCON = 0x10;
27 1 TCON = 0x40;
28 1 TMOD = 0x21;
29 1 TH0 = 0xB8;
30 1 TH1 = 0xB8;
31 1 }
32
33 void UART_Init()
34 {
35 1 SCON1 = 0x50;
36 1 }
37
38 void Port_IO_Init()
39 {
40 1 P0MDOUT = 0x01;
41 1 XBR0 = 0x05;
42 1 XBR2 = 0x44;
43 1 }
44
45 void Oscillator_Init()
46 {
47 1 int i = 0;
48 1 OSCXCN = 0x67;
49 1 for (i = 0; i < 3000; i++); // Wait 1ms for initialization
50 1 while ((OSCXCN & 0x80) == 0);
51 1 OSCICN = 0x0C;
52 1 }
53
54 void Interrupts_Init()
C51 COMPILER V8.08 MAIN 01/08/2008 15:03:27 PAGE 2
55 {
56 1 IE = 0x82;
57 1 EIE2 = 0x40;
58 1 }
59
60 // Initialization function for device,
61 // Call Init_Device() from your main program
62 void Init_Device(void)
63 {
64 1 Reset_Sources_Init();
65 1 Timer_Init();
66 1 UART_Init();
67 1 Port_IO_Init();
68 1 Oscillator_Init();
69 1 Interrupts_Init();
70 1 }
71
72 /*****************************************************************************************
73 ** 函数名称: Enable_Timer0
74 ** 功能描述: 启动定时器0,清零内部计数器
75 ** 输 入: 超时多少个时间单位。
76 ** 输 出: 无
77 ** 全局变量: TIMER0_PARAMETER,delay_num
78 ** 调用模块: 无
79 ******************************************************************************************/
80 void Enable_timer0(unsigned int num)
81 {
82 1 TIMER0_PARAMETER.num_unit = num;
83 1 delay_num = 0; //清零内部计数器
84 1 TCON |= 0x10;
85 1 }
86
87
88 /*****************************************************************************************
89 ** 函数名称: Disable_Timer0
90 ** 功能描述: 关闭定时器0
91 ** 输 入: 无
92 ** 输 出: 无
93 ** 全局变量: 无
94 ** 调用模块: 无
95 ******************************************************************************************/
96 void Disable_timer0()
97 {
98 1 TCON &= ~0x10;
99 1 }
100 /*****************************************************************************************
101 ** 函数名称: Get_writeone()
102 ** 功能描述: 关闭定时器0
103 ** 输 入: 无
104 ** 输 出: 返回接收结束状态
105 0、接收正常;1、接收到变频器发送回来的操作错误数据;2、接收超时
106 ** 全局变量: getmode
107 ** 调用模块: 无
108 ******************************************************************************************/
109 UINT8 Get_writeone(void)
110 {
111 1 UINT8 return_data = 0;
112 1
113 1 getmode = 0;
114 1 Enable_timer0(100);
115 1
116 1 while(1)
C51 COMPILER V8.08 MAIN 01/08/2008 15:03:27 PAGE 3
117 1 {
118 2 if(TIMER0_PARAMETER.timerout_flag == 1)
119 2 {
120 3 Disable_timer0();
121 3 TIMER0_PARAMETER.timerout_flag = 0;
122 3 getmode = TIMEROUT;
123 3 return_data = 2;//接收超时
124 3 break;
125 3 }
126 2 else if(getmode == RIGHT_LF)
127 2 {
128 3 Disable_timer0();
129 3 return_data = 0; //正确接收
130 3 break;
131 3 }
132 2 else if(getmode == WRONG_LF)
133 2 {
134 3 Disable_timer0();
135 3 return_data = 1; //接收到错误回复信号
136 3 break;
137 3 }
138 2 }
139 1
140 1 getmode = 0;
141 1 return return_data;
142 1 }
143
144
145
146
147
148 void main(void)
149 {
150 1 // volatile UINT8 num; //n代表发送或接收的数据字数
151 1 UINT16 count,i;
152 1 UINT8 loopnum = 0;
153 1
154 1 Init_Device();
155 1
156 1 count = 0;
157 1 pdatabuf = getdatabuf;
158 1 //测试程序
159 1
160 1 while(1)
161 1 {
162 2 while(count < 0x1770)
163 2 {
164 3 for(loopnum=0;loopnum<3;loopnum++)
165 3 {
166 4 Send_writeone(0x01,0x2001,count);
167 4 if(!Get_writeone())break;
168 4 }
169 3 if(loopnum >= 3)
170 3 {
171 4 Send_writeone(0x01,0x2000,2);//停止指令
172 4 if(!Get_writeone())while(1);
173 4 while(1);
174 4 }
175 3 for(i=0;i<65534;i++);
176 3 count++;
177 3 }
178 2 count = 0;
C51 COMPILER V8.08 MAIN 01/08/2008 15:03:27 PAGE 4
179 2 }
180 1
181 1 //测试程序完
182 1 }
183
184
185
186
187
188 void Timer0_ISR(void) interrupt 1
189 {
190 1 TH0 = 0xB8;
191 1 delay_num++;
192 1 //Timer 可以硬件清除溢出标志位
193 1 if (delay_num > TIMER0_PARAMETER.num_unit)
194 1 {
195 2 TIMER0_PARAMETER.timerout_flag = 1;
196 2 delay_num = 0;
197 2 }
198 1 }
199
200 void UART1_ISR(void) interrupt 20
201 {
202 1 static UINT8 getdata;
203 1 if(SCON1&0x01)
204 1 {
205 2 SCON1 &= 0xfe;
206 2 getdata = SBUF1 & 0x7f;//接收时屏蔽最高位,当作停止位
207 2
208 2 switch(getdata)
209 2 {
210 3 case T_STR:
211 3 getmode = SOF;break;//STR
212 3 case T_CR:
213 3 if(getmode <= 9)
214 3 {
215 4 getmode = WRONG_CR;
216 4 break;//提前接收CR,说明通信错误
217 4 }
218 3 else
219 3 {
220 4 getmode = RIGHT_CR;
221 4 break;//正确接收CR
222 4 }
223 3 case T_LF:
224 3 if(WRONG_CR == getmode)
225 3 {
226 4 getmode = WRONG_LF;//错误接收结束
227 4 break;//LF
228 4 }
229 3 else
230 3 {
231 4 getmode = RIGHT_LF;//正确接收结束
232 4 break;//LF
233 4 }
234 3 }
235 2 switch(getmode)
236 2 {
237 3 case SOF: pdatabuf = getdatabuf;getmode = 2;break;
238 3 case 2:
239 3 case 3:
240 3 case 4:
C51 COMPILER V8.08 MAIN 01/08/2008 15:03:27 PAGE 5
241 3 case 5:
242 3 case 6:
243 3 case 7:
244 3 case 8:
245 3 case 9:
246 3 case 10:
247 3 case 11:
248 3 case 12:
249 3 case 13:
250 3 case 14:
251 3 case 15:
252 3 case 16:
253 3 case 17:*pdatabuf = getdata;++pdatabuf;++getmode;break;
254 3 case RIGHT_CR:break;
255 3 case WRONG_CR:break;
256 3 case RIGHT_LF:break;//正确接收结束
257 3 case WRONG_LF:break;//错误接收结束,保留getmode,以供识别
258 3 case TIMEROUT:break;//外部定时器溢出
259 3 default: *pdatabuf = getdata;++pdatabuf;;break;
260 3 }
261 2 }
262 1 }
263
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 903 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 148 ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
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 + -