?? car.c
字號:
//============================================================
// 犀拓開發網 http://www.mcutop.com
//
// 文件名稱:car.c
// 實現功能:小車驅動
// 日期: 2009年3月2日
//============================================================
#include "avr/io.h"
#include "util/delay.h"
void car_init(void)
{
DDRD |= _BV(PD2) | _BV(PD3) | _BV(PD4) | _BV(PD5);
}
void car_stop(void) // 剎車
{
PORTD |= _BV(PD2) | _BV(PD3) | _BV(PD4) | _BV(PD5);
}
void car_ahead(void) // 前進
{
PORTD &= ~(_BV(PD2) | _BV(PD3) | _BV(PD4) | _BV(PD5));
_delay_ms(5);
PORTD |= _BV(PD2) | _BV(PD4);
}
void car_backward(void) // 后退
{
PORTD &= ~(_BV(PD2) | _BV(PD3) | _BV(PD4) | _BV(PD5));
_delay_ms(5);
PORTD |= _BV(PD3) | _BV(PD5);
}
void car_left_Circle(void) // 原地左轉
{
PORTD &= ~(_BV(PD2) | _BV(PD3) | _BV(PD4) | _BV(PD5));
_delay_ms(5);
PORTD |= _BV(PD3) | _BV(PD4);
}
void car_right_Circle(void) // 原地右轉
{
PORTD &= ~(_BV(PD2) | _BV(PD3) | _BV(PD4) | _BV(PD5));
_delay_ms(5);
PORTD |= _BV(PD2) | _BV(PD5);
}
void car_left_stop(void) // 左轉,左輪不動
{
PORTD &= ~(_BV(PD2) | _BV(PD3) | _BV(PD4) | _BV(PD5));
_delay_ms(5);
PORTD |= _BV(PD2) | _BV(PD3) | _BV(PD4);
}
void car_right_stop(void) // 右轉,右輪不動
{
PORTD &= ~(_BV(PD2) | _BV(PD3) | _BV(PD4) | _BV(PD5));
_delay_ms(5);
PORTD |= _BV(PD2) | _BV(PD4) | _BV(PD5);
}
void car_left(void) // 左轉
{
PORTD &= ~(_BV(PD2) | _BV(PD3) | _BV(PD4) | _BV(PD5));
_delay_ms(5);
PORTD |= _BV(PD4);
}
void car_right(void) // 右轉
{
PORTD &= ~(_BV(PD2) | _BV(PD3) | _BV(PD4) | _BV(PD5));
_delay_ms(5);
PORTD |= _BV(PD2);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -