⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dac_drv.c

📁 基于UCOS-II制作的MP3
💻 C
字号:
/*C**************************************************************************
* NAME:         dac_drv.c
*----------------------------------------------------------------------------
* Copyright (c) 2003 Atmel.
*----------------------------------------------------------------------------
* RELEASE:      snd1c-refd-nf-4_0_3      
* REVISION:     1.5     
*----------------------------------------------------------------------------
* PURPOSE:
* This file contains routines to address UDA1330ATS in L3 mode
*
*****************************************************************************/

/*_____ I N C L U D E S ____________________________________________________*/

#include "config.h"                         /* lib configuration header */
#include "board.h"                          /* board definition */
#include "dac_drv.h"                        /* dac driver definition */

/*_____ M A C R O S ________________________________________________________*/


/*_____ D E F I N I T I O N ________________________________________________*/

/*_____ D E C L A R A T I O N ______________________________________________*/
#ifdef DAC_L3MODE
/*F**************************************************************************
* NAME: dac_byte_send
*----------------------------------------------------------------------------
* PARAMS:
*   b:   byte to send
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Serialize a data/cmd/addr byte on DAC_L3DATA & DAC_L3CLOCK pins.
*----------------------------------------------------------------------------
* NOTE:
*   This function should only be used by dac_l3mode_send
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void dac_byte_send (Byte b)
{
Byte    c;

for (c=8;c;c--)
  {
  DAC_L3DATA=(b&1); // practically 50% duty cycle
  DAC_L3CLOCK=0;
  b>>=1;
  DAC_L3CLOCK=1;    // data bit is sampled here (rising edge)
  }
}


/*F**************************************************************************
* NAME: dac_l3mode_send
*----------------------------------------------------------------------------
* PARAMS:
*   addr:   logical address of the chip (000101xxb for UDA1330)
*   b:      data/cmd byte to send
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Send a L3-mode command to the DAC UDA1330
*----------------------------------------------------------------------------
* NOTE:
*   This function improve the song quality (low level, decrease signal/noise).
*----------------------------------------------------------------------------
* REQUIREMENTS:
*   Only tested with UDA1330ATS
*****************************************************************************/
void dac_l3mode_send (Byte addr,Byte b)
{
DAC_TEST=0;     // be carefull ! if DAC_TEST is set with DAC_APPSEL not set, I/O of UDA1330 change a lot
DAC_APPSEL=0;   // Turn DAC in L3 mode
DAC_L3MODE=1;   
DAC_L3CLOCK=1;
DAC_L3DATA=1;   // Normal state, basically, those three pins are already set
// Begin Addr transfer
DAC_L3MODE=0;
dac_byte_send(addr);
// Begin Data/Cmd transfer
DAC_L3MODE=1;
dac_byte_send(b);
// Ack end of data/cmd transfer
DAC_L3MODE=0;
DAC_L3MODE=1;
}

/*F**************************************************************************
* NAME: dac_set_vol
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Use the DAC to modify song level.
*----------------------------------------------------------------------------
* NOTE:
*   This function must be call each time mp3_volume is changed
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void dac_set_vol (Byte volume)
{
if (volume>=32) volume=16; // security !
if (volume<24)
  {
  MP3VOL = MP3VOR = 15;
  dac_l3mode_send(DAC_L3I_ADDR,64-(volume<<1)-volume+(volume>>2));
  }
else
  {
  MP3VOL = MP3VOR = 15 + ((volume-23)<<1);
  dac_l3mode_send(DAC_L3I_ADDR,0);
  }
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -