freescale

来自「Freescale 系列单片机常用模块与综合系统设计」· 代码 · 共 128 行

TXT
128
字号
/** ###################################################################
**     Filename  : voice_play.C
**     Project   : voice_play
**     Processor : MC9S08JM60CLHE
**     Version   : Driver 01.11
**     Compiler  : CodeWarrior HCS08 C Compiler
**     Date/Time : 2009-9-21, 20:11
**     Abstract  :
**         Main module.
**         This module contains user's application code.
**     Settings  :
**     Contents  :
**         No public methods
**
**     (c) Copyright UNIS, spol. s r.o. 1997-2008
**     UNIS, spol. s r.o.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
** ###################################################################*/
/* MODULE voice_play */


/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "start.h"
#include "oem.h"
#include "ce.h"
#include "pd.h"
#include "p_r.h"
#include "addr_low.h"
#include "addr_high.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"

unsigned char count;  //重复播放次数计数器
unsigned char Start_Flag; //开始键按下标志
unsigned char Idle_Flag;  //系统是否处于空闲状态标志

void delay( unsigned int time) 
{
  unsigned char i;
  
  while(time--) 
    for(i =0; i < 125; i++); 
}

void record_voice() 
{
    ce_PutVal(0);   //CE=0
    pd_PutVal(0);   //PD=0
    p_r_PutVal(0);   //PR=0    
}

void play_voice() 
{
    ce_PutVal(0);   //CE=0
    pd_PutVal(0);   //PD=0
    p_r_PutVal(1);   //PR=1    
}

void main(void)
{
  /* Write your local variable definition here */

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/
  
  count = 0;
  Start_Flag = 0;
  Idle_Flag = 1;
  
  while(Idle_Flag == 1) 
  {
    if(start_GetVal() == 0) 
    {
       delay(10);
       if(start_GetVal() == 0) 
       {
         Start_Flag = 1;
       }
       
       if(Start_Flag == 1) 
       {
         do 
         {
           addr_high_PutVal(0x03); //A8,A9=0
           addr_low_PutVal(0xff);  //A0~A7 =0
         
           record_voice();
         }
         while(start_GetVal() == 1);  //开始键松开
         
         Start_Flag = 0;
         
         p_r_PutVal(1);   //结束录音
         pd_PutVal(1);    //进入节电状态
         
         delay(500);      //延时500ms再播放录音
         
         addr_high_PutVal(0x03); //A8,A9=0
         addr_low_PutVal(0xff);  //A0~A7 =0
         
         play_voice();    // 从地址0处进行第一次播放
         
         Idle_Flag = 0;   //当前不空闲,按开始键无效        
       }
    }  
  }
} 

/* END voice_play */
/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 3.03 [04.07]
**     for the Freescale HCS08 series of microcontrollers.
**
** ###################################################################
*/

⌨️ 快捷键说明

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