?? trace_light.c
字號:
//追光機器人
#include <io8515v.h>
#include <macros.h>
#include <sl3010.c> //調用sl3010小車的子函數庫
#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 + -