?? hw.lst
字號:
C51 COMPILER V8.08 HW 12/26/2008 22:19:58 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE HW
OBJECT MODULE PLACED IN HW.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE HW.C BROWSE DEBUG OBJECTEXTEND
line level source
*** WARNING C500 IN LINE 1 OF HW.C: LICENSE ERROR (R208: RENEW LICENSE ID CODE (LIC))
1 #include <reg52.h>
2 #include <ctype.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <math.h>
7 #include <absacc.h>
8
9 #define uchar unsigned char
10 #define uint unsigned int
11 #define ulong unsigned long
12
13 sbit sm1623_dout=P1^0;
14 sbit sm1623_din=P1^1;
15 sbit sm1623_clk=P1^2;
16 sbit sm1623_stb=P1^3;
17 sbit hw_send=P1^4;
18 sbit sound=P1^5;
19 sbit P3_2=P3^2;
20
21 void delay(uchar delay_temp);//長延時
22 void delaym(uchar delaym_temp);//短延時
23 void disp(uchar dis);
24 void display();
25 uchar key(void);
26 uchar key_deal(void);
27
28 uchar i,j,k;
29 uchar temp_1,temp_2;
30 uchar code_dis[6];
31 uchar pulse;
32 uchar hw[34];
33
34 const uchar code hw_t[13]={3,2,3,2,6,2,3,2,3,2,3,2,3};
35 const uchar code hw_1[12]={2,3,2,3,2,3,2,3,2,3,5,3};
36 const uchar code hw_2[12]={2,3,2,3,2,3,2,3,5,6,0,0};
37 const uchar code hw_3[12]={2,3,2,3,2,3,2,3,5,3,2,3};
38 const uchar code hw_4[12]={2,3,2,3,2,3,5,6,2,3,0,0};
39 const uchar code hw_5[12]={2,3,2,3,2,3,5,6,5,3,0,0};
40 const uchar code hw_6[12]={2,3,2,3,2,3,5,3,2,6,0,0};
41 const uchar code hw_7[12]={2,3,2,3,2,3,5,3,2,3,2,3};
42 const uchar code hw_8[12]={2,3,2,3,5,6,2,3,2,3,0,0};
43 const uchar code hw_9[12]={2,3,2,3,5,6,2,3,5,3,0,0};
44 const uchar code hw_0[12]={2,3,2,3,2,3,2,3,2,3,2,3};
45
46 //紅外測試程序
47 exint0() interrupt 0
48 {
49 1 TR0=0;TR1=0;//關閉定時器0、1
50 1 if(pulse>15)
51 1 {
52 2 TR0=0;TR1=0;
53 2 TL0=0;TH0=0;TL1=0;TH1=0;
54 2 pulse=0;
C51 COMPILER V8.08 HW 12/26/2008 22:19:58 PAGE 2
55 2 return;
56 2 }
57 1
58 1 hw[pulse*2]=TH1-TH0;//低電平寬度
59 1 hw[pulse*2+1]=TH0;//高電平寬度
60 1 TL0=0;TH0=0;TL1=0;TH1=0;//定時器賦初值
61 1 TR0=1;TR1=1;//打開定時器0、1
62 1 delaym(10);//延時判斷是否是干擾脈沖(干擾脈沖比較窄)
63 1 P3_2=1;//判斷INT0輸入端是否為高電平,如是高電平說明是干擾脈沖
64 1 if(P3_2==1)
65 1 {
66 2 TR0=0;TR1=0;
67 2 TL0=0;TH0=0;TL1=0;TH1=0;
68 2 pulse=0;
69 2 return;
70 2 }
71 1 pulse++;
72 1 }
73
74 timer0() interrupt 1
75 {
76 1 uchar i;
77 1 if(temp_2==0)//紅外接收
78 1 {
79 2 TR0=0;TR1=0;//關定時器
80 2 TL0=0;TH0=0;TL1=0;TH1=0;//定時器賦初值
81 2 pulse=0;
82 2 for(i=0;i<16;i++)
83 2 {
84 3 hw[2*i]=0;
85 3 hw[2*i+1]=0;
86 3 }
87 2 hw[20]=0;
88 2 }
89 1 else//紅外發(fā)送
90 1 {
91 2 if(pulse==26)
92 2 {
93 3 EA=0;
94 3 TR0=0;//關閉定時器0
95 3 hw_send=1;
96 3 return;
97 3 }
98 2 if(hw[pulse]!=0)
99 2 {
100 3 TH0=0xff-hw[pulse];
101 3 TL0=0xe0;
102 3 pulse++;
103 3 hw_send=!hw_send;
104 3 }
105 2 else//遇到最后一個脈沖
106 2 {
107 3 EA=0;
108 3 TR0=0;//關閉定時器0
109 3 hw_send=1;
110 3 pulse=26;
111 3 }
112 2 }
113 1 }
114
115 timer1() interrupt 3
116 {
C51 COMPILER V8.08 HW 12/26/2008 22:19:58 PAGE 3
117 1 uchar i;
118 1 EA=0;
119 1 TR0=0;TR1=0;
120 1 hw[2*pulse]=256-TH0;//可以計算最后一個低電平寬度
121 1 TL0=0;TH0=0;TL1=0;TH1=0;
122 1
123 1 //獲得遙控按鍵鍵值并顯示
124 1 if(memcmp(hw+15,hw_1,12)==0)
125 1 {
126 2 sound=0;//鳴響
127 2 code_dis[5]=1;
128 2 display();
129 2 goto hw_ok;
130 2 }
131 1 if(memcmp(hw+15,hw_2,12)==0)
132 1 {
133 2 sound=0;//鳴響
134 2 code_dis[5]=2;
135 2 display();
136 2 goto hw_ok;
137 2 }
138 1 if(memcmp(hw+15,hw_3,12)==0)
139 1 {
140 2 sound=0;//鳴響
141 2 code_dis[5]=3;
142 2 display();
143 2 goto hw_ok;
144 2 }
145 1 if(memcmp(hw+15,hw_4,12)==0)
146 1 {
147 2 sound=0;//鳴響
148 2 code_dis[5]=4;
149 2 display();
150 2 goto hw_ok;
151 2 }
152 1 if(memcmp(hw+15,hw_5,12)==0)
153 1 {
154 2 sound=0;//鳴響
155 2 code_dis[5]=5;
156 2 display();
157 2 goto hw_ok;
158 2 }
159 1 if(memcmp(hw+15,hw_6,12)==0)
160 1 {
161 2 sound=0;//鳴響
162 2 code_dis[5]=6;
163 2 display();
164 2 goto hw_ok;
165 2 }
166 1 if(memcmp(hw+15,hw_7,12)==0)
167 1 {
168 2 sound=0;//鳴響
169 2 code_dis[5]=7;
170 2 display();
171 2 goto hw_ok;
172 2 }
173 1 if(memcmp(hw+15,hw_8,12)==0)
174 1 {
175 2 sound=0;//鳴響
176 2 code_dis[5]=8;
177 2 display();
178 2 goto hw_ok;
C51 COMPILER V8.08 HW 12/26/2008 22:19:58 PAGE 4
179 2 }
180 1 if(memcmp(hw+15,hw_9,12)==0)
181 1 {
182 2 sound=0;//鳴響
183 2 code_dis[5]=9;
184 2 display();
185 2 goto hw_ok;
186 2 }
187 1 if(memcmp(hw+15,hw_0,12)==0)
188 1 {
189 2 sound=0;//鳴響
190 2 code_dis[5]=0;
191 2 display();
192 2 }
193 1 hw_ok: pulse=0;
194 1 for(i=0;i<16;i++)
195 1 {
196 2 hw[2*i]=0;
197 2 hw[2*i+1]=0;
198 2 }
199 1 hw[20]=0;
200 1 EA=1;
201 1 }
202
203 main(void)
204 {
205 1 start:
206 1 hw_send=1;
207 1 temp_2=0;
208 1 //---------------------------------------紅外接收測試
209 1 pulse=0;
210 1 EA=0;
211 1 TL0=0;
212 1 TH0=0;
213 1 TL1=0;
214 1 TH1=0;
215 1 TMOD=0x19;//T0受INT0控制、T0、T1為定時,工作方式1
216 1 IT0=1;//外部中斷0為邊沿觸發(fā)方式
217 1 EX1=0;//不允許INT1中斷
218 1 EX0=1;//允許INT0中斷
219 1 ET1=1;//允許T1中斷
220 1 ET0=1;//允許T0中斷
221 1 EA=1;//允許中斷
222 1
223 1 for(i=0;i<5;i++)code_dis[i]=13;
224 1 code_dis[5]=10;
225 1 display();//最后一位顯示黑
226 1 while(key_deal()!=8)
227 1 {
228 2 delay(0xff);
229 2 if(code_dis[5]!=10)
230 2 {
231 3 sound=1;//關鳴響
232 3 code_dis[5]=10;
233 3 display();//最后一位顯示黑
234 3 }
235 2 }
236 1
237 1 //---------------------------------------紅外發(fā)送測試
238 1 EA=0;//關中斷
239 1 temp_2=0xff;//表示定時器0中斷中執(zhí)行紅外發(fā)送程序
240 1 pulse=26;
C51 COMPILER V8.08 HW 12/26/2008 22:19:58 PAGE 5
241 1 TL0=0;
242 1 TH0=0;
243 1 TL1=0;
244 1 TH1=0;
245 1 EX1=0;//不允許INT1中斷
246 1 EX0=0;//不允許INT0中斷
247 1 ET1=0;//不允許T1中斷
248 1 ET0=1;//允許T0中斷
249 1 code_dis[5]=10;
250 1 display();
251 1 sound=0;
252 1 delay(0xff);
253 1 sound=1;
254 1 memcpy(hw,hw_t,15);
255 1 for(i=0;i<5;i++)code_dis[i]=14;
256 1 code_dis[5]=10;
257 1 display();
258 1
259 1 while(1)
260 1 {
261 2 temp_1=key_deal();
262 2 switch(temp_1)
263 2 {
264 3 case 1:
265 3 EA=0;
266 3 goto start;
267 3 break;
268 3 case 2:
269 3 if(pulse==26)
270 3 {
271 4 delay(0xff);
272 4 pulse=0;
273 4 memcpy(hw+13,hw_2,12);
274 4 TH0=0xff-hw[pulse];
275 4 TL0=0xe0;
276 4 pulse++;
277 4 hw_send=0;
278 4 EA=1;//允許中斷
279 4 TR0=1;//打開定時器0
280 4 }
281 3 sound=0;
282 3 code_dis[5]=2;
283 3 display();
284 3 break;
285 3 case 3:
286 3 if(pulse==26)
287 3 {
288 4 delay(0xff);
289 4 pulse=0;
290 4 memcpy(hw+13,hw_3,12);
291 4 TH0=0xff-hw[pulse];
292 4 TL0=0xe0;
293 4 pulse++;
294 4 hw_send=0;
295 4 EA=1;//允許中斷
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -