|
lpc2103操作vs1003正弦测试不正常,大家帮我看看程序是不是有问题?谢谢!
# include "config.h"
# define REST 1 << 0 /* P0.00口作为VS1003 REST控制线 */
# define DREQ 1 << 1 /* P0.01口作为vs1003 DREQ控制线 */
# define XDCS 1 << 2 /* P0.02口作为vs1003 DCS控制线 */
# define XCS 1 << 3 /* P0.03口作为SSP从机的片选 */
# define LED1 1 << 17 /* P0.17控制LED1 */
# define LED2 1 << 18 /* P0.18控制LED2 */
# define LED3 1 << 19 /* P0.19控制LED3 */
# define LED4 1 << 20 /* P0.20控制LED4 */
# define COMMAND_READ 0x03 //读操作指令
# define COMMAND_WRITE 0x02 //写操作指令
# define SCI_MODE 0x0
# define SCI_STATUS 0x1
# define SCI_BASS 0x2
# define SCI_CLOCKF 0x3
# define SCI_DECODE_TIME 0x4
# define SCI_AUDATA 0x5
# define SCI_WRAM 0x6
# define SCI_WRAMDDR 0x7
# define SCI_HDAT0 0x8
# define SCI_HDAT1 0x9
# define SCI_AIADDR 0xA
# define SCI_VOL 0xB
# define SCI_AICTRL0 0xC
# define SCI_AICTRL1 0xD
# define SCI_AICTRL2 0xE
# define SCI_AICTRL3 0xF
//uint8 const uiBuf[8] = {/*0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07*/};
/*********************************************************************************************************
** Function name: DelayNS
** Descriptions: 长软件延时
** input parameters: uiDly延时控制值,值越大,延时越长
** output parameters: 无
** Returned value: 无
*********************************************************************************************************/
void DelayNS (uint32 NDly)
{
uint32 i;
for(; NDly > 0; NDly--){
for(i = 0; i < 500; i++);
}
}
void LDelayNS (uint32 uiDly)
{
uint32 i;
for(; uiDly > 0; uiDly--){
for(i = 0; i < 50000; i++);
}
}
/*********************************************************************************************************
** Function name: MSPIInit
** Descriptions: 初始化SPI接口,设置为主机,每次传输16位数据
** input parameters: 无
** output parameters: 无
** Returned value: 无
*********************************************************************************************************/
void MSPIInit(void)
{
PINSEL0 = (PINSEL0 & 0xFFFF00FF) | (0x15<<8); /* 设置SPI引脚连接 */
SPI_SPCCR = 0x6C; /* 设置SPI时钟分频 */
SPI_SPCR = 0 << 2 | /* 设置SPI每次传输发送和接收8位数据*/
0 << 3 | /* CPHA = 0第一个时钟采样 */
0 << 4 | /* CPOL = 0,SCK有效 */
1 << 5 | /* MSTR = 1,设置为主模式 */
0 << 6 | /* LSBF = 0,SPI传输MSB在先 */
0 << 7 ; /* SPIE = 0,SPI中断禁止 */
// 8 << 8 ; /* 设置8位传输 */
}
/*********************************************************************************************************
** Function name: MSPISendData
** Descriptions: SPI主模式发送数据
** input parameters: uiData: 将要发送的数据
** output parameters: 无
** Returned value: S0SPDR: 返回值为读取的数据
*********************************************************************************************************/
uint8 MSPISendData(uint8 uiData)
{
SPI_SPDR = uiData;
while ((SPI_SPSR & 0x80) == 0); /* 等待数据发送完毕 */
return(SPI_SPDR);
}
/*********************************************************************************************************
** Function name: WRITE_VSCOMMAND
** Descriptions:
** input parameters: 无
** output parameters: 无
** Returned value: 无
*********************************************************************************************************/
uint8 WRITE_VSCOMMAND(uint8 VS_addr,uint8 VS_hdata,uint8 VS_ldata)
{
while((IOPIN&DREQ)==0);
IO0CLR = XCS;
//IO0SET = XDCS;
MSPISendData(0x02);
MSPISendData(VS_addr);
MSPISendData(VS_hdata);
MSPISendData(VS_ldata);
IO0SET = XCS;
while((IOPIN&DREQ)==0);
return(0);
}
/*********************************************************************************************************
** Function name: SEND_SDI
** Descriptions:
** input parameters: 无
** output parameters: 无
** Returned value: 无
*********************************************************************************************************/
uint8 SEND_SDI(uint8 SDATA)
{
while((IOPIN&DREQ)==0);
IO0CLR = XCS;
IO0SET = XDCS;
MSPISendData(SDATA);
IO0CLR =XDCS;
IO0SET = XCS;
return(0);
}
/*********************************************************************************************************
** Function name: restVS
** Descriptions:
** input parameters: 无
** output parameters: 无
** Returned value: 无
*********************************************************************************************************/
void restVS(void)
{
IO0CLR = REST;
DelayNS(100);
IO0SET = XCS | XDCS | REST;
while((IOPIN&DREQ)==0);
DelayNS (1);
WRITE_VSCOMMAND(SCI_MODE,0x08,0x20);//CHU SHI HUA
DelayNS (1);
WRITE_VSCOMMAND(SCI_AUDATA,0xBB,0x81);//CHU SHI HUA
DelayNS (1);
WRITE_VSCOMMAND(SCI_BASS,0x00,0x55);//CHU SHI HUA
DelayNS (1);
WRITE_VSCOMMAND(SCI_CLOCKF,0x98,0x00);
DelayNS (1);
WRITE_VSCOMMAND(SCI_VOL,0x20,0x20);
DelayNS (1);
SEND_SDI(0xFF);
SEND_SDI(0xFF);
SEND_SDI(0xFF);
SEND_SDI(0xFF);
//return (0);
}
/*********************************************************************************************************
** Function name: SINE_TEST
** Descriptions:
** input parameters: 无
** output parameters: 无
** Returned value: 无
*********************************************************************************************************/
void SINE_TEST(void)
{
uint8 x=0;
while((IOPIN&DREQ)==0);
SEND_SDI(0x53);
SEND_SDI(0xef);
SEND_SDI(0x6e);
SEND_SDI(x);
SEND_SDI(0x00);
SEND_SDI(0x00);
SEND_SDI(0x00);
SEND_SDI(0x00);
LDelayNS(1000);
//IO0SET = XDCS;
}
/*********************************************************************************************************
** Function name: main
** Descriptions: SPI做主机
** input parameters: 无
** output parameters: 无
** Returned value: 无
*********************************************************************************************************/
int main(void)
{
PINSEL0 = PINSEL0 & 0xFFFFFF00; //SET P0.0~P0.3 IS GPIO
MSPIInit(); /* 初始化SPI接口 */
IO0DIR = XCS | XDCS | REST; /* set XCS | XDCS | REST is output */
IO0SET = REST;
restVS();
SINE_TEST();
while(1);
return (0);
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|