?? main.c
字號(hào):
/*
交流電機(jī)測(cè)試程序
main.c
MCU:at90s2313
時(shí)鐘:4MHz
芯藝 2004-09-25
*/
#include <avr/io.h>
#include <avr/delay.h>
#define uchar unsigned char
#define uint unsigned int
#define SET_RED_LED PORTD|=_BV(5) //PD5接紅色發(fā)光管
#define CLR_RED_LED PORTD&=~_BV(5)
#define SET_GRN_LED PORTD|=_BV(4) //PD4接綠色發(fā)光管
#define CLR_GRN_LED PORTD&=~_BV(4)
class CControl
{
public:
CControl();
public:
uchar m_bCounter;
void DelayMs(uint ms);
void RunMotor(uchar direction);
};
CControl::CControl()
{
m_bCounter=0;
}
void CControl::RunMotor(uchar direction)
{
if(direction==1)
{
SET_GRN_LED;
CLR_RED_LED;
}
else if(direction==2)
{
CLR_GRN_LED;
SET_RED_LED;
}
else
{
CLR_GRN_LED;
CLR_RED_LED;
}
for(uchar i=0;i<m_bCounter;i++)
{
while((PINB&_BV(0))==1);
while((PINB&_BV(0))==0);
if(direction==1)
{
PORTB|=_BV(PB3);
DelayMs(2);
PORTB&=~_BV(PB3);
}
else if(direction==2)
{
PORTB|=_BV(PB2);
DelayMs(2);
PORTB&=~_BV(PB2);
}
else
PORTB=0;
}
}
void CControl::DelayMs(uint ms)
{
uint k=0;
for(k=0;k<ms;k++)
_delay_loop_2(1000);
}
CControl g_oMotorCtl;
int main(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);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -