?? systhree.lst
字號:
C51 COMPILER V8.05a SYSTHREE 06/29/2007 12:36:53 PAGE 1
C51 COMPILER V8.05a, COMPILATION OF MODULE SYSTHREE
OBJECT MODULE PLACED IN Systhree.OBJ
COMPILER INVOKED BY: D:\Program Files\keil\C51\BIN\C51.EXE Systhree.C BROWSE DEBUG OBJECTEXTEND
line level source
1 /*********************************************************/
2 /** **/
3 /** 作者:jia **/
4 /** 時間:2007/6/6 **/
5 /** National University of Defence Technology **/
6 /** 0731-4573493 **/
7 /*********************************************************/
8
9 #include <absacc.h>
10 #include <reg52.h>
11 #include<intrins.h>
12
13 #define uchar unsigned char
14 #define uint8 unsigned char
15 #define uint16 unsigned int
16
17 #define LED8 XBYTE [0xA000] //數碼管地址
18 #define LED7 XBYTE [0xA001]
19 #define LED6 XBYTE [0xA002]
20 #define LED5 XBYTE [0xA003]
21 #define LED4 XBYTE [0xA004]
22 #define LED3 XBYTE [0xA005]
23 #define LED2 XBYTE [0xA006]
24 #define LED1 XBYTE [0xA007]
25
26 #define YD_INTERNAL 5
27
28
29
30 #define KEY XBYTE [0xA100] //鍵盤地址
31
32
33 /*掃描鍵盤使用的變量 */
34 sbit first_row = P1^4; //鍵盤第一行控制
35 sbit second_row = P1^3; //鍵盤第二行控制
36 bit first_getkey = 0,control_readkey = 0; //讀鍵盤過程中的標志位
37 bit getkey = 0; //獲得有效鍵值標志位 等于1時代表得到一個有效鍵值
38 bit keyon = 0; //防止按鍵沖突標志位
39 uchar keynum = 0; //獲得的有效按鍵值寄存器
40
41 uchar T2count = 0;
42 bit MotorStart=0; //啟動電機控制
43 sbit MotorForward = P1^0;
44 sbit MotorBack = P1^1;
45 sbit P1_2 = P1^2; // 外接蜂鳴器報警
46 sbit P1_6 = P1^6; // #RE
47 sbit P1_7 = P1^7; // DE MAX487 發送前7置1,接受前6\7置0
48 sbit P1_5 = P1^5; // 液滴調試用
49
50
51
52 uchar Vset = 255;
53 uchar Vnow = 75;
54 uint16 MotorTimer = 100 ;
55 uint16 circle = 0;
C51 COMPILER V8.05a SYSTHREE 06/29/2007 12:36:53 PAGE 2
56 uint16 Vnow100 = 7500;
57 uchar NOset = 16; //設置的從站號
58
59
60
61 // 系數
62 #define COEF 105 //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
63 #define HEIGHT0 100 // 初始高度1m,系數1.67
64 #define V_INITIAL0 78 // 初始液滴速度 78 t/min
65 #define MotorV 137 // 電機速度,50cm/s 86cm/63s
66 #define CIRCLE 20
67
68
69 uchar state = 0 ;
70 bit alarm =0;
71 bit direction=0;// 0 represent move down
72 uint16 temV = 0;
73 uint16 num =0;
74 uchar icount[6] = {0} ;
75 uint16 i = 0;
76 uchar vh =0;
77 uchar vl =0;
78 uint16 HMove;
79
80 uchar num_yt=0;
81 uchar num_yd_actual=0;
82
83 /*數碼管顯示使用的變量和常量*/
84 uchar lednum = 0; //數碼管顯示位控制寄存器
85 uchar led[8] = {0,0,0,0,0,0,0,0}; //數碼管顯示內容寄存器
86 uchar code segtab[18] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0
-x8c,0xff}; //七段碼段碼表
87 // "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "
-P" ,"black"
88
89 void leddisp(void); //數碼管顯示函數
90 void readkey(void); //讀鍵盤函數
91 void setvalue (unsigned char keynum);
92
93 void delay(uint8 time_nop);
94 void SetMotorTimeT2();
95 void sendBuf();
96 //************************************************************************************************
97 //***********************************************************************************************
98 //定時器T0是用方式三,低八位用來定時4ms,LED 顯示和鍵盤掃描
99
100 void intTL0() interrupt 1 //TL0 定時中斷處理函數
101 {
102 1 static uchar TL0_i = 0; // 定義靜態變量,用來計數TL0定時器的溢出次數(進入本函數的次數)
103 1 static uchar TL0_j = 0; // 定義靜態變量,用來計數intr1定時器的延遲(進入本函數的次數)
104 1 TL0 = -2720%256;
105 1 if(TL0_i++ == 11)//定時器中斷時間間隔 4ms
106 1 {
107 2 TL0_i = 0;
108 2 leddisp(); //每次定時中斷顯示更新一次
109 2 if(EX1 == 0 && TL0_j++ >= YD_INTERNAL)
110 2 {
111 3 EX1 = 1;
112 3 TL0_j = 0;
113 3 }
114 2 if(control_readkey == 1) //每兩次定時中斷掃描一次鍵盤
115 2 {
C51 COMPILER V8.05a SYSTHREE 06/29/2007 12:36:53 PAGE 3
116 3 readkey();
117 3 }
118 2 control_readkey = !control_readkey;
119 2
120 2 if(MotorStart==1)
121 2 {
122 3 if(T2count == MotorTimer || Vnow>=Vset-2 && Vnow<=Vset+2) //|| Vnow>Vset-5 && Vnow<Vset+5
123 3 {
124 4 MotorStart=0;
125 4 MotorForward=0;
126 4 MotorBack=0;
127 4 T2count=0;
128 4 Vnow=Vset;
129 4 Vnow100 = 100*Vnow;
130 4 }
131 3 else
132 3 {
133 4 if(Vset >= Vnow) direction = 1;
134 4 else direction = 0;
135 4 if(!direction)
136 4 {
137 5 MotorBack=1;
138 5 MotorForward=0;
139 5 }
140 4 else
141 4 {
142 5 MotorForward=1;
143 5 MotorBack=0;
144 5 }
145 4 }
146 3 }
147 2 else
148 2 {
149 3 MotorStart=0;
150 3 MotorForward=0;
151 3 MotorBack=0;
152 3 T2count=0;
153 3 }
154 2 }
155 1 }
156
157 //*************************************外部中斷1**********************************************************
-***
158 //********************************************************************************************************
-*********************
159
160 // 點滴信號檢測,置P1_5口為1,觸發發光二極管點亮一段時間
161 // 外部中斷1,用來接收LM567音頻鎖相環的點滴信號(低電平)
162 // 內置計數器,根據定時器T0定時中斷,計數后放入icount[i]數組
163 void intr1_serve (void )interrupt 2
164 {
165 1 //static uchar intr1_i = 0;
166 1
167 1
168 1 EX1 = 0;
169 1 P1_5 = ~ P1_5;
170 1 num_yt+=1;
171 1 num_yd_actual=num_yt/2;
172 1
173 1 }
174 //************************************************************************************************
175
C51 COMPILER V8.05a SYSTHREE 06/29/2007 12:36:53 PAGE 4
176 //*************************************外部中斷0**********************************************************
-***
177 //********************************************************************************************************
-*********************
178
179
180 void intr0_serve (void )interrupt 0
181 {
182 1 alarm = 1;
183 1 }
184 //************************************************************************************************
185
186 //********************************************************************************************************
-*********************
187
188 // 由于T0采用工作方式3,所以T1只能用作串口波特率發生器
189 // 注意:從站Fsoc=12MHz,主站Fsoc=24MHz,只需將波特率設置相同即可
190 // 此時,TH0占用TF1,所以此中斷處理程序是處理T0的TH0的,定時器T0占用TF1,相當于T1中斷
191 // 最大定時周期為256us
192 void time2_serve (void)interrupt 5
193 {
194 1
195 1 static uchar Vn100 = 0;
196 1 static uchar T2_i = 0; // 定義靜態變量,用來計數TL0定時器的溢出次數(進入本函數的次數)
197 1 static uchar j = 0;
198 1 static uchar test_circle = 0;
199 1 TF2 = 0;
200 1 if( T2_i++ == 8 ) //0.5S
201 1 {
202 2 T2_i = 0 ;
203 2 T2count++ ;
204 2
205 2
206 2 if( test_circle++ == 20 ) // total count to 10s
207 2 {
208 3 // 把外部跳變數發到icount[i]
209 3 icount[i%6]=num_yd_actual;
210 3 i++;
211 3 // 將外部中斷計數清0
212 3 num_yd_actual=0;
213 3 test_circle = 0;
214 3 }
215 2
216 2 // 每十秒更新一次速度
217 2 if(i>=6)
218 2 {
219 3 Vnow=0;
220 3 Vnow100=0;
221 3
222 3 for(j=0;j<6;j++)
223 3 {
224 4 Vnow+=icount[(i-j)%6];
225 4 Vnow100 = 100*Vnow;
226 4 }
227 3 if(i==6)
228 3 vh=Vnow;
229 3 if(i==12)
230 3 vl=Vnow;
231 3 }
232 2 }
233 1 if( Vn100++ == 16 )
234 1 {
C51 COMPILER V8.05a SYSTHREE 06/29/2007 12:36:53 PAGE 5
235 2 Vn100 = 0;
236 2 if(direction == 0 && MotorStart==1)
237 2 {
238 3 Vnow100 -= 131;
239 3 }
240 2 else if (direction == 1 && MotorStart==1)
241 2 {
242 3 Vnow100 += 131;
243 3
244 3 }
245 2
246 2 }
247 1 }
248 //********************************************************************************************************
-*********************
249 //********************************************************************************************************
-*********************
250 // end of time1
251 //**************************************************************************************************
252 //************************************************************************************************
253 void ps_serve (void )interrupt 4
254 {
255 1 static wait = 0;
256 1 if(RI == 1)
257 1 {
258 2 uchar a = 0,b = 0;
259 2 P1_6 = 0;
260 2 P1_7 = 0;
261 2 a = SBUF;
262 2 P1_7 = 1;
263 2 b = a & 0x0F;
264 2 RI = 0;
265 2 if(a >= 192 && b == NOset)
266 2 {
267 3 sendBuf();
268 3
269 3 wait = 1;
270 3 if( a >= 208)
271 3 alarm =0;
272 3 }
273 2 else
274 2 {
275 3 if(wait == 1)
276 3 {
277 4 if(a>=20 && a<=150)
278 4 {
279 5 Vset = a;
280 5 SetMotorTimeT2();
281 5 }
282 4 P1_7 = 1;
283 4 SBUF = Vnow100/100;
284 4 P1_6 = 0;
285 4 P1_7 = 0;
286 4 wait = 0;
287 4 }
288 3
289 3 }
290 2 }
291 1 else TI = 0;
292 1
293 1 }
294
C51 COMPILER V8.05a SYSTHREE 06/29/2007 12:36:53 PAGE 6
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -