📄 trace-light.c
字号:
/**********************************************************/
/* 广州天河双龙电子公司
http://www.sl.com.cn
PC.1检测右光敏电阻
PC.2检测左光敏电阻
功能:
追光程序,小车追着光走。
Chip type : ATMEGA16
Clock frequency : 8MHz
*/
/**********************************************************/
#include <iom16v.h>
#include <macros.h>
#include <diy0206.c> //调用sldiy0206机器人的子函数库
#define light_delay 100
unsigned char cds;
void trace_light()
{
port_init(); //PA,PB,PC,PD 初始化
work_status = 0x70; //置对应的工作状态标志
mic_startup(); //等待声控启动
while(1)
{
sw_touch(); //检测轻触开关
cds = PINC & 0x06; //0b0000,0110
if(cds == 0x00) //左右两侧都感测到光
{//直行
forward();
delay_ms(light_delay); //延时
}
if(cds == 0x02) //0b0000,0010___pc2(右侧)感测到光
{//慢速右转
turn_right_s();
delay_ms(light_delay); //延时
}
if(cds == 0x04) //0b0000,0100___pc1(左侧)感测到光
{//慢速左转
turn_left_s();
delay_ms(light_delay); //延时
}
if(cds == 0x06)
{//停止动作
PORTA = 0x55; //延时后停止动作,等待光照重新动作
delay_ms(light_delay*2);
stop();
}
}
}
void main()
{
trace_light();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -