📄 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 + -