單片機(jī)HEX文件下載:04032801_1_8COM.rar C51源碼:
/*---------------------------------------- 8路紅外遙控開關(guān)控制器 (SAA3010T電視遙控器) Copyright 2004/3/27 http://www.cdle.net http://bbs.cdle.net All rights reserved.
明浩 E-mail: pnzwzw@163.com pnzwzw@cdle.net 只用八路時(shí)可以用AT89C2051代替AT89C51 一體化接收頭輸出端拉P3.2(int0),P1為控制輸出端。 可以擴(kuò)展到32路或更多 輸出為低電平有效 ----------------------------------------*/ #include AT89x51.h> static unsigned char data IRCode[3],IRCON,IRCON2; static unsigned char data DT; void main(void) { unsigned int de; TMOD =0x01; //定時(shí)器0方式1 EA =1; //允許CPU中斷 IT0 =1; //INT0下降沿有效 EX0 =1; //開INT0中斷; do { for (de=0; de10000; de++) P3_6 =1; for (de=0; de10000; de++) P3_6 =0; if (DT) { for (de=0; de30000; de++) //這里起到按鍵值正確后會(huì)有一個(gè)延時(shí),防止重復(fù)按鍵 P3_6 =1; for (de=0; de30000; de++) P3_6 =0; DT =0; } EX0 =1; } while(1); } //定時(shí)器0中斷處理 void timeint(void) interrupt 1 using 2 { TH0=0xFD; TL0=0x1E; //設(shè)定時(shí)值為800us if (IRCON3) { if (IRCON28) //每中斷一次讀一次遙控接收頭的狀態(tài),每二次為遙控編碼中的一個(gè)位 { IRCON2++; IRCode[IRCON]=IRCode[IRCON]1; //每讀一次放入變量中的二進(jìn)制的一個(gè)位,每次左移一位 IRCode[IRCON]=IRCode[IRCON] | P3_2; //每八次填滿一個(gè)字節(jié),一個(gè)字節(jié)存放遙控編碼4個(gè)位 } else { IRCON++; //填滿一個(gè)字節(jié),指向下一個(gè)變量 IRCON2=0; //計(jì)數(shù)清零 } } else { TR0 =0; //關(guān)閉定時(shí)器 ET0 =0; //定時(shí)器0中斷關(guān)閉 if ((IRCode[1]!=0xFF) (IRCode[2]!=0xFF)) { if (IRCode[1] ==0x55) { switch (IRCode[2]) { case 0xAB: //1-8鍵控制 P1_0 =~P1_0; DT =1; break; case 0xAC: P1_1 =~P1_1; DT =1; break; case 0xAD: P1_2 =~P1_2; DT =1; break; case 0xB2: P1_3 =~P1_3; DT =1; break; case 0xB3: P1_4 =~P1_4; DT =1; break; case 0xB4: P1_5 =~P1_5; DT =1; break; case 0xB5: P1_6 =~P1_6; DT =1; break; case 0xCA: P1_7 =~P1_7; DT =1; break; case 0xD2: //按關(guān)閉電源鍵,關(guān)閉所有繼電器 P1 =0xFF; DT =1; break; } } } } } //INT0中斷 void INT0Fun(void) interrupt 0 using 2 { EX0 =0; //外部中斷0關(guān)閉 ET0 =1; //定時(shí)器0中斷打開 TH0=0xFD; TL0=0x1E; //設(shè)定時(shí)值為800us
for (IRCON=0; IRCON3; IRCON++) IRCode[IRCON] =0; IRCON =0; IRCON2 =0; //計(jì)數(shù)清零 TR0 =1;//開始計(jì)數(shù) |
評(píng)論