初中生
最后登录1970-1-1
在线时间 小时
注册时间2015-1-8
|
楼主 |
发表于 2015-1-10 22:50:01
|
显示全部楼层
#define DAC_DHR12R1_Address 0x40007408//0x40007420
/* 2¨DÎêy¾Y ---------------------------------------------------------*/
const uint16_t Sine12bit[8] = {0x0,0x26c,0x4d8,0x745,0x9b1,0xc1c,0xe89,0xffd
};
uint32_t DualSine12bit=0;
/**
* @brief ê1ÄüDACμÄê±Öó£¬3õê¼»ˉGPIO
* @param ÎT
* @retval ÎT
*/
static void DAC_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DAC_InitTypeDef DAC_InitStructure;
/* ê1ÄüGPIOAê±Öó */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
/* ê1ÄüDACê±Öó */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
/* DACμÄGPIOÅäÖã¬Ä£Äaêäèë */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* ÅäÖÃDAC í¨μà1 */
DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software; //′¥·¢Ô′
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; //2»ê1óÃ2¨Dη¢éúÆ÷
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; //2»ê1óÃDACêä3ö»o3å
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
/* ê1Äüí¨μà1 óéPA4êä3ö */
DAC_Cmd(DAC_Channel_1, ENABLE);
DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE);
/* ê1ÄüDACμÄDMAÇëÇó */
DAC_DMACmd(DAC_Channel_1, ENABLE);
}
/**
* @brief ÅäÖÃKEY
* @param ÎT
* @retval ÎT
*/
void KEY_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*¿aÆô°′¼ü¶Ë¿ú£¨PA£©μÄê±Öó*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
/**
* @brief ÅäÖÃDMA
* @param ÎT
* @retval ÎT
*/
static void DAC_DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
/* ê1ÄüDMA2ê±Öó */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
/* ÅäÖÃDMA2 */
DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12R1_Address; //íaéèêy¾YμØÖ·
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&DualSine12bit ; //Äú′æêy¾YμØÖ· DualSine12bit
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; //êy¾Y′«êä·½ÏòÄú′æÖáíaéè
DMA_InitStructure.DMA_BufferSize = 2; //»o′æ′óD¡Îa2×Ö½ú
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //íaéèêy¾YμØÖ·1춨
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; //Äú′æêy¾YμØÖ·×ÔÔö
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; //íaéèêy¾YòÔ×ÖÎaμ¥λ
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; //Äú′æêy¾YòÔ×ÖÎaμ¥λ
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //Ñ-»·Ä£ê½
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //¸ßDMAí¨μàóÅÏ輶
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //·ÇÄú′æÖáÄú′æÄ£ê½
DMA_Init(DMA2_Channel3, &DMA_InitStructure);
/* ê1ÄüDMA2-14í¨μà */
DMA_Cmd(DMA2_Channel3, ENABLE);
}
//°′¼üé¨Ãè
uint8_t Key_Scan(GPIO_TypeDef* GPIOx,u16 GPIO_Pin)
{
/*¼ì2aêÇ·ñóD°′¼ü°′Ï */
if(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin) == KEY_ON )
{
/*Ñóê±Ïû¶¶*/
Key_Delay(10000);
if(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin) == KEY_ON )
{
/*μè′y°′¼üêí·Å */
while(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin) == KEY_ON);
return KEY_ON;
}
else
return KEY_OFF;
}
else
return KEY_OFF;
}
//°′¼üD
void Key_Delay(__IO u32 nCount)
{
for(; nCount != 0; nCount--);
}
/**
* @brief DAC3õê¼»ˉoˉêy
* @param ÎT
* @retval ÎT
*/
void DAC_Mode_Init(void)
{
uint32_t Idx = 0;
DAC_Config();
DAC_DMA_Config();
KEY_GPIO_Config();
while(1)
{
if( Key_Scan(GPIOA,GPIO_Pin_0) == KEY_ON ){
Idx++;
DualSine12bit = Sine12bit[Idx];
DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE);
}
if(Idx==7)
Idx=0;
}
}
能看一下错误在哪吗?烧到板子里没反应。 |
|