📄 step_motor_led.lst
字号:
C51 COMPILER V8.02 STEP_MOTOR_LED 04/05/2007 22:09:43 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE STEP_MOTOR_LED
OBJECT MODULE PLACED IN step_motor_led.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE step_motor_led.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /*********************************************************************************************************
-********
2 Copyright (C), 2006, Shenzhen University,college of information engneering.
3 File Name: led_motor.c
4 Author: Iceant and Zhoudy
5 Version: Version 1.0
6 Start: Aug 17,2006
7 Last update: xxx xx,2006
8 Description: LCD serial display and motor drive
9 **********************************************************************************************************
-********/
10 #include <reg51.h>
11 #include <intrins.h>
12 #include <string.h>
13
14 #define uchar unsigned char
15 #define uint unsigned char
16
17 sbit motor0=P2^0;
18 sbit motor1=P2^1;
19 sbit motor2=P2^2;
20 sbit motor3=P2^3;
21 //pins for LCD enable
22 sbit LCD_E=P0^2;
23 sbit LCD_RW=P0^1;
24 sbit LCD_RS=P0^0;
25 sbit LCD_BUSY_CHECK = P1^7;
26 //pins for keys as bps selecting
27 sbit b1=P3^3;
28 sbit b2=P3^4;
29 sbit b3=P3^5;
30 //Menu display
31 code char examp1[]="Baud rate selecting:";
32 code char examp2[]="1:4800 bps";
33 code char examp3[]="2:9600 bps";
34 code char examp4[]="3:19200 bps";
35 code char examp5[]="Error! Can not display so much characters!";
36 int count=0;
37 int dly=100;//define the parameter of delay time
38 int direction=1; //turn left or right
39
40 ///////////type define the struct data received and the size of the buffer /////
41 typedef struct CMD
42 {
43 uchar buf[20];
44 uchar cnt;
45 }cmdstr;
46 cmdstr data cmd;
47
48
49 ////////////
50 void serial(void);
51 void Lcd_Dis(uchar dis) ;
52 void buffer_clear(void);
53 void Lcd_Check(void);
C51 COMPILER V8.02 STEP_MOTOR_LED 04/05/2007 22:09:43 PAGE 2
54 void Lcd_Cmd(uint cmd);
55 void Lcd_Ini(void);
56 void Lcd_String(char *str);
57 void Delayms(int dly) ;
58 void Serial_Init1(void) ;
59 void Serial_Init2(void);
60 void Serial_Init3(void);
61 void led_dispaly(void);
62 void motor_control(void);
63
64
65 /******************************************************************************
66 Function: LCD serial display and motor drive
67 Description: main
68 Calls: - None
69 Input: - None
70 Output: - None
71 Return:
72 ******************************************************************************/
73 void main(void)
74 {
75 1 cmd.cnt = 0;
76 1 //lcd initial
77 1 Lcd_Ini();
78 1 //menu display
79 1 Lcd_Cmd(0x80);
80 1 Lcd_String(examp1);
81 1 Lcd_Cmd(0xC0);
82 1 Lcd_String(examp2);
83 1 Lcd_Cmd(0x94);
84 1 Lcd_String(examp3);
85 1 Lcd_Cmd(0xD4);
86 1 Lcd_String(examp4);
87 1 do{ //wait for key press down
88 2 ;
89 2 }while(b1&&b2&&b3);
90 1 Delayms(30);//waiting for normal state
91 1 //select baud rate
92 1 do{
93 2 if(b1==0)
94 2 {
95 3 Lcd_Cmd(0x01);
96 3 Serial_Init1();
97 3 }
98 2 else if(b2==0)
99 2 {
100 3 Lcd_Cmd(0x01);
101 3 Serial_Init2();
102 3 }
103 2 else if(b3==0)
104 2 {
105 3 Lcd_Cmd(0x01);
106 3 Serial_Init3();
107 3 }
108 2 }while(b1&&b2&&b3);
109 1
110 1 while(1)
111 1 {/*
112 2 if(direction)
113 2 {
114 2 motor0=1; //1000
115 2 motor1=0;
C51 COMPILER V8.02 STEP_MOTOR_LED 04/05/2007 22:09:43 PAGE 3
116 2 motor2=0;
117 2 motor3=0;
118 2 motor_control();
119 2 motor0=1; //1100
120 2 motor1=1;
121 2 motor2=0;
122 2 motor3=0;
123 2 motor_control();
124 2 motor0=0; //0100
125 2 motor1=1;
126 2 motor2=0;
127 2 motor3=0;
128 2 motor_control();
129 2 motor0=0; //0110
130 2 motor1=1;
131 2 motor2=1;
132 2 motor3=0;
133 2 motor_control();
134 2 motor0=0; //0010
135 2 motor1=0;
136 2 motor2=1;
137 2 motor3=0;
138 2 motor_control();
139 2 motor0=0; //0011
140 2 motor1=0;
141 2 motor2=1;
142 2 motor3=1;
143 2 motor_control();
144 2 motor0=0; //0001
145 2 motor1=0;
146 2 motor2=0;
147 2 motor3=1;
148 2 motor_control();
149 2 motor0=1; //1001
150 2 motor1=0;
151 2 motor2=0;
152 2 motor3=1;
153 2 motor_control();
154 2 }
155 2 else
156 2 {
157 2 motor0=1; //1001
158 2 motor1=0;
159 2 motor2=0;
160 2 motor3=1;
161 2 motor_control();
162 2 motor0=0; //0001
163 2 motor1=0;
164 2 motor2=0;
165 2 motor3=1;
166 2 motor_control();
167 2 motor0=0; //0011
168 2 motor1=0;
169 2 motor2=1;
170 2 motor3=1;
171 2 motor_control();
172 2 motor0=0; //0010
173 2 motor1=0;
174 2 motor2=1;
175 2 motor3=0;
176 2 motor_control();
177 2 motor0=0; //0110
C51 COMPILER V8.02 STEP_MOTOR_LED 04/05/2007 22:09:43 PAGE 4
178 2 motor1=1;
179 2 motor2=1;
180 2 motor3=0;
181 2 motor_control();
182 2 motor0=0; //0100
183 2 motor1=1;
184 2 motor2=0;
185 2 motor3=0;
186 2 motor_control();
187 2 motor0=1; //1100
188 2 motor1=1;
189 2 motor2=0;
190 2 motor3=0;
191 2 motor_control();
192 2 motor0=1; //1000
193 2 motor1=0;
194 2 motor2=0;
195 2 motor3=0;
196 2 motor_control();
197 2 } */
198 2 }
199 1 }
200
201
202 /******************************************************************************
203 Function: motor_control
204 Description: motor_control
205 Calls: - None
206 Input: - None
207 Output: - None
208 Return:
209 ******************************************************************************/
210 void motor_control(void)
211 {
212 1 if((!b1)||(!b2)||(!b3)) //whether press the button
213 1 {
214 2 Delayms(3);
215 2 if(!b1) //button_direction is pressed dwon
216 2 {
217 3 while(!b1);
218 3 if(direction)
219 3 direction=0;
220 3 else
221 3 direction=1;
222 3 }
223 2 else if(!b2) // for button_left
224 2 {
225 3 while(!b2);
226 3 if(dly>15&&dly<350)
227 3 {
228 4 dly+=6;
229 4 }
230 3 else
231 3 {
232 4 dly-=12;
233 4 }
234 3 }
235 2 else if(!b3) //for button_right
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -