?? conrol.lst
字號:
C51 COMPILER V7.05 CONROL 09/27/2007 11:17:01 PAGE 1
C51 COMPILER V7.05, COMPILATION OF MODULE CONROL
OBJECT MODULE PLACED IN CONROL.OBJ
COMPILER INVOKED BY: C:\silabs\IDEfiles\C51\BIN\C51.exe CONROL.C DB OE
stmt level source
*** WARNING C500 IN LINE 1 OF CONROL.C: MISSING DEVICE (SECURITY KEY NOT FOUND)
1 //通信9個字節,前3個字節為幀頭,均為0xff;第四個字節為距離,a路占高4位
2 //bc路占低4位;第五個字節位速度a路占高4位,bc路占低4位;第六個字節為A路衰減量;
3 //第7個字節為B路衰減量;第8個字節為c路衰減量;第9個字節為控制開關信號,8位分別為
4 //* * * * 相參開關,c路開關,b路開關,a路開關,其中1為開,0為關
5 //系統采用15M晶振,每100ms更新一次距離延時,每秒鐘更新10次對應速度分別0,100m/s
6 //200m/s,300m/s,400m/s,500m/s,所以每100ms應該更新的距離分別為0m,10m,20m,30m
7 //40m,50m。15M的晶振一個脈沖對應的距離是10m。所以0m,10m,20m,30m
8 //40m,50m對應的脈沖改變量分別為0,1個,2個,3個,4個,5個。
9 //
10 //
11 //
12 //
13 //
14 #include <C8051F020.h>
15 #include <absacc.h>
16 #include <stdio.h>
17 #include <intrins.h>
18 #define uchar unsigned char
19 #define uint unsigned int
20 #define a_dis_com XBYTE[0x0FFF]
21 #define a_updata_com XBYTE[0x1FFF]
22 #define bc_dis_com XBYTE[0x2FFF]
23 #define bc_updata_com XBYTE[0x3FFF]
24 #define a_bc_v_com XBYTE[0x4FFF]
25 #define a_att_com XBYTE[0x5FFF]
26 #define b_att_com XBYTE[0x6FFF]
27 #define c_att_com XBYTE[0x7FFF]
28 #define on_off_com XBYTE[0X8FFF]
29 bit flag_a;
30 bit flag_bc;
31
32 uint code distance[]={1500,2000,5000,8000,15000,18000,21000,24000,27000,30000,32000};
33 uchar count_interrupt=0;
34 uchar count_receive_data;
35 uchar receive_data[9];
36 uchar a_dis,bc_dis;
37 uint a_conversion_data,bc_conversion_data;
38 uint save_a_inital_distance,save_bc_inital_distance;
39 uchar hex_h,hex_l;
40 uchar a_velocity,bc_velocity;
41 void dec_hex(uint x)
42 {hex_h=x/0xff;
43 1 hex_l=x%0xff;
44 1
45 1 }
46 void config_mcu (void)
47 {
48 1 //----------------------------------------------------------------
49 1 //看門狗配置
50 1 WDTCN = 0x07; // Watchdog Timer Control Register
51 1 WDTCN = 0xde; // 禁止看門狗
52 1 WDTCN = 0xAD;
53 1 // Configure the XBRn Registers
54 1 XBR0 = 0x04; // XBAR0: Initial Reset Value串口0使能
C51 COMPILER V7.05 CONROL 09/27/2007 11:17:01 PAGE 2
55 1 XBR1 = 0x00; // XBAR1: Initial Reset Value
56 1 XBR2 = 0xC0; // XBAR2: Initial Reset Value弱上拉全局禁止
57 1 P0MDOUT = 0xff; // Output configuration for P0
58 1 P1MDOUT = 0xff; // Output configuration for P1
59 1 P2MDOUT = 0xff; // Output configuration for P2
60 1 P3MDOUT = 0xff; // Output configuration for P3
61 1 P74OUT = 0xff; // Output configuration for P4-7
62 1 P1MDIN = 0xFF; // Input configuration for P1
63 1 EMI0CF = 0x3f; // EMIF ACTIVE ON p4-p7非復用movx指令訪問外部ram
64 1 }
65 //-------------------------------------------------------------------------
66 void SYSCLK_Init (void)
67 {
68 1 int i; /*延時計數器*/
69 1
70 1 OSCXCN = 0x67; /*打開外部晶體振蕩器*/
71 1 for (i=0; i < 256; i++) ; /*延時*/
72 1
73 1 while (!(OSCXCN & 0x80)) ; /*查詢外部晶體是否穩定起振*/
74 1
75 1 OSCICN = 0x08; /*用外部晶體作為系統時鐘,并禁止時鐘丟失檢測*/
76 1 }
77 //--------------------------------------------------------------------------
78 void UART0_Init (void)
79 {
80 1 SCON0 = 0x50; /*SCON0:模式1,8位UART,時能RX*/
81 1 TMOD = 0x20; /*TMOD: 定時器工作再模式2, 8位重載*/
82 1 TH1=0xfa; //波特率設置
83 1 TL1=0xfa; /*設置定時1用作波特率的重載值*/
84 1 TR1 = 1; /*開定時器1*/
85 1 CKCON = 0x00; /*定時器1用系統時鐘作12分頻為它的時基,定時器0用系統時鐘的12分頻作為
-時鐘,定時器2使用系統時鐘的12分頻作為時鐘*/
86 1 PCON = 0x80; /*SMOD00 = 1*/
87 1 }
88
89 //---------------------------------------------------------------------------------
90 void ComTx(uchar x){
91 1 SBUF0=x;
92 1 while(TI0==0);
93 1 TI0=0;
94 1 }
95 //-------------------------------------------------------------------------------------
96 void output_control_paramater(uint a_distance_data,uint bc_distance_data,uchar a_bc_v_data ,uchar a_att_
-data,
97 uchar b_att_data,uchar c_att_data,uchar on_off_data)
98 {dec_hex(a_distance_data);
99 1 a_dis_com=hex_l;
100 1 a_dis_com=hex_h;
101 1 a_updata_com=0x00;
102 1 dec_hex(bc_distance_data);
103 1 bc_dis_com=hex_l;
104 1 bc_dis_com=hex_h;
105 1 bc_updata_com=0x00;
106 1 a_bc_v_com=a_bc_v_data ;
107 1 a_att_com=a_att_data;
108 1 b_att_com=b_att_data;
109 1 c_att_com=c_att_data;
110 1 on_off_com=on_off_data;
111 1 }
112 //-------------------------------------------------------------------------------------
113 void main(void)
114 {
C51 COMPILER V7.05 CONROL 09/27/2007 11:17:01 PAGE 3
115 1
116 1 uchar crc,i;
117 1 crc=0;
118 1 config_mcu();
119 1 SYSCLK_Init();
120 1 UART0_Init();
121 1 output_control_paramater(0X00,0X00,0X00,0X00,0X00,0X00,0x00);//A,B,C路關閉
122 1 count_receive_data=0;
123 1 receive_data[9]=(0,0,0,0,0,0,0,0,0);
124 1 TL0=0xdf; //定時器0定時60ms
125 1 TH0=0x01;
126 1 T2CON=T2CON & 0XF0;//
127 1 EA=1;//使能總中斷
128 1 ES0=1;//使能串口0中斷
129 1 ET0=1;//使能定時器0中斷
130 1 ET2=1;//使能定時器2中斷
131 1
132 1 //ComTx(0x30);
133 1 while(1)
134 1 { do
135 2 { if (count_receive_data>=1)
136 3 //TR0=1;
137 3 ;
138 3 }
139 2 while(count_receive_data<9);
140 2 EA=0;
141 2 TR0=0;
142 2 TL0=0xdf;//定時器0定時20ms
143 2 TH0=0x01;
144 2 TL2=0x77; //定時器2定時50ms
145 2 TH2=0xec;
146 2 RCAP2L=0x77;
147 2 RCAP2H=0xec;
148 2 bc_dis=receive_data[3]&0x0f;//為轉換BC路距離,可直接查表
149 2 a_dis=receive_data[3]>>4;//為轉換后A路距離,可直接查表
150 2 a_velocity=(receive_data[4]>>4);//為轉換后A路速度,
151 2 if (a_velocity>=8)
152 2 flag_a=1;
153 2 else
154 2 flag_a=0;
155 2 a_velocity=a_velocity&0x07;//去掉符號位
156 2 bc_velocity=(receive_data[4]&0x0f);//為轉換后BC路速度,
157 2 if (bc_velocity>=8)
158 2 flag_bc=1;
159 2 else
160 2 flag_bc=0;
161 2 bc_velocity=bc_velocity&0x07;//去掉符號位
162 2 a_conversion_data=distance[a_dis];//轉換成A路應延時的脈沖數
163 2 bc_conversion_data=distance[bc_dis];//轉換成BC路應延時的脈沖數
164 2 save_a_inital_distance=a_conversion_data;
165 2 save_bc_inital_distance=bc_conversion_data;
166 2
167 2 if( receive_data[0]==0xff && receive_data[1]==0xff && receive_data[2]==0xff)
168 2 {for (i=3;i<9;i++)
169 3 crc=crc+receive_data[i];
170 3 ComTx(crc);
171 3 crc=0;
172 3 output_control_paramater(a_conversion_data,bc_conversion_data,receive_data[4],receive_data[5],receive
-_data[6],receive_data[7],receive_data[8]);
173 3 TR2=1;
174 3 }
175 2 count_receive_data=0;
C51 COMPILER V7.05 CONROL 09/27/2007 11:17:01 PAGE 4
176 2 receive_data[9]=(0,0,0,0,0,0,0,0,0);
177 2 EA=1;
178 2 }
179 1 }
180
181 /*串口中斷0子程序*/
182 void UART0_ISR (void) interrupt 4
183 {
184 1 if(!TI0) //是發送中斷還是接收中斷
185 1 { receive_data[count_receive_data]=SBUF0;
186 2 count_receive_data++;
187 2 RI0 = 0; /*清接收標志位*/
188 2 }
189 1 TI0 = 0; /*清發送標志位*/
190 1
191 1 }
192 /*定時器0中斷服務程序*/
193 void Timer0_Isr(void) interrupt 1
194 {
195 1 TR0=0;
196 1 TL0=0xdf;//定時器0定時20ms
197 1 TH0=0x01;
198 1 count_receive_data=0;
199 1 receive_data[9]=(0,0,0,0,0,0,0,0,0);
200 1 }
201 void Timer2_ISR (void) interrupt 5
202 {
203 1 TF2=0; //清除中斷標志
204 1 count_interrupt++;//中斷次數加1
205 1 if (count_interrupt==2) //100ms定時到
206 1 {count_interrupt=0;
207 2 //A路轉換后的距離換算
208 2 if(!flag_a)
209 2 a_conversion_data=a_conversion_data-a_velocity;
210 2 else
211 2 a_conversion_data=a_conversion_data+a_velocity;
212 2 //BC路轉換后的距離換算
213 2 if(!flag_bc)
214 2 bc_conversion_data=bc_conversion_data-bc_velocity;
215 2 else
216 2 bc_conversion_data=bc_conversion_data+bc_velocity;
217 2 output_control_paramater(a_conversion_data,bc_conversion_data,receive_data[4],receive_data[5],receive_da
-ta[6],receive_data[7],receive_data[8]);
218 2 if ((a_conversion_data>36000 )||(a_conversion_data<5))
219 2 a_conversion_data=save_a_inital_distance;
220 2 if ((bc_conversion_data>=36000) ||(bc_conversion_data<=5))
221 2 bc_conversion_data=save_bc_inital_distance;
222 2 }
223 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 711 ----
CONSTANT SIZE = 22 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 25 10
IDATA SIZE = ---- ----
BIT SIZE = 2 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -