📄 c2051.lst
字号:
C51 COMPILER V7.07 C2051 06/28/2006 10:27:25 PAGE 1
C51 COMPILER V7.07, COMPILATION OF MODULE C2051
OBJECT MODULE PLACED IN c2051.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE c2051.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include <reg51.h>
2 #include <math.h>
3
4 #define POS1 218//(223-5) //测试头下落至磁环高度时的位置
5 #define POS2 51 //测试头移至磁环正中心时的位置
6 #define POS3 142//(137+5) //测试头上升至磁环高度时的位置
7
8 #define TIME1 10 //脉冲之间的延时
9 #define TIME2 4
10 #define TIME3 13
11 #define TIME4 16
12 #define TIME5 19
13 #define TIME6 23
14 #define TIME7 28
15 #define TIME8 35
16
17 #define NUM 9 //两齿轮的比例
18
19 #define HIGH 1
20 #define LOW 0
21
22 sbit PULSE = P3^7;
23 sbit SENS = P3^0;
24 sbit LED = P3^1;
25
26 unsigned char pos; //测试头位置
27
28 void delay( unsigned char time )
29 {
30 1 unsigned char i = time;
31 1 while( --i );
32 1 }
33
34 void delays( )
35 {
36 1 unsigned char i = 20;
37 1 while( --i )
38 1 delay( 255 );
39 1 }
40 void step( )
41 {
42 1
43 1 /*************************************************
44 1 小拨盘前进一格(45度),
45 1 为防止出错,发出的脉冲数最多可移动2格
46 1 转动过程中检查光耦以确定是否到位
47 1 检查测试头位置以确定拨盘是否还可以继续转动
48 1 64细分,转动45度需1600个脉冲
49 1 分2步发送脉冲,第一步直接发送160个脉冲
50 1 第二步边监测边发脉冲,最多发3200个脉冲
51 1 *************************************************/
52 1 unsigned int i, j;
53 1 LED = HIGH;
54 1 //第一步
55 1 for ( i = 1400; i > 0; i -- )
C51 COMPILER V7.07 C2051 06/28/2006 10:27:25 PAGE 2
56 1 {
57 2 for ( j = NUM; j > 0; j -- )
58 2 {
59 3 // if((SENS==0)||((pos>=POS1)||(pos<POS3))) break;
60 3 PULSE = HIGH;
61 3 delay( TIME2 );
62 3 PULSE = LOW;
63 3 delay( TIME2 );
64 3 }
65 2 }
66 1
67 1 //第二步
68 1 for ( i = 2000; i > 0; i -- )
69 1 {
70 2 pos = P1;
71 2 // if ( ( SENS == 0 ) || (( pos >= POS2 ) && ( pos < POS3 )) )
72 2 if ( ( SENS == 0 ) || (( pos >= POS1 ) || ( pos < POS3 )) )
73 2 // if( SENS == 0 )
74 2 break;
75 2 for ( j = NUM; j > 0; j -- )
76 2 {
77 3 PULSE = HIGH;
78 3 delay( TIME2 );
79 3 PULSE = LOW;
80 3 delay( TIME2);
81 3 if(SENS==0) break;
82 3 }
83 2 }
84 1
85 1 //3
86 1 for ( i = 160; i > 0; i -- )
87 1 {
88 2 pos = P1;
89 2 // if ( ( SENS == 0 ) || (( pos >= POS2 ) && ( pos < POS3 )) )
90 2 if ( ( SENS == 0 ) || (( pos >= POS1 ) || ( pos < POS3 )) )
91 2 // if( SENS == 0 )
92 2 break;
93 2 for ( j = NUM; j > 0; j -- )
94 2 {
95 3 if(SENS==0) break;
96 3 PULSE = HIGH;
97 3 delay( TIME3 );
98 3 PULSE = LOW;
99 3 delay( TIME3 );
100 3 }
101 2 }
102 1
103 1 //防止丢步,补差
104 1 for ( i = 160; i > 0; i -- )
105 1 {
106 2 pos = P1;
107 2 // if ( ( SENS == 0 ) || (( pos >= POS2 ) && ( pos < POS3 )) )
108 2 if ( ( SENS == 0 ) || (( pos >= POS1 ) || ( pos < POS3 )) )
109 2 // if( SENS == 0 )
110 2 break;
111 2 for ( j = NUM; j > 0; j -- )
112 2 {
113 3 if(SENS==0) break;
114 3 PULSE = HIGH;
115 3 delay( TIME3 );
116 3 PULSE = LOW;
117 3 delay( TIME3 );
C51 COMPILER V7.07 C2051 06/28/2006 10:27:25 PAGE 3
118 3 }
119 2 }
120 1 LED = LOW;
121 1
122 1 }
123 /*
124 void test( )
125 {
126 unsigned int i;
127 while( 1 )
128 {
129
130 step( );
131 }
132 }
133 */
134 void init( )
135 {
136 1 unsigned char i;
137 1 pos = P1;
138 1 while( ( pos == 0xff ) || ( pos == 0x00) )
139 1 {
140 2 pos = P1;
141 2 }
142 1 pos = P1;
143 1 i = pos;
144 1 //判断马达是否上电
145 1 while( pos == i )
146 1 {
147 2 delay( 25 );
148 2 i = P1;
149 2 }
150 1 //空转一周
151 1 pos = P1;
152 1 i = pos;
153 1 while( pos == i )
154 1 {
155 2 delay( 25 );
156 2 i = P1;
157 2 }
158 1 delays( );
159 1
160 1 while( pos != i )
161 1 {
162 2 i = P1;
163 2 }
164 1
165 1
166 1 }
167
168 void main( )
169 {
170 1 // test( );
171 1 init( );
172 1 pos = P1;
173 1 while ( ( pos <= POS2 ) || ( pos >= POS3 ) )
174 1 {
175 2 // delay( 25 );
176 2 pos = P1;
177 2 }
178 1 pos = P1;
179 1 while ( ( pos <= POS2 ) || ( pos >= POS3 ) )
C51 COMPILER V7.07 C2051 06/28/2006 10:27:25 PAGE 4
180 1 {
181 2 // delay( 25 );
182 2 pos = P1;
183 2 }
184 1
185 1 while ( 1 )
186 1 {
187 2 //等待
188 2 pos = P1;
189 2 while ( ( pos >= POS2 ) && ( pos < POS3 ) )
190 2 {
191 3 // delay( 25 );
192 3 pos = P1;
193 3 }
194 2 pos = P1;
195 2 while ( ( pos >= POS2 ) && ( pos < POS3 ) )
196 2 {
197 3 // delay( 25 );
198 3 pos = P1;
199 3 }
200 2
201 2 //判断方向
202 2 pos = P1;
203 2 delays( );
204 2 while( (pos >= P1) || ( (P1-pos)>=250 ) )
205 2 {
206 3 pos = P1;
207 3 // delays( );
208 3 }
209 2 //步进一格
210 2 step( );
211 2
212 2 // delays( );
213 2
214 2 pos = P1;
215 2 while ( ( pos <= POS2 ) || ( pos >= POS3 ) )
216 2 {
217 3 // delay( 25 );
218 3 pos = P1;
219 3 }
220 2 pos = P1;
221 2 while ( ( pos <= POS2 ) || ( pos >= POS3 ) )
222 2 {
223 3 // delay( 25 );
224 3 pos = P1;
225 3 }
226 2 }
227 1
228 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 456 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 1 ----
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 + -