?? diy0206_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 保持高電平
// 或按下遙控器<A>(保持 0.5s) 進入遙控機器人運行環境
//聲控起動遙控車程序,未起動時,PA口的8 LED 呈廣告燈效果(霓虹燈)
//聲控起動后,機器人開始動作
//遙控器無按鍵,機器人直行
//按住 < A > 鍵,機器人右轉,同時演奏右轉指示音樂;
//按住 < B > 鍵,機器人后退,同時演奏后退指示音樂;
//按住 < C > 鍵,機器人停止,同時演奏停止指示音樂;
//按住 < D > 鍵,機器人左轉,同時演奏左轉指示音樂;
//釋放遙控器按鍵,音樂停止
//將 pd1 接低電平,pd3,pd2,pd0 保持高電平
// 或按下遙控器<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 保持高電平
// 或按下遙控器<D>(保持 0.5s) 機器人按程序設定路線行走,走四方形,同時演奏音樂
//自走車 機器人走四方形路線,遙控器調節行走路線
//聲控起動機器人按設定路線行走,未起動時,PA口的 8 LED 呈廣告燈效果(霓虹燈)
//聲控起動后,機器人開始動作,PA口的 8 LED 指示運動狀態
//程序等待聲控起動運行,未啟動運行時機器人運行霓虹車程序。
//連續按住遙控器 < C > 鍵超過 10s 起動看門狗,再過 1s 系統復位
//將 diy0206.c 文件拷貝到 icc avr 安裝目錄的<include>文件夾
//diy0206.c 是diy0206機器人板的子函數庫
//程序中調用此文件后 #include <diy0206.c>
//可直接調用里面的函數和變量
// 最后更新:2003.04.17
#include <io8515v.h>
#include <macros.h>
#include <diy0206.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 & 0xF0;
switch (remote_in)
{//檢測遙控器是否有鍵按下
case 0x00: // none
rst_time=0;
break;
case 0x20: // < A >
rst_time=0;
break;
case 0x40: // < B >
rst_time=0;
break;
case 0x10: // < C >
rst_time++;
break;
case 0x80: // < D >
rst_time=0;
break;
}
if(rst_time > 400) // 400*25ms=10s,+1s 看門狗復位
{
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 & 0xF0;
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 0x20: // < A >
turn_right(); //右轉
temp1=sound_right[sound_add];
break;
case 0x40: // < B >
backward(); //后退
temp1=sound_back[sound_add];
break;
case 0x10: // < C >
stop(); //停止運動
temp1=sound_stop[sound_add];
break;
case 0x80: // < 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 & 0xF0;
switch (remote_in)
{//檢測遙控器是否有鍵按下
case 0x20: // < A >
sound_add=0;
sound_1 = 0x11;
break;
case 0x40: // < B >
sound_add=0;
sound_1 = 0x22;
break;
case 0x10: // < C >
sound_add=0;
sound_1 = 0x33;
break;
case 0x80: // < 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]);
}
}
}
}
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 + -