📄 main.lst
字号:
C51 COMPILER V7.06 MAIN 09/12/2005 12:55:40 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE main.c BROWSE DEBUG OBJECTEXTEND TABS(2)
stmt level source
1
2 #include <AT89X52.H>
3 #include <absacc.h>
4 #include <math.h>
5 #include <stdlib.h>
6
7 #define uchar unsigned char
8 #define uint unsigned int
9
10 #define Ram XBYTE[0x2000]
11 #define Rom XBYTE[0x4000]
12 //画线****************************
13 #define zheng 1 //收缩
14 #define fan 0 //释放
15 #define one_step 0.010
16 #define time_count 20000 //定时常数
17 //*****************************
18 extern void delay(uint dtime);
19
20 /*串口操作 ************************* ******************************/
21 extern char getbyte(void); //从接收缓冲区取一个byte,如不想等待则在调用前检测inbufsign是否为1。
22 extern putbyte(char c); //放入一个字节到发送缓冲区
23 extern putstring(uchar *puts); //发送一个定义在程序存储区的字符串到串口
24 extern putbytes(uchar *outplace,uint j);//放一串数据到发送缓冲区,需要定义发送的字节数
25 extern puthex(uchar c); //发送一个字节的hex码,分成两个字节发。
26 extern bit inbufsign; //串口接收到数据标志
27 extern void serial_init (void); //串口初始化
28 #define CR putstring("\r\n") //发送一个回车换行
29 #define XIAN 1
30 #define YUAN 2
31 #define QUXIAN 3
32 /*液晶操作***/
33 extern void lcd_cls(void); //清屏
34 extern void lcd_string(uchar attr,uchar *string); //显示字符串
35 extern void Set_module_light(uchar module);
36 //extern void lcd_cursor(uchar x, uchar y);
37 //8279操作
38 extern void init8279();
39 //**********键盘操作
40 extern uchar data key;
41 //画线函数定义
42 uchar shape=0;
43 uint xdata num0 _at_ 0x209b;
44 uint xdata num1 _at_ 0x20a1;
45 uchar xdata state _at_ 0x20b0;
46 float xdata l_xishu _at_ 0x2008;
47 float xdata r_xishu _at_ 0x2010;
48 float xdata xstart _at_ 0x2016;
49 float xdata ystart _at_ 0x201b;
50 float xdata xend _at_ 0x2020;
51 float xdata yend _at_ 0x2026;
52 float xdata xcur _at_ 0x202b;
53 float xdata ycur _at_ 0x2030;
54
55
C51 COMPILER V7.06 MAIN 09/12/2005 12:55:40 PAGE 2
56 uchar xdata direction_l _at_ 0x2040;
57 uchar xdata direction_r _at_ 0x2042;
58
59
60 static uchar xdata keystr[2][4] _at_ 0x2072;
61 static uchar xdata count _at_ 0x207b,isy _at_ 0x207c;
62
63 uchar xdata x_temp _at_ 0x2100;
64 uchar xdata y_temp _at_ 0x2102;
65 uchar xdata xystr[3] _at_ 0x2103;
66
67 double xdata pt1_x _at_ 0x2200,pt1_y _at_ 0x2208,
68 pt2_x _at_ 0x2210,pt2_y _at_ 0x2218,
69 temp _at_ 0x2220, motorl_step _at_ 0x2228,
70 motorr_step _at_ 0x2230;
71 uint xdata timer0_l _at_ 0x2068,timer1_l _at_ 0x206c;
72 uint data timer1_r;
73 void GetPCdata()
74 {
75 1 if(inbufsign!=1)
76 1 return;
77 1 if(getbyte() == 0x05);
78 1 {
79 2 key=getbyte();
80 2 // sdkey=key;
81 2 }
82 1 }
83
84 // uchar sdkey;
85
86 //左电机正转函数
87 void step0_z(uchar i)
88 {
89 1 switch(i)
90 1 {
91 2 case 0:
92 2 P1_0=0;
93 2 P1_1=0;
94 2 break;
95 2 case 1:
96 2 P1_0=1;
97 2 P1_1=0;
98 2 break;
99 2 case 2:
100 2 P1_0=1;
101 2 P1_1=1;
102 2 break;
103 2 case 3:
104 2 P1_0=0;
105 2 P1_1=1;
106 2 break;
107 2 }
108 1 }
109 //左电机反转函数
110 void step0_f(uchar i)
111 {
112 1 switch(i)
113 1 {
114 2 case 0:
115 2 P1_0=0;
116 2 P1_1=1;
117 2 break;
C51 COMPILER V7.06 MAIN 09/12/2005 12:55:40 PAGE 3
118 2 case 1:
119 2 P1_0=1;
120 2 P1_1=1;
121 2 break;
122 2 case 2:
123 2 P1_0=1;
124 2 P1_1=0;
125 2 break;
126 2 case 3:
127 2 P1_0=0;
128 2 P1_1=0;
129 2 break;
130 2 }
131 1
132 1 }
133 //右电机正转函数
134 void step1_z(uchar i)
135 {
136 1 switch(i)
137 1 {
138 2 case 0:
139 2 P1_2=0;
140 2 P1_3=0;
141 2 break;
142 2 case 1:
143 2 P1_2=1;
144 2 P1_3=0;
145 2 break;
146 2 case 2:
147 2 P1_2=1;
148 2 P1_3=1;
149 2 break;
150 2 case 3:
151 2 P1_2=0;
152 2 P1_3=1;
153 2 break;
154 2 }
155 1
156 1 }
157 //左电机反转函数
158 void step1_f(uchar i)
159 {
160 1 switch(i)
161 1 {
162 2 case 0:
163 2 P1_2=0;
164 2 P1_3=1;
165 2 break;
166 2 case 1:
167 2 P1_2=1;
168 2 P1_3=1;
169 2 break;
170 2 case 2:
171 2 P1_2=1;
172 2 P1_3=0;
173 2 break;
174 2 case 3:
175 2 P1_2=0;
176 2 P1_3=0;
177 2 break;
178 2 }
179 1
C51 COMPILER V7.06 MAIN 09/12/2005 12:55:40 PAGE 4
180 1 }
181 //上面的变量赋初值后调用下面函数计算电机应走的步数以及方向
182
183 void shoudong()
184 {
185 1 // GetPCdata();
186 1 P0=0xff;
187 1 //timer0_l=10000;
188 1 //timer1_r=10000;
189 1 motorl_step=1000;
190 1 motorr_step=1000;
191 1 if(!P0_0)direction_l=1;
192 1 if(!P0_1)direction_l=0;
193 1 if(!P0_0||!P0_1)TR0=1;else TR0=0;
194 1
195 1 if(!P0_2)direction_r=0;
196 1 if(!P0_3)direction_r=1;
197 1 if(!P0_2||!P0_3)TR1=1;else TR1=0;
198 1 }
199
200 float dis;
201 displayxy()
202 {
203 1 while(state)
204 1 if(!(num0%10)||!(num0)%7)
205 1 {
206 2 dis=(pt1_x+(pt2_x-pt1_x)*num0/motorl_step);
207 2 xystr[0]=dis/10+48;
208 2 xystr[1]=(int)dis%10+48;
209 2 xystr[2]='\0';
210 2 lcd_cls();
211 2 lcd_string(0,"\r\nX: ");
212 2 lcd_string(0,xystr);
213 2 lcd_string(0," cm");
214 2 dis=(pt1_y+(pt2_y-pt1_y)*num0/motorl_step);
215 2 xystr[0]=dis/10+48;
216 2 xystr[1]=(int)dis%10+48;
217 2 xystr[2]='\0';
218 2 lcd_string(0,"\r\nY: ");
219 2 lcd_string(0,xystr);
220 2 lcd_string(0," cm");
221 2 }
222 1 // shoudong();
223 1 }
224
225
226
227
228
229
230
231 void line()
232 {
233 1 // temp=0;
234 1
235 1
236 1 motorr_step=
237 1 (sqrt((95-pt2_x)*(95-pt2_x)+
238 1 (115-pt2_y)*(115-pt2_y))-
239 1 sqrt((95-pt1_x)*(95-pt1_x)+
240 1 (115-pt1_y)*(115-pt1_y))-
241 1 (pt2_x-40)*0.001)
C51 COMPILER V7.06 MAIN 09/12/2005 12:55:40 PAGE 5
242 1 /one_step;//右电机应走的步数
243 1
244 1 motorl_step=(sqrt((pt2_x+15)*(pt2_x+15)+(115-pt2_y)*(115-pt2_y))
245 1 -sqrt((pt1_x+15)*(pt1_x+15)+(115-pt1_y)*(115-pt1_y))-
246 1 (pt2_x-40)*0.001)/one_step;//左电机应走的步数
247 1 if(motorl_step<0)
248 1 direction_l=zheng;
249 1 else
250 1 direction_l=fan;
251 1 if(motorr_step<0)
252 1 direction_r=zheng;
253 1 else
254 1 direction_r=fan;
255 1 motorl_step=abs(motorl_step);
256 1 motorr_step=abs(motorr_step);
257 1 temp=motorl_step/motorr_step;
258 1 l_xishu=1;
259 1 r_xishu=temp;
260 1 TR0=1;
261 1 TR1=1;
262 1 state=1;
263 1 }
264
265
266 void timer0_init()
267 {
268 1 timer0_l=time_count*l_xishu;
269 1 TMOD=0x01; //设定定时器的工作方式//左电机
270 1 TH0=(65536-timer0_l)/256;
271 1 TL0=(65536-timer0_l)%256;
272 1 ET0=1;
273 1 EA=1;
274 1 }
275 void timer1_init()//定时1毫秒
276 {
277 1 timer1_l=time_count*r_xishu;
278 1 TMOD=0x11; //设定定时器的工作方式//右电机
279 1 TH1=(65536-timer1_l)/256;
280 1 TL1=(65536-timer1_l)%256;
281 1 ET1=1;
282 1 EA=1;
283 1 //IE复位后的状态 0X0000B
284 1 }
285 void time0_1ms() interrupt 1//左电机定时
286 {
287 1 uint data timer0_l=time_count*l_xishu;
288 1 TH0=(65536-timer0_l)/256;
289 1 TL0=(65536-timer0_l)%256;
290 1 if(direction_l==zheng)
291 1 step0_z(num0%4);
292 1 else
293 1 step0_f(num0%4);
294 1 if(num0>=motorl_step)
295 1 {
296 2 TR0=0;
297 2 num0=0;
298 2 state=0;
299 2 }
300 1 else
301 1 {
302 2 num0++;
303 2 }
C51 COMPILER V7.06 MAIN 09/12/2005 12:55:40 PAGE 6
304 1 }
305 void time1_1ms() interrupt 3//右电机定时
306 {
307 1 timer1_r=time_count*r_xishu;
308 1 TH1=(65536-timer1_r)/256;
309 1 TL1=(65536-timer1_r)%256;
310 1
311 1 if(direction_r==zheng)
312 1 step1_z(num1%4);
313 1 else
314 1 step1_f(num1%4);
315 1
316 1 if(num1>=motorr_step)
317 1 {
318 2 TR1=0;
319 2 num1=0;
320 2 state=0;
321 2 }
322 1 else
323 1 {
324 2 num1++;
325 2 }
326 1
327 1 }
328 //**********************
329 uchar data KeyFuncIndex = 0;//当前状态
330 //状态函数开始
331 void start1()
332 {
333 1 lcd_cls();
334 1 lcd_string(1,"定点\r\n");//背光显示
335 1 lcd_string(0,"矩形\r\n");
336 1 lcd_string(0,"三角\r\n");
337 1 lcd_string(0,"圆形\r\n");
338 1 lcd_string(0,"循迹\r\n");
339 1 }
340 void start2()
341 {
342 1 lcd_cls();
343 1 lcd_string(0,"定点\r\n");//背光显示
344 1 lcd_string(1,"矩形\r\n");
345 1 lcd_string(0,"三角\r\n");
346 1 lcd_string(0,"圆形\r\n");
347 1 lcd_string(0,"循迹\r\n");
348 1 }
349 void start3()
350 {
351 1 lcd_cls();
352 1 lcd_string(0,"定点\r\n");//背光显示
353 1 lcd_string(0,"矩形\r\n");
354 1 lcd_string(1,"三角\r\n");
355 1 lcd_string(0,"圆形\r\n");
356 1 lcd_string(0,"循迹\r\n");
357 1 }
358 //***************************
359 void start4()
360 {
361 1 lcd_cls();
362 1 lcd_string(0,"定点\r\n");//背光显示
363 1 lcd_string(0,"矩形\r\n");
364 1 lcd_string(0,"三角\r\n");
365 1 lcd_string(1,"圆形\r\n");
C51 COMPILER V7.06 MAIN 09/12/2005 12:55:40 PAGE 7
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -