新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > PHILIPS 51LPC系列單片機(jī)解析方案

PHILIPS 51LPC系列單片機(jī)解析方案

作者: 時(shí)間:2012-06-20 來(lái)源:網(wǎng)絡(luò) 收藏

void speed(s){ /*電機(jī)轉(zhuǎn)換控制子程序*/

uchar pulsecount, pulseduration=0;

uint i=0;

uint j=0;

if (((CMP10x02))!(CMP20x02)/*查詢比較器*/

{for (i=0;i

{for(j=0;j210;j++) ;} /*延時(shí)觸發(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設(shè)為高阻輸入*/

P0M2=0xd5; /*P00,P04,P06設(shè)為推挽方式*/

P1=0xff;

P1M1=0x82; /*P17用于VZC檢測(cè)*/

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; //啟動(dòng)電機(jī)

while(1)

{if(P1_1= =0) {

x=0;

while (!x){;}

if(P1_1=0)

{P1=0xff;s=s+1;} //停止電機(jī)

if(s= =8){s=0;}

while(!P1_1){;} //等待釋放按鍵

while(P10x80){};

while(!(P10x80)){};

while(P10x80)();

whie(!(P10x80)){};

while(P10x80){};

P1=P10xfe;} //啟動(dòng)電機(jī)

EA=1;TR0=1;

speed(s); }

} //結(jié)束


上一頁(yè) 1 2 3 下一頁(yè)

評(píng)論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉