|
发表于 2010-7-25 17:56:19
|
显示全部楼层
目前在做通过mega16的spi端口播放isd1790芯片中的声音...isd1790语音模块没有问题...可是连最最基本的放音功能都实现不了...
求高手帮忙啊,拜托了~~~程序如下(目前只需要通过spi使得isd1790放音即可),下载程序一点反应都没有,急!>.<
//ICC-AVR application builder : 2010/7/23 16:52:06
// Target : M16
// Crystal: 4.0000Mhz
#include <iom16v.h>
#include <macros.h>
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
//SPI initialize
// clock rate: 1000000hz
void spi_init(void)
{
SPCR = 0x78; //setup SPI
SPSR = 0x00; //setup SPI
PORTB |= (1<<PB4) | (1<<PB5) | (1<<PB6) | (1<<PB7);
DDRB |= (1<<DDB5) | (1<<DDB7) | (1<<DDB4);
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
spi_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void SPI_MasterTransmit(char cData)
{
PORTB &=~ (1<<PB4); //强制接收方进入从模式
SPCR |= (1<<MSTR); // MSTR有时会被清零,这里强制进入主机模式
/* 启动数据传输 */
SPDR = cData;
/* 等待传输结束 */
while(!(SPSR & (1<<SPIF)))
;
PORTB |= (1<<PB4);
}
void Delay(void) //延时,没有详细计算
{
unsigned int i,j;
for(i=1000;i>0;i--)
{
for(j=200;j>0;j--)
;
}
}
void main(void)
{
unsigned char i=0;
init_devices();
while(1)
{
//SPI_MasterTransmit(0x01);
//SPI_MasterTransmit(0x00);
SPI_MasterTransmit(0x40);
//Delay();Delay();Delay();Delay();
SPI_MasterTransmit(0x00);
//Delay();Delay();Delay();Delay();
}
} |
|