📄 remote_light.c
字号:
//追光机器人 和 遥控机器人程序
//将 pd0 接低电平,pd3,pd2,pd1 保持高电平
// 或按下遥控器<A>(保持 0.5s) 进入遥控机器人运行环境
//将 pd1 接低电平,pd3,pd2,pd0 保持高电平
// 或按下遥控器<B>(保持 0.5s) 进入追光机器人运行环境
//将 sl3010.c 文件拷贝到 icc avr 安装目录的<include>文件夹
//sl3010.c 是sl3010机器人的子函数库
//程序中调用此文件后 #include <sl3010.c>
//可直接调用里面的函数和变量
/*
void port_init(); //PA,PB,PC,PD 初始化
void delay_us(int time); //微妙级延时
void delay_ms(unsigned int time);//毫秒级延时
void sw_touch(); //检测轻触开关
void mic_startup(); //等待声控启动
void remote_auto_time(); //遥控器控制直行和转弯时间
void turn_right(); //右转
void turn_left(); //左转
void turn_right_s(); //慢速右转
void turn_left_s(); //慢速左转
void backward(); //后退
void forward(); //前行
void stop(); //停止运动
*/
//更新日期 2003.03.17
#include <io8515v.h>
#include <macros.h>
#include <sl3010.c> //调用sl3010小车的子函数库
#define light_delay 100
unsigned char cds;
void remote_car()
{//遥控车程序
unsigned char remote_in,led,timers;
led = 0x00;
for(timers=0;timers<7;timers++)
{//8 LED 整体亮灭闪烁
PORTA = led;
delay_ms(500);
led = ~led;
}
work_status = 0x60;//置对应的工作状态标志
mic_startup();//等待声控启动函数
while(1)
{
sw_touch();//检测轻触开关
remote_in = PINB & 0x0F;
switch (remote_in)
{//检测遥控器是否有键按下
case 0x04: // < A >
turn_right(); //右转
break;
case 0x02: // < B >
backward(); //后退
break;
case 0x08: // < C >
stop(); //停止运动
break;
case 0x01: // < D >
turn_left(); //左转
break;
case 0x00:
forward(); //前行
break;
}
delay_ms(100);
}
}
void trace_light()
{
unsigned char cds,led,timers;
led = 0xc3;
for(timers=0;timers<9;timers++)
{//8 LED 整体亮灭闪烁
PORTA = led;
delay_ms(500);
led = ~led;
}
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()
{
unsigned char pd_select,remote_select;
port_init(); //PA,PB,PC,PD 初始化
work_status = 0x67; //置对应的工作状态标志
PORTA = 0x7e;
while(1)
{
pd_select = PIND & 0x0f;
if(pd_select == 0x0e)//pd0=0,其它为高电平
{
while(1)
{
delay_ms(500);//消除抖动
pd_select = PIND & 0x0f;
if(pd_select == 0x0e)//pd0=0,其它为高电平
{remote_car();}//运行遥控车程序
else
break;
}
}
if(pd_select == 0x0d)//pd1=0,其它为高电平
{
while(1)
{
delay_ms(500);//消除抖动
pd_select = PIND & 0x0f;
if(pd_select == 0x0d)//pd1=0,其它为高电平
{trace_light();}//运行遥控车程序
else
break;
}
}
remote_select = PINB & 0x0f;//检测遥控器是否有键按下
if(remote_select == 0x04)// A
{
while(1)
{
delay_ms(500);//消除抖动
remote_select = PINB & 0x0f;
if(remote_select == 0x04)// A
{remote_car();}//运行遥控车程序
else
break;
}
}
if(remote_select == 0x02)// B
{
while(1)
{
delay_ms(500);//消除抖动
remote_select = PINB & 0x0f;
if(remote_select == 0x02)// B
{trace_light();}//运行追光机器人程序
else
break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -