公告:
精彩视频
348826281 元老 Fans 发消息
发表于 11-3-31 18:07:53 |显示全部楼层 来自: 中国陕西
本帖最后由 348826281 于 11-4-3 18:12 编辑

试验版本,用电位器控制,以后要改成舵机信号控制。

用了ATmega8L、电阻、电容各一个,以后还要加功放。

原理:由ADC控制T/C0产生中断的速度,用T/C0给T/C1喂数据,用T/C1的PWM产生声音,反复播放一段声音(来自网游“飚车”的rpm.wav)。

还需要改进,希望能接近“极品飞车”的水平



348826281 元老 Fans 发消息
发表于 11-3-31 18:10:08 |显示全部楼层 来自: 中国陕西
本帖最后由 348826281 于 11-3-31 18:14 编辑

原代码


//ICC-AVR application builder
// Target : M8
// Crystal: 8.0000Mhz
#include
#include
#include
#include
int n;
unsigned int adc,tc0no;

//一段声音
__flash char sound[373]={0x89,0x96,0x95,0x94,0xA2,0xB3,0xBE,0xC6,0xC5,0xC2,0xC5,0xD8,
0xE5,0xE5,0xE7,0xE3,0xDE,0xE0,0xDF,0xDF,0xDA,0xDB,0xDC,0xDA,0xD5,0xD4,0xD3,0xD4,
0xD8,0xD4,0xD0,0xCE,0xCC,0xCF,0xD0,0xCC,0xB9,0xA8,0x9D,0x88,0x7B,0x70,0x5F,0x53,
0x50,0x4D,0x48,0x3F,0x47,0x60,0x69,0x60,0x56,0x44,0x41,0x4E,0x51,0x4D,0x4A,0x51,
0x56,0x49,0x46,0x44,0x44,0x4F,0x59,0x59,0x66,0x72,0x76,0x75,0x83,0x90,0x98,0xA2,
0xAD,0xB6,0xBB,0xB8,0xB8,0xBC,0xC0,0xC4,0xC2,0xBF,0xC1,0xD0,0xD2,0xCB,0xC6,0xCD,
0xCE,0xCB,0xC2,0xC2,0xC1,0xBB,0xAB,0xB0,0xB7,0xB9,0xA4,0xA4,0xB0,0xAC,0xAB,0xB2,
0xA7,0x9A,0x86,0x71,0x6A,0x6D,0x5A,0x41,0x34,0x31,0x25,0x11,0x08,0x06,0x08,0x0D,
0x11,0x14,0x16,0x12,0x13,0x13,0x1E,0x2F,0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E,0x20,0x1E,0x30,0x3F,0x3D,0x3D,0x4D,0x52,0x4A,0x4A,0x4C,0x44,
0x49,0x53,0x52,0x52,0x5C,0x68,0x6E,0x75,0x80};

//根据电位器的数值调整播放速度
__flash char tc0start[33]={0x82,0x87,0x8C,0x91,0x95,0x99,0x9D,0xA0,0xA4,0xA7,
0xA9,0xAC,0xAF,0xB1,0xB3,0xB5,0xB7,0xB9,0xBB,0xBC,0xBE,0xC0,0xC1,0xC2,0xC4,
0xC5,0xC6,0xC7,0xC8,0xCA,0xCB,0xCC,0xCD};

void port_init(void)
{
PORTB = 0x00;
DDRB  = 0x02; //PB1 --> OC1A  output
PORTC = 0x00; //m103 output only
DDRC  = 0x00; // PC.0 ADC
PORTD = 0x00;
DDRD  = 0x00;
}
//ADC initialize
void adc_init(void)
{
ADCSR = 0x00; //disable adc
ADMUX = 0x40; //AVcc ADC0 0100 0000
ACSR  = 0x80; //analogy comparer 1000 0000
ADCSR = 0xEF; //1110 1111  self trigger
}
#pragma interrupt_handler adc_isr:iv_ADC
void adc_isr(void)
{
adc=(unsigned int)ADCL;            //Read 8 low bits first (important)
adc|=((unsigned int)ADCH << 8); //read 2 high bits and shift into top byte
tc0no=(adc>>5);
}

//TIMER0 initialize - prescale:8
void timer0_init(void)
{
TCCR0 = 0x00; //stop
TCNT0 = 0x82; //set count
TCCR0 = 0x02; //start timer
}

#pragma interrupt_handler timer0_ovf_isr:iv_TIM0_OVF
void timer0_ovf_isr(void)
{
TCNT0 = tc0start[tc0no]; //播放速度
    OCR1AH =0x00;
    OCR1AL = sound[n];
    n++;    //声音循环播放
     if (n-372>0)
    {
     n=0;
    }
}
//TIMER1 initialize - prescale:1
// WGM: 5) PWM fast, TOP=0xFF
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xFF; //setup
TCNT1L = 0x01;
OCR1AH = 0x00;
OCR1AL = 0x80;
OCR1BH = 0x00;
OCR1BL = 0x80;
ICR1H  = 0x00;
ICR1L  = 0xFF;
TCCR1A = 0xA1; //1010 0010
TCCR1B = 0x09; //start Timer  0000 1001
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
adc_init();
timer0_init();
timer1_init();
  
MCUCR = 0x00;
GICR  = 0x00;
TIMSK = 0x01; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void main(void)
{
    n=0;tc0no=0;
init_devices();

while (1)
{
} //while(1)
} //main



有不对的地方请指出,我也是初学者,见笑了
TURBOdrive 论坛元老 发消息
发表于 11-3-31 18:54:08 |显示全部楼层 来自: 中国黑龙江哈尔滨
有创意啊!厉害!我原来也有过这想法,但是这方面懂的太少,最终没能实现……
pt32503 超级元老 发消息
发表于 11-3-31 19:04:44 |显示全部楼层 来自: 中国广东江门
见过高手,但是没见过响LZ一样强的!强烈期待成品!!不过音源能否选择个更狠点的就好了。
無雙 超级元老 发消息
发表于 11-3-31 19:05:13 |显示全部楼层 来自: 中国广东广州
希望楼主早日搞出来啊````俺为什么没玩电车就是因为太安静了``给人是感觉就象是在玩玩具``有人用发声管做模似声``看到日本人做了一个网上有视频感觉也8错```我早上看到有老人健身玩的那种带风鸣的东西``应当可以加装在车上如果电机带动`转的越快声也越大`速度慢下来声音也变小`不知道可不可以用这东西来模似````如果有电子模似的就更放便了。。哈哈。。

点评

林四海  中间劈叉大了点吧  发表于 11-8-9 19:51
foresty  我来看你这大腿的 真有感觉  发表于 11-3-31 19:50
714413695 长老 Fans 发消息
发表于 11-3-31 19:43:24 |显示全部楼层 来自: 中国四川内江
这个才是极品,望楼主能搞出NB的排气声音
xtt7214753 终极 Fans 发消息
发表于 11-3-31 19:57:29 |显示全部楼层 来自: 中国江苏扬州
这个我想过,还有一种方案给楼主考虑考虑
用ISD语音芯片录好声音,单片机控制播放
foresty 金牌 Fans 发消息
发表于 11-3-31 19:59:54 |显示全部楼层 来自: 中国北京
真是NB的东西....支持啊
x3440 长老 Fans 发消息
发表于 11-3-31 20:11:34 |显示全部楼层 来自: 中国广东中山
支持量产~~~
gzhuangh 高级 Fans 发消息
发表于 11-3-31 21:45:20 |显示全部楼层 来自: 中国广东深圳
强啊,支持!
您需要登录后才可以回帖 登录 | 注册

广告投放|联系我们|手机|投稿|Archiver|About us|Advertise|遥控迷模型网|RCFans ( 粤ICP备10210518号-1 )

版权所有 RCFans.com © 2003-2016

返回顶部