📄 mcu.lst
字号:
100 void InitMCU(void)
101 {
102 1 unsigned char *p;
103 1 unsigned char i;
104 1 // P2 = 0xF0;
105 1 p = &PortA;
106 1 for(i=0; i<0x4A; i++){
107 2 *p = SystemRegTab[i];
108 2 p++;
109 2 }
110 1
111 1 // set timer 0
112 1 TMOD &= 0xf0;
113 1 TMOD |= 0x02;
114 1 TL0 = -250;
115 1 TH0 = -250;
116 1 TCON &= 0xcf;
117 1 TCON |= 0x10;
118 1
119 1 // set timer 1
120 1 TMOD &= 0x0f;
121 1 TMOD |= 0x20;
122 1 TL1 = 0xf3; //0xf3;
123 1 TH1 = 0xf3; //0xf3;
124 1 TCON &= 0x3f;
125 1 TCON |= 0x40;
126 1
127 1 SCON = 0x52;
128 1 PCON |= 0x80;
129 1
130 1 // set interrupt
131 1 CmdTxPtr1 = 0;
C51 COMPILER V7.20 MCU 09/14/2004 12:21:02 PAGE 19
132 1 CmdTxPtr2 = 0;
133 1 CmdRxPtr1 = 0;
134 1 CmdRxPtr2 = 0;
135 1 T0_INT_CNT = 0;
136 1 rwbuf = 0;
137 1 abuf = 0;
138 1 dbuf = 0;
139 1 IE = 0x86;
140 1 #ifdef Debug
flag3 = 4;
#else
143 1 flag3 = 0;
144 1 #endif
145 1
146 1 Sleep(50);
147 1 PowerStatus = 0xff;
148 1 IIC_BaudRate = 0x02;
149 1 LoadDDCData(1);
150 1 }
151
152 void Timer0(void) interrupt 1 using 2
153 {
154 1 if(++T0_INT_CNT >= 4){
155 2 T0_INT_CNT = 0;
156 2 if(Timer1 != 0) // 1ms
157 2 Timer1--;
158 2 if(++Timer10ms >= 10){ // 10ms
159 3 CLRWDT = 0x55;
160 3 Timer10ms = 0;
161 3 if(Timer2 != 0)
162 3 Timer2--;
163 3 if(Timer3 != 0)
164 3 Timer3--;
165 3 if(Timer4 != 0)
166 3 Timer4--;
167 3 if(RepeatTimer != 0)
168 3 RepeatTimer--;
169 3 if(PoSvTimer != 0)
170 3 PoSvTimer--;
171 3 }
172 2 }
173 1 }
174
175 void Sleep(unsigned short time)
176 {
177 1 Timer1 = time; /* timeout n ms */
178 1 while(Timer1 != 0){
179 2 }
180 1 }
181
182 void WaitSetup(unsigned short time)
183 {
184 1 Timer1 = time; /* timeout n ms */
185 1 while(Timer1 != 0){
186 2 CheckModeChange();
187 2 }
188 1 }
189
190 void ScanKeyPad(void)
191 {
192 1 //unsigned char i,j,k;
193 1 unsigned char Temp;
C51 COMPILER V7.20 MCU 09/14/2004 12:21:02 PAGE 20
194 1 Timer1 = 0;
195 1 /*
196 1 do{
197 1 while((ADC_REG[3] & BIT_7) == 0){};
198 1 KeyPad1 = ADC_REG[0] & 0x7f;
199 1 KeyPad2 = ADC_REG[1] & 0x7f;
200 1 if((ADC_REG[2] & 0x7f) < 0x38){
201 1 flag1 |= BIT_7;
202 1 return;
203 1 }
204 1 ADC_CON = 0x17; //Channel; // Start AD Convert
205 1 ADC_CON = 0x97; //Channel; // Start AD Convert
206 1 //check adc0
207 1 if(KeyPad1 > KeyTemp1){
208 1 if((KeyPad1 - KeyTemp1 ) > 5){
209 1 KeyTemp1 = KeyPad1;
210 1 flag1 |= BIT_2;
211 1 Timer1 = KeyStabTime;
212 1 }
213 1 }
214 1 else{
215 1 if((KeyTemp1 - KeyPad1 ) > 5){
216 1 KeyTemp1 = KeyPad1;
217 1 flag1 |= BIT_2;
218 1 Timer1 = KeyStabTime;
219 1 }
220 1 }
221 1 //check adc1
222 1 if(KeyPad2 > KeyTemp2){
223 1 if((KeyPad2 - KeyTemp2 ) > 5){
224 1 KeyTemp2 = KeyPad2;
225 1 flag1 |= BIT_2;
226 1 Timer1 = KeyStabTime;
227 1 }
228 1 }
229 1 else{
230 1 if((KeyTemp2 - KeyPad2 ) > 5){
231 1 KeyTemp2 = KeyPad2;
232 1 flag1 |= BIT_2;
233 1 Timer1 = KeyStabTime;
234 1 }
235 1 }
236 1
237 1 //check power key
238 1 if(((PortC & BIT_6) == 0)&&((flag3 & BIT_5) != 0)){
239 1 flag3 &= ~BIT_5;
240 1 flag1 |= BIT_2;
241 1 Timer1 = KeyStabTime;
242 1 }
243 1 if(((PortC & BIT_6) != 0)&&((flag3 & BIT_5) == 0)){
244 1 flag3 |= BIT_5;
245 1 flag1 |= BIT_2;
246 1 Timer1 = KeyStabTime;
247 1 }
248 1 }while(Timer1 != 0);
249 1 //change key
250 1 if((flag1 & BIT_2) != 0x00){
251 1 flag1 &= ~BIT_2;
252 1 if((flag3 & BIT_2) != 0x00){
253 1 printf("KEY1 = %x\r\n",(unsigned short)KeyTemp1);
254 1 printf("KEY2 = %x\r\n",(unsigned short)KeyTemp2);
255 1 }
C51 COMPILER V7.20 MCU 09/14/2004 12:21:02 PAGE 21
256 1 for(i=0; i<5; i++){
257 1 if(KeyTemp1 > KeyTab[i])
258 1 j = KeyTemp1 - KeyTab[i];
259 1 else
260 1 j = KeyTab[i] - KeyTemp1;
261 1 if(j < 16){
262 1 j = i;
263 1 break;
264 1 }
265 1 }
266 1 for(i=0; i<5; i++){
267 1 if(KeyTemp2 > KeyTab[i])
268 1 k = KeyTemp2 - KeyTab[i];
269 1 else
270 1 k = KeyTab[i] - KeyTemp2;
271 1 if(k < 16){
272 1 k = i;
273 1 break;
274 1 }
275 1 }
276 1 KeyBuffer = k << 4;
277 1 KeyBuffer |= j;
278 1 */
279 1
280 1 Temp=PortA;
281 1 Timer1=10;
282 1 while(Timer1);
283 1 Temp&=PortA;
284 1 Timer1=10;
285 1 while(Timer1);
286 1 KeyBuffer=(~Temp)&0x1F;
287 1 switch(KeyBuffer){
288 2 case 0x10:
289 2 KeyBuffer=PowerKey;
290 2 break;
291 2 case 0x08:
292 2 KeyBuffer=RightKey;
293 2 break;
294 2 case 0x04:
295 2 KeyBuffer=LeftKey;
296 2 break;
297 2 case 0x02:
298 2 KeyBuffer=DownKey;
299 2 break;
300 2 case 0x01:
301 2 KeyBuffer=UpKey;
302 2 break;
303 2 default:
304 2 KeyBuffer=0xff;
305 2 break;
306 2 }
307 1 if(KeyBuffer==KeyTemp1){flag1 &=~BIT_2;KeyTemp1=KeyBuffer;KeyBuffer=0xff;}
308 1 else {flag1 |= BIT_2; KeyTemp1=KeyBuffer;}
309 1
310 1
311 1
312 1 if((flag1 & BIT_2) != 0x00){/*
313 2 if((flag3 & BIT_5) == 0){
314 2 if(KeyBuffer == DownKey){
315 2 flag3 |= BIT_0;
316 2 flag2 &= ~BIT_5;
317 2 Write24C16(0xcd,0x01);
C51 COMPILER V7.20 MCU 09/14/2004 12:21:02 PAGE 22
318 2 if((flag3 & BIT_2) != 0x00)
319 2 printf("Entry Factory mode\r\n");
320 2 }
321 2 else{
322 2 flag3 &= ~BIT_0;
323 2 k = Read24C16(0xe1);
324 2 k = ColorTab[k];
325 2 if(k == 0)
326 2 flag2 &= ~BIT_5;
327 2 else
328 2 flag2 |= BIT_5;
329 2 Write24C16(0xcd,0x00);
330 2 if((flag3 & BIT_2) != 0x00)
331 2 printf("Release Factory mode\r\n");
332 2 }
333 2 flag2 &= 0xf3; //clear display flag
334 2 KeyBuffer = PowerKey;
335 2 }*/
336 2 if((flag3 & BIT_2) != 0x00)
337 2 printf("KeyBuffer = %x\r\n",(unsigned short)KeyBuffer);
338 2 // set repeat timer
339 2 Repeat = KeyBuffer;
340 2 RepeatTimer = KeyHoldTime;
341 2 }
342 1 else{
343 2 if((RepeatTimer == 0)&&((OSD_Type > 0x00)||(OSD_Type < 0x04))){
344 3 switch(Repeat){
345 4 case LeftKey:
346 4 KeyBuffer = Repeat;
347 4 RepeatTimer = KeyRepeatTime;
348 4 break;
349 4 case RightKey:
350 4 KeyBuffer = Repeat;
351 4 RepeatTimer = KeyRepeatTime;
352 4 break;
353 4 }
354 3 }
355 2 }
356 1 }
357
358 void CheckKey(void)
359 {
360 1 //unsigned char k;
361 1 ScanKeyPad();
362 1
363 1 //out of range
364 1 //power saving
365 1 if((PowerStatus & BIT_7) == 0){
366 2 if(KeyBuffer == RightKey){
367 3 ModePoint = 0xff;
368 3 }
369 2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -