📄 laserscanning.lst
字号:
C51 COMPILER V7.09 LASERSCANNING 05/28/2005 15:04:13 PAGE 1
C51 COMPILER V7.09, COMPILATION OF MODULE LASERSCANNING
OBJECT MODULE PLACED IN LaserScanning.OBJ
COMPILER INVOKED BY: D:\Program Files\Keil\C51\BIN\C51.EXE LaserScanning.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include <REGX51.H>
2 #include "LCD.h"
3 #include "D12_USB.h"
4
5 sbit En573 = P3^4;
6 extern EVENT_FLAGS EventFlags; //事件信号
7 extern unsigned char idata EndPoint1Buffer[4];
8 //////////////////////////////////////////////////////////////////////////////////////////////////////////
-///////////
9 unsigned char IntToStrTemp[10];
10 void IntToStr(unsigned int t, unsigned char *str, unsigned char n)
11 {
12 1 unsigned char a[5]; char i, j;
13 1 a[0]=(t/10000)%10; //取得整数值到数组
14 1 a[1]=(t/1000)%10;
15 1 a[2]=(t/100)%10;
16 1 a[3]=(t/10)%10;
17 1 a[4]=(t/1)%10;
18 1
19 1 for(i=0; i<5; i++) //转成ASCII码
20 1 a[i]=a[i]+'0';
21 1 for(i=0; a[i]=='0' && i<=3; i++);
22 1 for(j=5-n; j<i; j++) //填充空格
23 1 { *str=' '; str++; }
24 1 for(; i<5; i++)
25 1 { *str=a[i]; str++; } //加入有效的数字
26 1 *str='\0';
27 1 }
28 //******************************************定时器相关****************************************************
-*******************
29 unsigned int Timer0Count,MotorPlusDelay;
30
31 void SetSpeed(unsigned int Speed)
32 {
33 1 MotorPlusDelay = Speed;
34 1 }
35
36 void InitialTimer0(void)
37 {
38 1 EventFlags.Bits.Timer = 0;
39 1 SetSpeed(10); //定时事件10ms
40 1 TMOD = 0x01;
41 1 TH0 = 0xFC;
42 1 TL0 = 0x18;
43 1 TR0=1;
44 1 ET0=1;
45 1 EA=1;
46 1 }
47
48 void Timer0(void) interrupt 1 using 3
49 {
50 1 TH0=0xFC;
51 1 TL0=0x18;
52 1 if(++Timer0Count>MotorPlusDelay)
53 1 {
C51 COMPILER V7.09 LASERSCANNING 05/28/2005 15:04:13 PAGE 2
54 2 Timer0Count = 0;
55 2 EventFlags.Bits.Timer = 1; //1ms定时溢出事件信号
56 2 }
57 1 }
58
59 //******************************************电机相关******************************************************
-*************
60 unsigned char MotorXIndex, MotorYIndex; //相位标志
61 unsigned char MotorXStatus, MotorYStatus; //端口状态
62 int MotorXPosion, MotorYPosion; //坐标
63 unsigned char RunMode = 0x00; //电机系统运行模式
64 bit Running = 0; //是否运行标志
65 unsigned char ScanRange = 0; //扫描范围
66 //扫描标志
67 bit MotorXArrival = 0,MotorYArrival = 0,RunDirection = 0;
68 unsigned char RectCodeIndex = 0,RoundCodeIndex = 0;RingIndex = 0;
69
70 unsigned char code MotorCodeX[8] = {0xFC,0xFD,0xF9,0xFB,0xF3,0xF7,0xF6,0xFE};
71 unsigned char code MotorCodeY[8] = {0xCF,0xDF,0x9F,0xBF,0x3F,0x7F,0x6F,0xEF};
72
73 void StopMotor(void) //释放端口
74 {
75 1 Running = 0;
76 1 P1 = 0xFF;
77 1 MotorXArrival = 0;
78 1 MotorYArrival = 0;
79 1 RunDirection = 0;
80 1 RectCodeIndex = 0;
81 1 RoundCodeIndex = 0;
82 1 RingIndex = 0;
83 1 }
84
85 void InitialMotor(void)
86 {
87 1 MotorXIndex = MotorYIndex = 0;
88 1 MotorXStatus = MotorCodeX[MotorXIndex];
89 1 MotorYStatus = MotorCodeY[MotorYIndex];
90 1 MotorXPosion = MotorYPosion = 0;
91 1 P1 = MotorXStatus&MotorYStatus;
92 1 Delay1ms(2);
93 1 StopMotor();
94 1 }
95 //Motor X
96 void MotorXOneStep(bit Direction)
97 {
98 1 if(Direction)
99 1 {
100 2 MotorXIndex = (MotorXIndex+7)%8;
101 2 MotorXPosion++;
102 2 }
103 1 else
104 1 {
105 2 MotorXIndex = (MotorXIndex+1)%8;
106 2 MotorXPosion--;
107 2 }
108 1 MotorXStatus = MotorCodeX[MotorXIndex];
109 1 P1 = MotorXStatus&MotorYStatus;
110 1 }
111 //Motor Y
112 void MotorYOneStep(bit Direction)
113 {
114 1 if(Direction)
C51 COMPILER V7.09 LASERSCANNING 05/28/2005 15:04:13 PAGE 3
115 1 {
116 2 MotorYIndex = (MotorYIndex+7)%8;
117 2 MotorYPosion++;
118 2 }
119 1 else
120 1 {
121 2 MotorYIndex = (MotorYIndex+1)%8;
122 2 MotorYPosion--;
123 2 }
124 1 MotorYStatus = MotorCodeY[MotorYIndex];
125 1 P1 = MotorXStatus&MotorYStatus;
126 1 }
127
128 void BackHome(void)//归位
129 {
130 1 if(MotorXPosion >= 0)
131 1 {
132 2 while(MotorXPosion !=0)
133 2 {
134 3 MotorXOneStep(0);
135 3 Delay1ms(2);
136 3 }
137 2 }
138 1 else
139 1 {
140 2 while(MotorXPosion !=0)
141 2 {
142 3 MotorXOneStep(1);
143 3 Delay1ms(2);
144 3 }
145 2 }
146 1
147 1 if(MotorYPosion >= 0)
148 1 {
149 2 while(MotorYPosion !=0)
150 2 {
151 3 MotorYOneStep(0);
152 3 Delay1ms(2);
153 3 }
154 2 }
155 1 else
156 1 {
157 2 while(MotorYPosion !=0)
158 2 {
159 3 MotorYOneStep(1);
160 3 Delay1ms(2);
161 3 }
162 2 }
163 1 }
164 //******************************************键盘检测******************************************************
-*************
165 unsigned char code KeyCode[] = {126,125,123,119,111,95,63};//0~6
166 unsigned char KeyStatus(void) //按键状态
167 {
168 1 unsigned char i,KeyValue;
169 1 En573 = 0;
170 1 KeyValue = P2&0x7F;
171 1 En573 = 1;
172 1 if(KeyValue == 0x7F)
173 1 return 0xFF;
174 1 for(i = 0; i<7; i++)
175 1 {
C51 COMPILER V7.09 LASERSCANNING 05/28/2005 15:04:13 PAGE 4
176 2 if(KeyValue == KeyCode[i])
177 2 return i;
178 2 }
179 1 return 0xFF;
180 1 }
181
182 unsigned char GetKey(void) //Press Key,(KeyDown,KeyUp)
183 {
184 1 unsigned char KeyOld,KeyNew;
185 1 KeyOld = KeyStatus();
186 1 if(KeyOld == 0xFF)
187 1 return 0xFF;
188 1 Delay1ms(3);
189 1 KeyNew = KeyStatus();
190 1 if(KeyNew == 0xFF)
191 1 return KeyOld;
192 1 else
193 1 return 0xFF;
194 1 }
195 //*****************************************CPU相关********************************************************
-************
196 void InitialCPU(void)
197 {
198 1 En573 = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -