protect.c
来自「智能小车的往返行驶,单片机实现,使用红外信号进行路面信号的采集」· C语言 代码 · 共 61 行
C
61 行
#include "SPCE061V004.h"
#define FORWARD 0 //前进状态
#define BACKWARD 1 //后退状态
#define STOP 2 //停止状态
#define BLACKWIRE_H 7
typedef unsigned int uint;
extern uint SpeedValue; //档位值,从1-100
extern uint Status; //记录和控制车前进,后退状态
extern uint Blackwire; //记录黑线数
extern uint S; //总路程,单位:厘米
extern uint Time; //总时间
extern uint key_array[8];
extern uint led[8];
void LEDdisplay( unsigned char , unsigned char );
unsigned char PointCTL(unsigned char );
void delay(uint );
void FaceBlackWire();
void Speed(uint speedvalue);
void ForeWheelForword();
void ForeWheelReverse();
void TurnLeft();
void TurnRight();
void Stop();
void Adjust();
void NoMoveProtect();
uint t_buf_protect=0;
uint s_buf_protect=0;
uint times_protect=0;
void Protect()
{
if(times_protect==0)
{
s_buf_protect=S;
t_buf_protect=Time;
times_protect=0x0f;
}
else if(t_buf_protect!=Time)
{
if ( (S-s_buf_protect)<8)
{NoMoveProtect();t_buf_protect=Time;s_buf_protect=S;}
else { s_buf_protect=S;t_buf_protect=Time;}
}
}
void NoMoveProtect()
{
if(Status== FORWARD )
{
ForeWheelReverse();
delay(0x45);
TurnLeft();
ForeWheelForword();
}
else if(Status== BACKWARD )
{
ForeWheelForword();
delay(0x45);
TurnRight();
ForeWheelReverse();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?