2、eg51.h>//51芯片管腳定義頭文件#include//內(nèi)部包含延時(shí)函數(shù)_nop_()#defineucharunsignedchar#defineuintunsignedintucharcodeFFW[8]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};//正轉(zhuǎn)相序編碼ucharcodeREV[8]={0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01};//反轉(zhuǎn)相序編碼ucharcodeYK_code[]={0xfc,0xf8,0xf4,0xf0,0xec,0xe8,0x
3、e4,0xe0,0xdc,0xd8};//遙控器解碼對(duì)應(yīng)的編碼“0-9”ucharcodes8[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//數(shù)碼管顯示“0-9”ucharcodePM[2]={0xff,0xbf};//數(shù)碼管顯示正反轉(zhuǎn)ucharcodeSW[2]={0xbf,0x7f};//數(shù)碼管位顯示sbitIR=P3^2;//定義紅外接收器控制端口sbitBEEP=P3^6;//定義蜂鳴器控制端口uintLowTime,HighTime;//儲(chǔ)存高低電平寬度uchara[4];//儲(chǔ)存四位用
4、戶碼和數(shù)據(jù)碼ucharkey=10;//儲(chǔ)存檢測(cè)到的鍵值,預(yù)先置為無效位ucharcount=1;//數(shù)碼管顯示轉(zhuǎn)動(dòng)圈數(shù)的計(jì)數(shù)標(biāo)識(shí)位bitflag=0;//正轉(zhuǎn)反轉(zhuǎn)的標(biāo)志位bitwbs=0;//數(shù)碼管顯示位的標(biāo)識(shí)位/**************************************************函數(shù)功能:實(shí)現(xiàn)n毫秒延時(shí)入口參數(shù):n**************************************************/voiddelaynms(uinti){ucharj;while(i--){for(j=0;j<114;j++)//1
5、ms基準(zhǔn)延時(shí)程序{;}}}/**************************************************函數(shù)功能:蜂鳴器發(fā)出響聲**************************************************/voidbeep(void){uchari;for(i=0;i<80;i++){BEEP=~BEEP;delaynms(1);//延時(shí)}BEEP=1;//關(guān)閉蜂鳴器}/**************************************************函數(shù)功能:步進(jìn)電機(jī)正轉(zhuǎn)并在數(shù)碼管上顯示出來****
6、**********************************************/voidmotor_ffw(void){uchari,j;for(j=0;j<8;j++)//內(nèi)部轉(zhuǎn)軸轉(zhuǎn)一圈{if(wbs==0)//控制數(shù)碼管顯示P0=PM[flag];elseP0=s8[count];P2=SW[wbs];wbs=~wbs;for(i=0;i<8;i++)//一個(gè)周期轉(zhuǎn)四十五度{P1=FFW[i];//取數(shù)據(jù)delaynms(1);//調(diào)整速度}P2=0xff;}}/*******************************************
7、*******函數(shù)功能:步進(jìn)電機(jī)反轉(zhuǎn)并在數(shù)碼管上顯示出來**************************************************/voidmotor_rev(void){uchari,j;for(j=0;j<8;j++)//內(nèi)部轉(zhuǎn)軸轉(zhuǎn)一圈{if(wbs==0)//控制數(shù)碼管顯示P0=PM[flag];elseP0=s8[count];P2=SW[wbs];wbs=~wbs;for(i=0;i<8;i++)//一個(gè)周期轉(zhuǎn)四十五度{P1=REV[i];//取數(shù)據(jù)delaynms(1);//調(diào)整速度}P2=0xff;}}/*********