?? ir.lst
字號:
C51 COMPILER V8.05a IR 03/20/2009 21:16:22 PAGE 1
C51 COMPILER V8.05a, COMPILATION OF MODULE IR
OBJECT MODULE PLACED IN ir.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ir.c ROM(COMPACT) BROWSE DEBUG OBJECTEXTEND
line level source
1 #include<reg51.h>
2 #include <intrins.h>
3 #define uchar unsigned char
4 #define uint unsigned int
5 #define ulong unsigned long
6
7
8 #define Nop() {_nop_(); _nop_(); _nop_(); _nop_(); _nop_();}
9
10
11
12 volatile ulong IRcode=0x00000000; //32位的鍵代碼
13 volatile ulong Irdcode=0x00000000;
14 volatile uint customcode=0x0000; //16位用戶碼
15 volatile uint time_us=0x0000; //兩個下降沿之間的時間
16
17 volatile uchar timeH,timeL; //保存TH1 TL的值
18
19 uchar Lcustomcode; //低8用戶碼
20 uchar Hcustomcode; //高8
21 uchar datacode; //8位鍵數據碼
22 uchar mycode;
23 uchar Rdatacode; //8位鍵數據反碼
24 uchar uc1ms;
25 uchar uc10ms;
26 uchar uc3ms;
27
28
29 uchar ucDispTime;
30 uchar ucDispOrder;
31 uchar ucDispCon;
32 uchar ucSpeakerTime;
33 unsigned char code LedData[16] = { 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0
-x86,0x8e};
34 unsigned char code LedCon[2] = {0x8f,0x4f};
35 unsigned char ucDispData[2]; // 存放顯示數據
36 sbit led1 = P3^7;
37 sbit led2 = P3^6;
38 sbit power=P1^0; //電源開關
39 sbit BEEP= P2^1;
40 bit NewIRcode=0; //指示當處理完了32位碼后,就有了新的遙控碼
41 bit DataRight=0; //為1時讀取數據正確
42 bit bSampleOk;
43 bit bSampling;
44 bit b10msInt;
45 bit b1msInt;
46 bit bKeySound;
47 bit b1msMain;
48 bit IR_E; //表示有新的遙控鍵控下就更新掃描數據
49 bit b3msint;
50
51 void SendDataToDispDevice();
52 void Ir_process();
53 void display();
54 void beeping();
C51 COMPILER V8.05a IR 03/20/2009 21:16:22 PAGE 2
55
56 /****** 晶振為12 MHZ*******/
57 /**定時器1,12 MHZ最大定時為65.53ms***/
58 //------------------------------------------------------------------------------
59 void init()
60 {
61 1 IP=0x09; //定時器1,外部中斷0優先級高
62 1 TMOD=0x11; //定時器0,工作方式1 ; 定時器1,工作方式1
63 1 TCON=0x01; //外中斷0下降沿觸發,(包括TR1=0,TR0=0)
64 1 TH0=0xff; //初始化定時器0,定時0.2ms
65 1 TL0=0x47;
66 1 TH1=0x00; //初始化定時器1
67 1 TL1=0x00;
68 1
69 1 EA=1; //開全中斷
70 1 ET0=1; //開放T0中斷
71 1 ET1=1; //開放T1中斷
72 1 EX0=1; //開放INT0
73 1 TR1=0;
74 1 TR0=1;
75 1
76 1 }
77 //--------------------------------------
78 void TimeProg(void)
79 {
80 1 b1msMain = b1msInt;
81 1 b1msMain=0;
82 1 b10msInt = 0;
83 1
84 1
85 1 if(b1msInt == 1)
86 1 {
87 2 b1msMain=1;
88 2 if(++uc10ms == 10)
89 2 {
90 3 uc10ms = 0;
91 3 b10msInt = 1;
92 3 if(bKeySound==1)
93 3 { beeping();
94 4 bKeySound=0;
95 4 }
96 3 }
97 2
98 2 }
99 1 }//void TimeProg(void)
100 //-------------------------------------interrupt0-------------------------------------
101 void IR_ISR() interrupt 0 using 1 //遙控器中斷處理函數
102 {
103 1 static uchar cn;
104 1
105 1 TR1=0;
106 1 timeH=TH1;
107 1 timeL=TL1;
108 1 TH1=0;
109 1 TL1=0;
110 1 TR1=1; //開定時器中斷1
111 1
112 1 time_us=(unsigned int)timeH;
113 1 time_us=time_us<<8;
114 1 time_us=time_us|timeL;
115 1
116 1 if(time_us>12200&&time_us<13000) {cn=1;IRcode=0;} //遇到引導碼,就把cn清0,IRcode清0
C51 COMPILER V8.05a IR 03/20/2009 21:16:22 PAGE 3
117 1 //引導碼的時間長度為9ms+4.5ms
118 1 if(cn<34)
119 1 {
120 2 if(time_us>950&&time_us<1120) //0
121 2 {
122 3 IRcode=IRcode|0x00000000;
123 3 if(cn<33) IRcode=IRcode>>1;
124 3 }
125 2
126 2 else if(time_us>1920&&time_us<2120) //1t > 1950 && t < 2150
127 2 {
128 3 IRcode=IRcode|0x80000000;
129 3 if(cn<33) IRcode=IRcode>>1;
130 3 }
131 2
132 2
133 2 //else if(time_us>10000&&time_us<11000) {Irdcode=IRcode;cn=34; } //遇到重復碼
134 2 //cn用于記錄接收到的數據位
135 2 }
136 1 cn++;
137 1 if(cn==34)
138 1 { NewIRcode=1;
139 2 TR1=0;
140 2
141 2 Irdcode= IRcode; cn=0;
142 2 } //讀完32位碼,則有新碼產生
143 1
144 1 }
145
146 //--------------------------------------timer_ISR------------------------------
147 void Timer0_ISR() interrupt 1 using 2 //定時器0中斷函數
148 {
149 1 TR0=0;
150 1 TH0=0xff; //初始化定時器0,定時0.2ms 晶振為11.0592 MHZ
151 1 TL0=0x47;
152 1 TR0=1;
153 1 if(++uc1ms == 5)
154 1 {
155 2 uc1ms = 0;
156 2 b1msInt=1;
157 2 if(++uc3ms==8)
158 2 {
159 3 uc3ms=0;
160 3 b3msint=1;
161 3 SendDataToDispDevice(); //n* ms送一次顯示
162 3 }
163 2
164 2
165 2 }
166 1 }//void Timer0IntProg() interrupt 1 using 1
167
168 void Timer1_ISR() interrupt 3 using 3 //定時器1中斷函數
169 {
170 1 TR1=0;
171 1 TH1=0x00; //初始化定時器1
172 1 TL1=0x00;
173 1 TR1=1;
174 1
175 1 }
176 //--------------------SendDataToDispDevice----------
177 void SendDataToDispDevice()
178 {
C51 COMPILER V8.05a IR 03/20/2009 21:16:22 PAGE 4
179 1 unsigned char n;
180 1 //watchdog();
181 1 if(++ucDispOrder >= 2) ucDispOrder = 0; // 下一顯示巡回
182 1
183 1 // 下面為發送控制數據 位控
184 1
185 1 if(ucDispOrder==0)
186 1 {led1=0;
187 2 led2=1;
188 2 Nop();
189 2 Nop();
190 2
191 2 }
192 1 if(b3msint==1)
193 1 {if(ucDispOrder==1)
194 2 {led2=0;
195 3 led1=1;
196 3 Nop();
197 3 Nop();
198 3 }
199 2 }
200 1 // 下面為發送顯示數據
201 1 n = LedData[ucDispData[ucDispOrder]];
202 1 P0=n;
203 1
204 1
205 1
206 1 } //void SendDataToDispDevice()
207
208 //------------------------------------main()----------------------------------------------
209 void main()
210 {
211 1
212 1 init();
213 1 beeping();
214 1 while(1)
215 1 {
216 2 TimeProg();
217 2 Ir_process();
218 2 display();
219 2
220 2 }
221 1
222 1 }
223
224 void Ir_process()
225
226 {
227 1
228 1 if(NewIRcode==1) //如果有新的遙控碼就讀
229 1 {
230 2 NewIRcode=0; //讀完之后清零,表示新碼已讀
231 2 customcode=(Irdcode>>16); //取紅外碼中的按碼鍵
232 2 //取低8位用戶碼
233 2 Lcustomcode=customcode>>8;//取低8位按碼鍵
234 2 datacode=(unsigned char)(customcode&0x00ff); //取高8位按碼鍵
235 2
236 2
237 2 Rdatacode=Lcustomcode; //取低8位按碼鍵的反碼
238 2
239 2 if(~Rdatacode!=datacode)
240 2 { DataRight=0;
C51 COMPILER V8.05a IR 03/20/2009 21:16:22 PAGE 5
241 3 Irdcode=0;
242 3 datacode=Rdatacode=0;
243 3 } //校驗用戶碼,反碼
244 2
245 2 else
246 2 { DataRight=1;
247 3 IR_E=1;
248 3 mycode=datacode;}
249 2 if(DataRight==1) { bKeySound = 1;DataRight=0; }
250 2
251 2 }
252 1
253 1
254 1
255 1 }
256
257 void display()
258 {
259 1 /* unsigned char a[2];
260 1 a[0] = mycode & 0x0f;
261 1 mycode = mycode >> 4;
262 1 a[1] = mycode & 0x0f;
263 1 ET0 = 0;
264 1 ucDispData[0] = a[0];
265 1 ucDispData[1] = a[1];
266 1 ET0 = 1;*/
267 1 if(IR_E==1)
268 1 {
269 2 ET0 = 0;
270 2 ucDispData[0] = mycode & 0x0f;
271 2 mycode = mycode >> 4;
272 2 ucDispData[1] = mycode & 0x0f;
273 2 IR_E=0;
274 2 ET0 = 1;
275 2 }
276 1 }
277
278 /**********************************************************/
279 void delay(unsigned char x) //x*0.14MS
280 {
281 1 unsigned char a;
282 1 while(x--)
283 1 {
284 2 for (a = 0; a<13; a++) {;}
285 2 }
286 1 }
287
288
289 /**********************************************************/
290 void beeping()
291 {
292 1 unsigned char i;
293 1
294 1 for (i=0;i<100;i++)
295 1 {
296 2 delay(4);
297 2 BEEP=!BEEP; //BEEP取反
298 2 }
299 1 BEEP=1;
300 1 //關閉蜂鳴器
301 1 }
302
C51 COMPILER V8.05a IR 03/20/2009 21:16:22 PAGE 6
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 587 ----
CONSTANT SIZE = 18 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 29 ----
IDATA SIZE = ---- ----
BIT SIZE = 10 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -