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

📄 acprd_song.c

📁 source code for a sample alarm control panel system using Freescale MC9S12DP256 . The project was im
💻 C
字号:
//=============================================================================
// File: ACPRD_SONG.C - V1.00
// Rem.: The ACPRD Project Page on the Web -> http://hc12web.de/acprd
//=============================================================================

//-- Includes -----------------------------------------------------------------

#include <stdio.h>
#include "datatypes.h"
#include "acprd_freqout.h"
#include "acprd_song.h"

//-- Static Vars --------------------------------------------------------------

const UINT16 *song_ptr;
UINT16 song_dura;

// frequency definitions (unit: period time in 祍)
const UINT16 period_table[] = {
	0,		// pause
	1912,	// 523Hz - c
	1805,	// 554Hz - cis
	1704,	// 587Hz - d
	1608,	// 622Hz - dis
	1517,	// 659Hz - e
	1433,	// 698Hz - f
	1351,	// 740Hz - fis
	1276,	// 784Hz - g
	1205,	// 830Hz - gis
	1136,	// 880Hz - a
	1073,	// 932Hz - ais
	1013 	// 987Hz - h
	};

//-- Code ---------------------------------------------------------------------

void initSong(void) {

	song_ptr = NULL;
	}

//-----------------------------------------------------------------------------

void startSong(const UINT16 *asong) {

	song_dura = 0;
	song_ptr = asong;
	setFreqOut(0);
	}

//-----------------------------------------------------------------------------

// song playing?
// if not return NULL
//
UINT16 *hasSong(void) {

	return (UINT16 *)song_ptr;
	}

//-----------------------------------------------------------------------------

void handleSong(void) {

	unsigned period;

	if(song_ptr == NULL) return;
	if(song_dura == 0) {
		song_ptr++;
		// get 1/freq of note (period in 祍)
		period = period_table[*song_ptr & 0x000f];
		// low octave -> double period
		if((*song_ptr & 0x00f0) == _DEEP) period <<= 1;
		// start playing the tone
		setFreqOut(period);
		if(*song_ptr == _STOP) {
			startSong(NULL);
			return;
			}
		song_dura = (*song_ptr >> 8) & 0x003f;
		}
	else if(song_dura == 1) setFreqOut(0); // mute last 1/32 of each note
	song_dura--;
	}

//=============================================================================

⌨️ 快捷键说明

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