📄 sl3010_4._c
字号:
/*******************************************/
/* 广州天河双龙电子公司 */
/* http://www.sl.com.cn */
/* 020-85510191,87578852,87578872 */
/* nikko@sl.com.cn */
/*******************************************/
//遥控器没有按键或者 pd3,pd2,pd1,pd0 短路块全部不接上,全为高电平
//机器人运行音乐机器人程序。
//PA口为音乐灯,当不同的音乐节奏,点亮不同的灯。
//声控起动音乐机器人程序,未起动时,PA口的8 LED 呈广告灯效果(霓虹灯)
//声控起动后,机器人开始演奏音乐,同时PA口LED灯根据音乐节拍闪烁
//按遥控器上不同的键后可改变机器人演奏的乐曲。
//将 pd0 接低电平,pd3,pd2,pd1 保持高电平,只连接pd0的短路块
// 或按下遥控器<A>(保持 0.5s) 进入遥控机器人运行环境
//声控起动遥控车程序,未起动时,PA口的8 LED 呈广告灯效果(霓虹灯)
//声控起动后,机器人开始动作
//遥控器无按键,机器人直行
//按住 < A > 键,机器人右转,同时演奏右转指示音乐;
//按住 < B > 键,机器人后退,同时演奏后退指示音乐;
//按住 < C > 键,机器人停止,同时演奏停止指示音乐;
//按住 < D > 键,机器人左转,同时演奏左转指示音乐;
//释放遥控器按键,音乐停止
//将 pd1 接低电平,pd3,pd2,pd0 保持高电平,只连接pd1的短路块
// 或按下遥控器<B>(保持 0.5s) 寻迹机器人,探测白底黑线,沿黑线行进
//声控起动寻迹机器人程序,未起动时,PA口的 8 LED 呈广告灯效果(霓虹灯)
//声控起动后,机器人开始动作,PA口的 8 LED 指示运动状态
//将 pd2 接低电平,pd3,pd1,pd0 保持高电平,只连接pd2的短路块
// 或按下遥控器<C>(保持 0.5s) 机器人避障碍、避悬崖行进
//声控起动避悬崖,壁障碍运行程序,未起动时,PA口的8 LED 呈广告灯效果(霓虹灯)
//声控起动后,机器人开始动作,PA口的 8 LED 指示运动状态
//探测到边缘,后退、转弯,并以伴有音乐提示。
//将 pd3 接低电平,pd2,pd1,pd0 保持高电平,只连接pd3的短路块
// 或按下遥控器<D>(保持 0.5s) 机器人按程序设定路线行走,走四方形,同时演奏音乐
//自走车 机器人走四方形路线,遥控器调节行走路线
//声控起动机器人按设定路线行走,未起动时,PA口的 8 LED 呈广告灯效果(霓虹灯)
//声控起动后,机器人开始动作,PA口的 8 LED 指示运动状态
//程序等待声控起动运行,未启动运行时机器人运行霓虹车程序。
//连续按住遥控器 < C > 键超过 10s 起动看门狗,再过 1s 系统复位
//将 sl3010.c 文件拷贝到 icc avr 安装目录的<include>文件夹
//sl3010.c 是sl3010机器人板的子函数库
//程序中调用此文件后 #include <sl3010.c>
//可直接调用里面的函数和变量
// 最后更新:2003.04.17
#include <io8515v.h>
#include <macros.h>
#include <sl3010.c>
#include <eeprom.h>
#define xuanya_delayms 300
#define cny_delayms 50
#define light_delay 100
/* 音乐数据 */
/* 四分之一拍为0x10, 二分之一拍为0x20, 一拍为0x40 */
/* 低1-1 2-2 3-3 4-4 5-5 6-6 7-7 */
/* 中1-8 2-9 3-A 4-B 5-C 6-D 7-E */
/* 高1-F */
#pragma data:eeprom
unsigned char sound[]={ //乐曲数据表
//情非得以
0x20,0x1c,0x1d,0x4c,0x4c,0x4c,0x4c,0x20,0x2d,0x19,0x1a,0x19,0x18,0x48,0x48,0x48,
0x48,0x47,0x47,0x46,0x46,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x45,
0x23,0x24,0x25,0x44,0x45,0x24,0x23,0x22,0x42,0x40,0x40,0x23,0x22,0x21,0x41,0x28,
0x48,0x23,0x25,0x45,0x40,0x40,0x21,0x21,0x42,0x21,0x21,0x41,0x20,0x28,0x47,0x26,
0x17,0x16,0x15,0x45,0x40,0x31,0x11,0x21,0x21,0x21,0x22,0x42,0x40,0x20,0x23,0x23,
0x24,0x25,0x24,0x23,0x24,0x25,0x26,0x23,0x23,0x42,0x42,0x40,0x23,0x22,0x21,0x41,
0x28,0x28,0x28,0x23,0x25,0x45,0x45,0x40,0x20,0x25,0x46,0x28,0x28,0x48,0x20,0x29,
0x47,0x26,0x17,0x16,0x15,0x45,0x25,0x25,0x26,0x28,0x18,0x16,0x26,0x28,0x26,0x28,
0x19,0x19,0x49,0x49,0x20,0x25,0x2a,0x18,0x19,0x29,0x28,0x16,0x17,0x16,0x15,0x25,
0x25,0x28,0x29,0x2a,0x29,0x48,0x28,0x48,0x2c,0x4c,0x4c,0x40,0x2a,0x2c,0x1c,0x1a,
0x2a,0x2a,0x29,0x4a,0x2b,0x2a,0x4a,0x4a,0x40,0x2a,0x29,0x29,0x28,0x28,0x26,0x48,
0x29,0x26,0x45,0x45,0x40,0x25,0x25,0x26,0x21,0x18,0x16,0x26,0x28,0x26,0x28,0x29,
0x49,0x49,0x20,0x25,0x28,0x29,0x2a,0x29,0x49,0x28,0x48,0x2c,0x4c,0x4c,0x40,0x2a,
0x2c,0x15,0x1a,0x2a,0x2a,0x29,0x4a,0x2b,0x2a,0x4a,0x4a,0x40,0x2a,0x29,0x29,0x28,
0x28,0x26,0x28,0x28,0x29,0x26,0x45,0x45,0x40,0x25,0x25,0x26,0x28,0x28,0x26,0x2a,
0x19,0x18,0x28,0x18,0x19,0x48,0x48,0x40,0x40,0x40,0x40,0x28,0x48,0x29,0x28,0x28,
0x2a,0x1a,0x1a,0x1a,0x18,0x40,0x20,0x26,0x28,0x28,0x28,0x26,0x28,0x48,0x26,0x25,
0x45,0x45,0x40,0x40,0x40,0x28,0x48,0x28,0x28,0x1c,0x1d,0x2d,0x2c,0x28,0x28,0x28,
0x20,0x26,0x19,0x1a,0x29,0x19,0x18,0x28,0x28,0x26,0x21,0x29,0x49,0x49,0x40,0x20,
0x28,0x29,0x2a,0x4a,0x4a,0x20,0x25,0x28,0x29,0x48,0x48,0x48,0x25,0x25,0x26,0x28,
0x28,0x26,0x2a,0x19,0x18,0x28,0x18,0x19,0x49,0x49,0x40,0x40,
0x00,0x00
};
#pragma data:data
/* 音阶表 */
const unsigned int TONETABLE[15]={DO,RE,MI,FA,SO,LA,TI,DO_H,
RE_H,MI_H,FA_H,SO_H,LA_H,TI_H,DO_HH};
/* 音阶重装常数 */
unsigned int toneconst;
unsigned int sound_add=0;
unsigned int rst_time,delay_time1,delay_time2,led_delayms=600;
unsigned char temp,temp1;
unsigned char pa,pb,pc,pd,remote_in,timers,cny_in,cny_times,cds,pd_select,remote_select;
unsigned char gzsl,t0_times;
unsigned char sound_1,sound_2;
const unsigned char led_data[]=
{//设置LED广告灯数据表
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,
0x00,0x18,0x3c,0x7e,0xff,0x7e,0x3c,0x18,
0x00,0x18,0x3c,0x7e,0xff,0x7e,0x3c,0x18,
0xf8,0xf1,0xe3,0xc7,0x8f,0x1f,0x8f,0xc7,0xe3,0xf1,
0xf8,0xf1,0xe3,0xc7,0x8f,0x1f,0x8f,0xc7,0xe3,0xf1,
0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,
0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,
0xff,0xe7,0xdb,0xbd,0x7e,0xbd,0xdb,0xe7,
0xff,0xe7,0xdb,0xbd,0x7e,0xbd,0xdb,0xe7,
0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,
0x0a,0x0a
};
const unsigned char music_11[]=
{//七子之歌
0x45,0x23,0x25,0x23,0x65,0x26,0x25,0x23,0x26,0x45,0x45,0x41,
0x21,0x22,0x43,0x25,0x23,0x42,0x20,0x23,0x45,0x45,0x25,0x25,
0x26,0x25,0x23,0x45,0x25,0x26,0x25,0x28,0x26,0x45,0x45,0x41,
0x25,0x23,0x22,0x21,0x42,0x23,0x65,0x25,0x22,0x43,0x41,0x41,
0x41,0x41,0x45,0x23,0x25,0x23,0x65,0x26,0x25,0x23,0x26,0x45,
0x45,0x41,0x21,0x22,0x43,0x25,0x23,0x42,0x20,0x23,0x45,0x45,
0x25,0x25,0x26,0x25,0x23,0x45,0x25,0x26,0x25,0x28,0x26,0x45,
0x45,0x41,0x25,0x23,0x22,0x21,0x42,0x23,0x65,0x25,0x22,0x43,
0x41,0x41,0x41,0x20,0x25,0x4a,0x29,0x28,0x26,0x25,0x45,0x26,
0x46,0x25,0x36,0x18,0x2a,0x28,0x49,0x49,0x49,0x20,0x25,0x4a,
0x39,0x18,0x26,0x25,0x45,0x26,0x46,0x25,0x46,0x2a,0x29,0x49,
0x49,0x49,0x49,0x4a,0x39,0x18,0x26,0x25,0x45,0x48,0x26,0x25,
0x23,0x22,0x41,0x40,0x22,0x23,0x45,0x45,0x45,0x45,0x40,0x25,
0x26,0x48,0x48,0x48,
0x00,0x00
};
const unsigned char music_22[]=
{//走进新时代
0x68,0x26,0x25,0x23,0x22,0x13,0x12,0x41,0x41,0x41,0x23,0x25,
0x28,0x48,0x28,0x29,0x2a,0x29,0x26,0x45,0x45,0x45,0x45,0x68,
0x29,0x29,0x28,0x26,0x25,0x46,0x46,0x46,0x25,0x26,
0x29,0x43,0x25,0x22,0x23,0x22,0x21,0x42,0x42,0x42,0x42,0x63,
0x25,0x26,0x25,0x26,0x25,0x23,0x22,0x13,0x12,0x41,0x23,0x25,
0x28,0x28,0x28,0x28,0x29,0x2a,0x2a,0x29,0x46,0x46,0x46,0x46,
0x46,0x29,0x2a,0x28,0x28,0x26,0x25,0x26,0x26,0x25,0x43,0x43,
0x22,0x42,0x26,0x25,0x23,0x22,0x13,0x12,0x41,0x41,0x41,0x41,
0x00,0x00
};
const unsigned char music_33[]=
{
//星语心愿
0x36,0x18,0x27,0x26,0x25,0x26,0x43,0x43,0x43,0x26,0x25,0x36,0x18,0x27,0x18,0x17,
0x26,0x27,0x48,0x48,0x48,0x28,0x29,0x2a,0x2a,0x2a,0x2a,0x49,0x49,0x28,0x27,0x26,
0x27,0x45,0x45,0x46,0x48,0x47,0x26,0x25,0x46,0x46,0x46,0x40,0x40,0x40,0x40,0x40,
0x36,0x18,0x27,0x26,0x25,0x26,0x26,0x26,0x46,0x46,0x26,0x25,0x36,0x18,0x27,0x18,
0x17,0x26,0x27,0x48,0x48,0x48,0x28,0x29,0x2a,0x2a,0x2a,0x2a,0x49,0x49,0x28,0x27,
0x26,0x27,0x45,0x45,0x46,0x26,0x28,0x47,0x45,0x40,0x26,0x28,0x47,0x45,0x46,0x46,
0x46,0x46,0x46,0x46,0x46,0x23,0x25,0x46,0x4a,0x39,0x18,0x27,0x28,0x48,0x48,0x48,
0x28,0x27,0x36,0x16,0x45,0x47,0x46,0x46,0x46,0x23,0x25,0x46,0x4a,0x39,0x18,0x27,
0x28,0x48,0x48,0x28,0x27,0x36,0x16,0x45,0x27,0x26,0x46,0x46,0x46,0x46,0x46,0x46,
0x00,0x00
};
const unsigned char music_44[]=
{
//上海滩
0x2a,0x2c,0x4d,0x4d,0x4d,0x2a,0x2c,0x49,0x49,0x49,0x2a,0x2c,
0x2d,0x4f,0x2d,0x4c,0x1d,0x18,0x2a,0x49,0x49,0x49,0x29,0x2a,
0x4c,0x4c,0x4c,0x29,0x2a,0x29,0x26,0x4d,0x4d,0x4d,0x26,0x28,
0x39,0x1a,0x29,0x27,0x26,0x28,0x45,0x45,0x45,0x2a,0x2c,0x4d,
0x4d,0x4d,0x2a,0x2c,0x49,0x49,0x49,0x2a,0x2c,0x2d,0x4f,0x2d,
0x4c,0x1d,0x18,0x2a,0x49,0x49,0x49,0x29,0x2a,0x4c,0x4c,0x4c,
0x29,0x2a,0x29,0x26,0x4d,0x4d,0x4d,0x26,0x28,0x39,0x1a,0x29,
0x27,0x26,0x25,0x48,0x48,0x20,0x2f,0x2f,0x2d,0x4f,0x4f,0x20,
0x2d,0x2f,0x2d,0x4c,0x4c,0x4c,0x2c,0x2a,0x6d,0x2c,0x48,0x19,
0x18,0x28,0x4a,0x4a,0x20,0x2a,0x2a,0x29,0x4a,0x4a,0x20,0x2f,
0x2f,0x2e,0x4d,0x4d,0x4d,0x2a,0x2a,0x69,0x2a,0x2f,0x2e,0x2d,
0x2a,0x4c,0x4c,0x4c,
0x00,0x00
};
const unsigned char sound_none[]={0x28,0x27,0x36,0x16,0x45,0x47,0x46,0x46,0x46,0x23,0x25,0x46,0x4a,0x39,0x18,0x27,
0x28,0x48,0x48,0x28,0x27,0x36,0x16,0x45,0x27,0x26,0x46,0x46,0x46,0x46,0x46,0x46,0x00,0x00};
const unsigned char sound_right[]={0x23,0x25,0x46,0x4a,0x39,0x18,0x27,0x28,0x48,0x48,0x48,
0x28,0x27,0x36,0x16,0x45,0x47,0x46,0x46,0x46,0x00,0x00};
const unsigned char sound_back[]={0x2a,0x2c,0x4d,0x4d,0x4d,0x2a,0x2c,0x49,0x49,0x49,0x2a,0x2c,0x2d,0x4f,
0x2d,0x4c,0x1d,0x18,0x2a,0x49,0x49,0x49,0x00,0x00};
const unsigned char sound_stop[]={0x23,0x24,0x25,0x44,0x45,0x24,0x23,0x22,0x42,0x40,0x40,0x23,0x22,0x21,0x41,0x28,
0x48,0x23,0x25,0x45,0x40,0x40,0x00,0x00};
const unsigned char sound_left[]={0x68,0x26,0x25,0x23,0x22,0x13,0x12,0x41,0x41,0x41,0x23,0x25,
0x28,0x48,0x28,0x29,0x2a,0x29,0x26,0x45,0x45,0x45,0x00,0x00};
//Watchdog initialisation
// prescale: 1024K cycles
void watchdog_init(void)
{
WDR(); //this prevents a timout on enabling
WDTCR = 0x0E; //WATCHDOG ENABLED - dont forget WDR
}
//TIMER0 initialisation - prescale:1024
// desired value: 25mSec
// actual value: 24.960mSec (0.2%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop timer
TCNT0 = 0x3D; //set count value
TCCR0 = 0x05; //start timer
}
#pragma interrupt_handler timer0_ovf_isr:iv_TIMER0_OVF
void timer0_ovf_isr(void)
{
TCNT0 = 0x3D; //reload counter value
t0_times++;
remote_in = PINB & 0x0F;
switch (remote_in)
{//检测遥控器是否有键按下
case 0x00: // none
rst_time=0;
break;
case 0x04: // < A >
rst_time=0;
break;
case 0x02: // < B >
rst_time=0;
break;
case 0x08: // < C >
rst_time++;
break;
case 0x01: // < D >
rst_time=0;
break;
}
if(rst_time > 400) // 400*25ms=10s,+1s 看门狗复位
{
PORTA = 0xff;
watchdog_init();
while(1);
}
if(gzsl == 0x88)
{
if(t0_times == 10)
{
timers++;
t0_times = 0;
pa = led_data[timers];
if(pa==0x0a){timers=0;}
PORTA = pa;
}
}
if(gzsl == 0x33)
{
sw_touch();
if(t0_times == 8) //8*25ms=200ms
{
t0_times = 0;
remote_in = PINB & 0x0F;
sound_1 = remote_in;
if(sound_2 != sound_1)
{sound_add=0;sound_2 = sound_1;}
switch (remote_in)
{//检测遥控器是否有键按下
case 0x00:
forward(); //前行
sound_add=0x00;
temp1=0x00;
break;
case 0x04: // < A >
turn_right(); //右转
temp1=sound_right[sound_add];
break;
case 0x02: // < B >
backward(); //后退
temp1=sound_back[sound_add];
break;
case 0x08: // < C >
stop(); //停止运动
temp1=sound_stop[sound_add];
break;
case 0x01: // < D >
turn_left(); //左转
temp1=sound_left[sound_add];
break;
}
}
}
if(gzsl == 0x11)
{
if(t0_times == delay_time1) //delay_time1*25ms
{
t0_times = 0;
gzsl = 0x22;
forward();
}
}
if(gzsl == 0x22)
{
if(t0_times == delay_time2) //delay_time2*25ms
{
t0_times = 0;
gzsl = 0x11;
turn_right();
}
}
if(gzsl == 0x44)
{
sw_touch();
pc = PINC & 0xE0;
if(pc == 0xE0)
{
stop();
t0_times = 0;timers = 0x22;
temp1=EEPROMread((int)&sound[sound_add]);
}
if(pc == 0x40 || pc == 0x80 || pc == 0x20 || pc == 0xc0 || pc == 0x60)
{
timers=0x55;
t0_times = 0;
}
if(timers == 0x55)
{
if(t0_times < 16) //16*25ms=400ms
{
backward();
temp1=sound_back[sound_add];
}
if(t0_times > 16 && t0_times < 24) //8*25ms=200ms
{
turn_left();
temp1=sound_back[sound_add];
}
if(t0_times == 24)
{
timers = 0;
t0_times = 0;
}
}
if(timers != 0x55 && timers != 0x22)
{
forward();
temp1 = 0;
}
}
if(gzsl == 0x55)
{
if(t0_times == 4) //4*25ms=100ms 扫描一次
{
t0_times = 0;
remote_in = PINB & 0x0F;
switch (remote_in)
{//检测遥控器是否有键按下
case 0x04: // < A >
sound_add=0;
sound_1 = 0x11;
break;
case 0x02: // < B >
sound_add=0;
sound_1 = 0x22;
break;
case 0x08: // < C >
sound_add=0;
sound_1 = 0x33;
break;
case 0x01: // < D >
sound_add=0;
sound_1 = 0x44;
break;
}
if(sound_1 == 0x11)
{
temp1 = music_11[sound_add];
}
if(sound_1 == 0x22)
{
temp1 = music_22[sound_add];
}
if(sound_1 == 0x33)
{
temp1 = music_33[sound_add];
}
if(sound_1 == 0x44)
{
temp1 = music_44[sound_add];
}
if(sound_1 == 0x88)
{
// temp1=EEPROMread((int)&sound[sound_add]);
temp1 = music_22[sound_add];
}
}
}
}
void stop_timer0()
{
CLI();
TCCR0 = 0x00;//停止timer0
MCUCR = 0x00;
GIMSK = 0x00;
TIMSK = 0x00;
SEI();
}
/*******************************************/
/* 电子音乐演示程序 */
/*******************************************/
//使用说明:音乐输出端口:PORTC.0,音乐数据存放
//于AT90S8515 的EEPROM存贮器中。
// 可以用并口下载软件写入新的音乐文件
//声控起动音乐机器人程序,未起动时,PA口的8 LED 呈广告灯效果(霓虹灯)
//声控起动后,机器人开始演奏音乐
//按遥控器上不同的键后可改变机器人演奏的乐曲。
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -