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

📄 mainx.c

📁 凌阳单片机的语音程序4
💻 C
字号:
/*****************************************************************************************
Program: SACM-MS01 player with play, stop, pause, resume, volume up, volume down function

General Function call:
System_Initial();               For Hardware, Keyboard scan, see system.asm in detail
System_ServiceLoop();           For Keyboard scan, see system.asm in detail


Standard Function call:
int STD_GetCh();                
        Return values of STD_GetCh() : {0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}
 
 
Function call for SACM-MS01 only:
Syntax: 
 SACM_MS01_Play(SongIndex)
        song index: 0 - max index
        song index:255 - reserved for PC-Play
                                                 
 SACM_MS01_Stop();
        
 SACM_MS01_Pause();
 SACM_MS01_Resume();
 
 SACM_MS01_VolumeUp(volume index);
 SACM_MS01_VolumeDn(volume index);
        volume index: {0..15}
        
*****************************************************************************************/
#include "hardware.h"
#include "ms01.h"

#define Disable                 0
#define Enable                  1

#define MaxSongNum              11                  // Max. of song in resource
#define MaxVolume               15                  // Max. of volume

int     Ret = 0;                                    // Define for return value of subroutine

int main() {
        int Key = 0;                                // define for store temperary key code
        int SongIndex = 0;                          // Initial to first song
        int VolumeIndex = 8;                        // Initial to middle volume
        int DAC_PWM_Select = 4;                        // 0: 24K PWM or DAC, 1: 24K Current DAC(TimerA)		
													// 2: 20K Current(TimerA) 3: 16K Current(TimerA)	
        Ret = System_Initial();
        
        							
       	DAC_PWM_Select = 1;
        Ret = SACM_MS01_Initial(DAC_PWM_Select);
        SACM_MS01_Play(SongIndex);           // Play song
        while(1) {                                  	// Main loop in c language domain
            Key = STD_GetCh();
            switch(Key) {
            case 0x00:
                    break;
            case 0x01:
            		Key = Key;
            
                    SACM_MS01_Play(SongIndex);           // Play song
                    break;
            case 0x02:
                    SACM_MS01_Stop();                    // Stop song
                    break;
            case 0x04:
                    SACM_MS01_Pause();                   // Pause song
                    break;
            case 0x08:
                    SACM_MS01_Resume();                  // Rusume song after song was paused
                    break;
            case 0x10:
                    VolumeIndex++;
                    if(VolumeIndex > MaxVolume)
                            VolumeIndex = MaxVolume;
                    SACM_MS01_Volume(VolumeIndex);       // Song volume up
                    break;
            case 0x20:
                    if(VolumeIndex == 0)
                            VolumeIndex = 0;
                    else
                            VolumeIndex--;
                    SACM_MS01_Volume(VolumeIndex);  // Song volume down
                    break;
            case 0x40:      						// play next song 
                    if( ++SongIndex == MaxSongNum)
                          SongIndex = 0;
                    SACM_MS01_Play(SongIndex);
                    break;
                        
            case 0x80:      						// play previous song
                    if( --SongIndex < 0)
                          SongIndex = MaxSongNum-1;
                    SACM_MS01_Play(SongIndex);
                    break;
            default:
                    break;
            }
            Ret = System_ServiceLoop();             // Service loop for Key Scanning
            Ret = SACM_MS01_ServiceLoop();          // Service loop for SACM-MS01 playing
        }
        return 0;
}

⌨️ 快捷键说明

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