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

📄 main.c

📁 spce061单片机的一些程序!C语言和汇编语言都有
💻 C
字号:
//======================================================================================
//
//        The information contained herein is the exclusive property of
//      Sunplus Technology Co. And shall not be distributed, reproduced,
//      or disclosed in whole in part without prior written permission.
//
//            (C) COPYRIGHT 2001   SUNPLUS TECHNOLOGY CO.
//                           ALL RIGHTS RESERVED
//
//    The entire notice above must be reproduced on all authorized copies.
//
//========================================================================================
//  工程名称: MS01.spj
//  功能描述:   MS01以自动方式播放
//				
//  文件来源: 《SPCE061单片机原理及应用技术》第七章 凌阳音频压缩算法,第286页
//  IDE环境:  	SUNPLUS u'nSPTM  IDE 1.8.0(or later)
//
//  涉及的库:	CMacro.lib/sacmv25.lib
//
//  组成文件:	MAIN.c
//    	 		ISr.asm/hardware.asm/key.asm
//	            hardware.inc/key.inc/MS01.h/MS01.inc
//     	
//  日期:       2002-6-12
//===========================================================================================
#include "hardware.h"
#include "ms01.h"

#define Disable                 0
#define Enable                  1

#define MaxSongNum              11           	// 最大语音资源文件个数
#define MaxVolume               15          	//最大音量

#define Inst_Max_Num			35				// 乐器混合数
#define Drum_Max_Num			20				// 鼓点数

#define DAC_24K					1
#define DAC_20K					2
#define DAC_16K					3

#define Manual			        0
#define	Auto			        1


int     Ret = 0;              					// 定义子程序返回值

int main()
 {
        int Key = 0;         					// 定义存储器键值
        int SongIndex = 0;   					// 第一首曲子的初始化
        int VolumeIndex = 8; 					//初始化中音
		int	OnIndex=0,OffIndex=0;
		int Channel=0, Instrument=0 ,Drum=0;
		// 2: 20K Current(TimerA) 3: 16K Current(TimerA)	
        Ret = System_Initial();
        
        SACM_MS01_Initial(DAC_24K);
        SACM_MS01_Play(SongIndex,DAC1+DAC2, Ramp_UpDn_On);  //播放音乐
        
        //SACM_MS01_ChannelOff(0);
        //SACM_MS01_ChannelOff(1);
        //SACM_MS01_ChannelOff(2);
        //SACM_MS01_ChannelOff(3);
        //SACM_MS01_ChannelOff(4);
        //SACM_MS01_ChannelOff(5);
        
        while(1) 
    {                               				// 用C语言定义主函数范围
            Key = SP_GetCh();
            switch(Key) 
       {
            case 0x00:
                    break;
            case 0x01:
            		SACM_MS01_Play(SongIndex,DAC1+DAC2, Ramp_UpDn_On);  // 播放音乐
                    break;
            case 0x02:
                    SACM_MS01_Stop();                 // 停止播放
                    break;
            case 0x04:
					     
            		SACM_MS01_ChannelOn(OnIndex);
		            if (OnIndex++ > 5) OnIndex = 0;
		            
                    //SACM_MS01_Pause();                // 暂停
                    break;
            case 0x08:
            		
            		SACM_MS01_ChannelOff(OffIndex);
		            if (--OffIndex < 0) OffIndex = 5;
		            
                    //SACM_MS01_Resume();           	// 暂停后恢复 after song was paused
                    break;
            case 0x10:
                    VolumeIndex++;
                    if(VolumeIndex > MaxVolume)
                            VolumeIndex = MaxVolume;
                    SACM_MS01_Volume(VolumeIndex); 		// 音量增加
                    break;
            case 0x20:
                    if(VolumeIndex == 0)
                            VolumeIndex = 0;
                    else
                            VolumeIndex--;
                    SACM_MS01_Volume(VolumeIndex); 		// 音量减小
                    break;
            case 0x40:      							//播放下一首
                    if( ++SongIndex == MaxSongNum)
                          SongIndex = 0;
                    SACM_MS01_Play(SongIndex, DAC1+DAC2, Ramp_UpDn_On);
                    break;
                        
            case 0x80:      							//播放前一首 
            		SACM_MS01_ChannelOff(0);
        			SACM_MS01_ChannelOn(1);
        			SACM_MS01_ChannelOn(2);
        			SACM_MS01_ChannelOff(3);
        			SACM_MS01_ChannelOff(4);
        			SACM_MS01_ChannelOff(5);
		                
            		SACM_MS01_SetInstrument(2,Instrument,0);//f(channel, instrument,song command on/off)
            		if(++Instrument > Inst_Max_Num) Instrument=0;
                    
                    SACM_MS01_SetInstrument(1,Drum,1);		//f(channel, instrument,song command on/off)
            		if(++Drum > Drum_Max_Num) Drum=0;
                                
                    //if( --SongIndex < 0)
                    //SongIndex = MaxSongNum-1;
                    //SACM_MS01_Play(SongIndex,DAC1+DAC2);
                    break;
            default:
                    break;
            }
            Ret = System_ServiceLoop();            		// 键扫描服务子程序
            Ret = SACM_MS01_ServiceLoop();         		//   SACM-MS01 播放子程序
	}
        return 0;
}
 

⌨️ 快捷键说明

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