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

📄 voice_drv.c

📁 ATMEL公司AT89C51SND1为主控制器MP3源代码
💻 C
字号:
/*C**************************************************************************
* NAME:         voice_drv.c
*----------------------------------------------------------------------------
* Copyright (c) 2003 Atmel.
*----------------------------------------------------------------------------
* RELEASE:      snd1c-refd-nf-4_0_3      
* REVISION:     1.9     
*----------------------------------------------------------------------------
* PURPOSE:
* This file contains the voice driver routines Timer 1 is used as conversion 
* time base, its frequency is defined in config.h
*
* NOTES:
* Global Variables:
*   - voice_buffer:    array of bytes in xdata space
*   - gl_pointer:   byte in data space
*****************************************************************************/

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

#include "config.h"                 /* system configuration */
#include "board.h"                  /* board definition */
#include "dac\dac_drv.h"            /* dac driver definition */
#include "lib_mcu\clock\clock.h"    /* clock definition */
#include "voice_drv.h"              /* voice driver definition */


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


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

extern  xdata   Byte    voice_buffer[];
extern  data    Byte    gl_pointer;

Byte    voc_volume;                     /* volume value */


/*_____ D E C L A R A T I O N ______________________________________________*/

static  void    voc_audio_init (void);


/*F**************************************************************************
* NAME: voc_rec_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Initialize the timer and ADC
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*   T1_PRIO defined in config.h
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void voc_rec_init (void)
{
  gl_pointer = 0x00;
  Adc_set_clock(AD_CLOCK);
  Adc_enable();
  Adc_select_channel(VOICE_CHANNEL);          /* select voice channel */
  T1_init(T1_NOT_GATED, T1_TIMER, T1_MODE_2); /* 8-bit auto-reload */
  TH1 = T1_BASE;                              /* load timer */ 
  t1_set_prio(T1_PRIO);                       /* set-up priority */
  T1_enable_int();                            /* enable interrupt */
  T1_start();
}


/*F**************************************************************************
* NAME: voc_play_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Audio interface initialization
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void voc_play_init (void)
{
  gl_pointer = 0x00;
  voc_audio_init();                       /* init audio interface */
  clock_voice_init();                     /* program the voice clocks */
}


/*L**************************************************************************
* NAME: voc_audio_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Audio interface initialization in voice mode
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*   DAC_NB_BIT and AUD_PRIO defined in config.h
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void voc_audio_init (void)
{
  Aud_set_pcm_32(DAC_NB_BIT);
  Aud_set_voice(MSK_DUP0);
  aud_set_prio(AUD_PRIO);
  Aud_enable();
  Dac_unmute();
}


/*F**************************************************************************
* NAME: voc_play_start
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Fill audio buffer and start sample request
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*   0x80 offset is added for unsigned to signed samples conversion 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void voc_play_start (void)
{
Byte i;

  for (i = 8; i != 0; i--)
  {
    AUDDAT = (char)voice_buffer[gl_pointer++] / (char)voc_volume;
  }
  Aud_voice_play();                       /* start sample request */
}


/*F**************************************************************************
* NAME: voc_play_stop
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Stop voice playing
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void voc_play_stop (void)
{
  Dac_mute();                               /* silence */
  aud_stop();                               /* disable audio */
  Pll_stop();                               /* disable pll */
}


/*F**************************************************************************
* NAME: voc_inc_volume
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Increment playing volume
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void voc_inc_volume (void)
{
  if (voc_volume != VOC_VOLUME_MAX)
  {
    voc_volume--;
  }
}


/*F**************************************************************************
* NAME: voc_dec_volume
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Decrement playing volume
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void voc_dec_volume (void)
{
  if (voc_volume != VOC_VOLUME_MIN)
  {
    voc_volume++;
  }
}


/*F**************************************************************************
* NAME: voc_rec_int
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Timer 1 interrupt function
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*   IRQ_T1 defined in extsnd1.h
*   gl_pointer is modulo 256
*   VOICE_CHANNEL is always selected by default, other conversion on 
*   BATTERY_CHANNEL may pause the Timer 1 and reselect VOICE_CHANNEL for
*   proper voice conversion.
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
Interrupt (voc_rec_int(void), IRQ_T1) 
{
  Adc_convert_idle();                       /* launch new conversion */
  voice_buffer[gl_pointer++] = (Adc_get_data_h()); /* write data in buffer */
  Adc_ack_conversion();
}


/*F**************************************************************************
* NAME: voc_play_int
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Audio interrupt function
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*   IRQ_AUD defined in extsnd1.h
*   The underrun condition is not tested as it must not appear
*   0x80 offset is added for unsigned to signed samples conversion 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
Interrupt (voc_play_int (void), IRQ_AUD)
{
  ACC= AUDSTA;                        /* dummy read to clear flags */
  AUDDAT = (char)(voice_buffer[gl_pointer++] + 0x80)/(char)voc_volume;
  AUDDAT = (char)(voice_buffer[gl_pointer++] + 0x80)/(char)voc_volume;
  AUDDAT = (char)(voice_buffer[gl_pointer++] + 0x80)/(char)voc_volume;
  AUDDAT = (char)(voice_buffer[gl_pointer++] + 0x80)/(char)voc_volume;
}





⌨️ 快捷键说明

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