#include "sys.h"
#include "delay.h"
#include "string.h"
#include "Audio.h"
#define SPI_CS PCout(0)
#define SPI_SCK PDout(3)
#define SPI_SDO PDout(4)
static void SPI_Send_Data(uint8_t dat)
{
uint8_t i = 0;
SPI_CS = 0;
SPI_SCK = 0;
for (i = 0; i < 8; i++)
{
SPI_SDO = (dat & 0x01) ? 1 : 0;
SPI_SCK = 1;
delay_us(2);
SPI_SCK = 0;
dat >>= 1;
delay_us(1);
}
SPI_CS = 1;
delay_us(5);
}
static void SPI_WriteCMDData(uint8_t cmd, uint8_t dat)
{
SPI_Send_Data(cmd);
SPI_Send_Data(dat);
}
void Audio_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3| GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
SPI_WriteCMDData(0x01, 0); //语言 0中文 1英文
SPI_WriteCMDData(0x02,50); //速度 1-100 10正常速度
SPI_WriteCMDData(0x03,10); //音调 0-20 10正常
SPI_WriteCMDData(0x04 ,0); //播放模式 默认0:播放前强制结束当前的播放 1:叠加播放
}
void Audio_Start( uint8_t *str)
{
SPI_WriteCMDData(0x05, strlen(str)); //字符串长度
SPI_Send_Data(0x06); //发送文本
while(*str)
{
SPI_Send_Data(*str++);
}
}
|