PHILIPS 51LPC系列單片機解析方案
void speed(s){ /*電機轉換控制子程序*/
uchar pulsecount, pulseduration=0;
uint i=0;
uint j=0;
if (((CMP10x02))!(CMP20x02)/*查詢比較器*/
{for (i=0;i
{for(j=0;j210;j++) ;} /*延時觸發(fā)*/
CMP1=CMP10xfc;
CMP2=CMP20xfc;
pulsecount=1;
{P1=P10xfe;
pulseduration=12; /*觸發(fā)脈沖寬度*/
while(pulseduration){pulseduration- -;}
P1=P1|0x01;
pulsecount- -;
}
}
}
void Initcomparatior(void){ //初始化P87LPC761//
PT0AD=0x6f; /*禁止P0口的數(shù)字功能*/
P0=0xff;
P0M1=0x2a; /*P01,P03,P05設為高阻輸入*/
P0M2=0xd5; /*P00,P04,P06設為推挽方式*/
P1=0xff;
P1M1=0x82; /*P17用于VZC檢測*/
P1M2=0x05;
CMP1=0x34;
CMP2=0x34;
}
void main(void)
{uchar pulsecount ,pulseduration=0x00;
uint j;i=0;
SP=0x5f;EA=0;
TH0=-(28/256);
TL0=-(28%256);
TF0=0;EA=0;TR0=0;
ET0=1;CMP1=CMP2=0;
Initcomparator();
CMP1=CMP10xfc;
CMP2=CMP20xfc;s=0;
while(P1_1) {;}
while(!P1_1){;}
while(P10x80){};
while(!(P10x80)){};
while(P10x80){}
while(!(P10x80)){};
while(P10x80){};
P1=P10xfe; //啟動電機
while(1)
{if(P1_1= =0) {
x=0;
while (!x){;}
if(P1_1=0)
{P1=0xff;s=s+1;} //停止電機
if(s= =8){s=0;}
while(!P1_1){;} //等待釋放按鍵
while(P10x80){};
while(!(P10x80)){};
while(P10x80)();
whie(!(P10x80)){};
while(P10x80){};
P1=P10xfe;} //啟動電機
EA=1;TR0=1;
speed(s); }
} //結束
評論