日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 單片機 > 單片機
[導讀] MCU:at90s2313時鐘:4MHz#include#include#defineucharunsignedchar#defineuintunsignedint#defineSET_RED_LEDPORTD|=_BV(5)//PD5接紅色發(fā)光管#defineCLR_RED_LEDPORTD&=~_BV(5)#defineSET_GRN_LEDPORT

MCU:at90s2313
時鐘:4MHz

#include
#include

#defineucharunsignedchar
#defineuintunsignedint

#defineSET_RED_LEDPORTD|=_BV(5)//PD5接紅色發(fā)光管
#defineCLR_RED_LEDPORTD&=~_BV(5)

#defineSET_GRN_LEDPORTD|=_BV(4)//PD4接綠色發(fā)光管
#defineCLR_GRN_LEDPORTD&=~_BV(4)

classCControl
{
publIC:
CControl();
public:
ucharm_bCounter;

voidDelayMs(uintms);
voidRunMotor(uchardirection);
};

CControl::CControl()
{
m_bCounter=0;

}

voidCControl::RunMotor(uchardirection)
{
if(direction==1)
{
SET_GRN_LED;
CLR_RED_LED;
}
elseif(direction==2)
{
CLR_GRN_LED;
SET_RED_LED;
}
else
{
CLR_GRN_LED;
CLR_RED_LED;
}

for(uchari=0;i{
while((PINB&_BV(0))==1);
while((PINB&_BV(0))==0);

if(direction==1)
{
PORTB|=_BV(PB3);
DelayMs(2);
PORTB&=~_BV(PB3);
}
elseif(direction==2)
{
PORTB|=_BV(PB2);
DelayMs(2);
PORTB&=~_BV(PB2);
}
else
PORTB=0;
}
}

voidCControl::DelayMs(uintms)
{
uintk=0;
for(k=0;k_delay_loop_2(1000);
}

CControlg_oMotorCtl;

intmain(void)
{
DDRD=_BV(4)|_BV(5);//發(fā)光管I/O初始化
PORTD=0X00;

PORTB=0;//控制口I/O初始化
DDRB=_BV(PB3)|_BV(PB2);

g_oMotorCtl.m_bCounter=200;

//SET_GRN_LED;

g_oMotorCtl.DelayMs(2000);

while(1)
{
g_oMotorCtl.RunMotor(1);
g_oMotorCtl.RunMotor(0);
g_oMotorCtl.RunMotor(2);
g_oMotorCtl.RunMotor(0);
}

}



本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉