/*
METADATA
ATMEGA88PA
ADVANCEDMUSIC
SODIUMWATER
* GccApplication1.cpp
FOR ATMEGA88MUSIC
PB0 ->BASE OF 三极管
PD2 ->KEY(INT0)
* Created: 2022/1/13 22:51:12
* Author: 钠·鳞线链·水
*/

/*
1 8 64 256 1024
8 8 119 113 106 100 95 89 84 80 75 71 67 63
7 8 239 225 213 201 190 179 169 159 150 142 134 127
6
5 64 119 113 106 100 95 89 84 80 75 71 67 63
4 64 239 225 213 201 190 179 169 159 150 142 134 127
3 256 119 113 106 100 95 89 84 80 75 71 67 63
2 256 239 225 213 201 190 179 169 159 150 142 134 127
1 1024 119 113 106 100 95 89 84 80 75 71 67 63
0 1024 239 225 213 201 190 179 169 159 150 142 134 127
*/
/*
TCCR0B:FOC0A FOC0B - - WGM02 CS02..00
TCCR0A:COM0A1..0 COM0B1..0 - - WGM01..00
Mode WGM02 WGM01 WGM00 Timer/Counter Mode of Operation TOP Update of OCRx at TOV Flag Set on(1)(2)
0 0 0 0 Normal 0xFF Immediate MAX
1 0 0 1 PWM, phase Correct 0xFF TOP BOTTOM
2 0 1 0 CTC OCRA Immediate MAX
3 0 1 1 Fast PWM 0xFF BOTTOM MAX
4 1 0 0 Reserved – – –
5 1 0 1 PWM, phase Correct OCRA TOP BOTTOM
6 1 1 0 Reserved – – –
7 1 1 1 Fast PWM OCRA BOTTOM TOP
BOTTOM=0 TOP=TOP MAX=0XFF
CS02..00:STOP 1 8 64 256 1024 EXTFALL EXTRISE
TCNT0:计数器
TIMSK:OCIE2 TOIE2 TICIE1 OCIE1A OCIE1B TOIE1 OCIE0 TOIE0
TOIE0:使能溢出中断
TIFR:

SREG:I T H S V N Z C
I:全局中断使能

*/
#define F_CPU 8000000
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#define delay _delay_ms

//常量
const PROGMEM unsigned char halfzq[3][12]={{119,113,106,100,95,89,84,80,75,71,67,63},{239,225,213,201,190,179,169,159,150,142,134,127},{60,57,53,50,48,45,42,40,38,36,33,31}};
//半周期表
const PROGMEM unsigned char ygdyb[9][2]={{5,1},{5,0},{4,1},{4,0},{3,1},{3,0},{3,2},{2,1},{2,0}};
//音高对应表
const PROGMEM unsigned int fpxsb[6]={1,1,8,64,256,1024};
//分频系数表,注意:0位置无效!

//读谱变量
unsigned int unittime=250;
//default=120bpm
unsigned int unvdumbtime=10;
unsigned int scoreloopcounter=100,scorepointer=0;
char stopplay=0,scoreloop=0;
char movingkey=0;

//发声变量
unsigned long beepcounter=0;
unsigned long dumbthres=0;
//------------------------------------------------------------------------------------------
/*
//0~8 发音
//9 休止符
//10 无条件跳转并计数
//11 无条件停
//12 计数器开关
//13 计数器重设
//14 计数器归零跳转
//15 计数器归零停
//16 重设时间单位
//17 标记符号
//18 寻标操作并计数
//19 设置偏移音调
//20 设置不发音时间
//21 计数器归零寻标
//22 噪声,最大65毫秒*/

#define MUSICLENGTH 100
const PROGMEM unsigned char MUSICPROGRAM[MUSICLENGTH][3] = {
//{18, 0, 2},
/*
//测试片段
{4, 0, 1}, {4, 0, 1}, {4, 0, 1}, {4, 0, 1}, {4, 0, 1},
{4, 9, 1}, {4, 11, 1}, {5, 0, 1},
{13, 0, 5}, {5, 2, 1}, {5, 4, 1}, {5, 5, 1}, {5, 7, 1},
{14, 0, 15}, {10, 0, 9}, {9, 0, 2}, {10, 0, 0},
//*/
/*小行星()
{17, 0, 1}, {17, 65, 65}, {16, 0, 250},
{4, 0, 2}, {4, 0, 2}, {4, 7, 2}, {4, 7, 2}, {4, 9, 2}, {4, 9, 2}, {4, 7, 4},
{4, 5, 2}, {4, 5, 2}, {4, 4, 2}, {4, 4, 2}, {4, 2, 2}, {4, 2, 2}, {4, 0, 4},
{4, 7, 2}, {4, 7, 2}, {4, 5, 2}, {4, 5, 2}, {4, 4, 2}, {4, 4, 2}, {4, 2, 4},
{4, 7, 2}, {4, 7, 2}, {4, 5, 2}, {4, 5, 2}, {4, 4, 2}, {4, 4, 2}, {4, 2, 4},
{4, 0, 2}, {4, 0, 2}, {4, 7, 2}, {4, 7, 2}, {4, 9, 2}, {4, 9, 2}, {4, 7, 4},
{4, 5, 2}, {4, 5, 2}, {4, 4, 2}, {4, 4, 2}, {4, 2, 2}, {4, 2, 2}, {4, 0, 4},
//{18, 255, 0},//*/

/*天空之城(118)
//{17, 0, 2}, {17, 65, 66},
{19, 1, 0}, {16, 0x01, 0x4d},//3
{4, 9, 1}, {4, 11, 1}, {5, 0, 3}, {4, 11, 1}, {5, 0, 2}, {5, 4, 2}, {4, 11, 6},
{4, 4, 2}, {4, 9, 3}, {4, 7, 1}, {4, 9, 2}, {5, 0, 2}, {4, 7, 7},
{4, 4, 1}, {4, 5, 3}, {4, 4, 1}, {4, 5, 1}, {5, 0, 3}, {4, 4, 6}, //{3, 9, 1}, {3, 11, 1}, {4, 0, 2},
{5, 0, 1}, {5, 0, 1}, {4, 11, 3}, {4, 6, 1}, {4, 6, 2}, {4, 11, 2}, {4, 11, 2}, {4, 9, 2}, {4, 8, 2},//28
{4, 9, 1}, {4, 11, 1}, {5, 0, 3}, {4, 11, 1}, {5, 0, 2}, {5, 4, 2}, {4, 11, 6},
{4, 4, 2}, {4, 9, 3}, {4, 7, 1}, {4, 9, 2}, {5, 0, 2}, {4, 7, 6},
{4, 4, 2}, {4, 5, 3}, {5, 0, 1}, {4, 11, 1}, {5, 0, 3}, {5, 2, 2}, {5, 2, 1}, {5, 4, 1}, {5, 0, 4}, //{9, 0, 2},
{5, 0, 1}, {4, 11, 1}, {4, 9, 1}, {4, 9, 1}, {4, 11, 2}, {4, 8, 2}, {4, 9, 6},//30
{5, 0, 1}, {5, 2, 1}, {5, 4, 3}, {5, 2, 1}, {5, 4, 2}, {5, 7, 2}, {5, 2, 6},
{4, 7, 2}, {5, 0, 3}, {4, 11, 1}, {5, 0, 2}, {5, 4, 2}, {5, 4, 8},
{4, 9, 1}, {4, 11, 1}, {5, 0, 2}, {4, 11, 1}, {5, 0, 1}, {5, 2, 2}, {5, 0, 3}, {4, 7, 1}, {4, 7, 4},
{5, 5, 2}, {5, 4, 2}, {5, 2, 2}, {5, 0, 2}, {5, 4, 6},//27
{5, 4, 2}, {5, 9, 3}, {5, 9, 1}, {5, 7, 3}, {5, 7, 1}, {5, 4, 1}, {5, 2, 1}, {5, 0, 2} , {5, 0, 3},
{5, 0, 1}, {5, 2, 3}, {5, 0, 1}, {5, 2, 2}, {5, 7, 2}, {5, 4, 6},
{5, 4, 2}, {5, 9, 3}, {5, 9, 1}, {5, 7, 3}, {5, 7, 1}, {5, 4, 1}, {5, 2, 1}, {5, 0, 2} , {5, 0, 3},
{5, 0, 1}, {5, 2, 3}, {5, 0, 1}, {5, 2, 2}, {4, 11, 2}, {4, 9, 6},//30
//{18, 0, 2},
//*/
//世上只有妈妈好(38)
{17, 0, 3}, {17, 65, 67},
{19, 1, 0}, {16, 0, 250},
{4, 9, 3}, {4, 7, 1}, {4, 4, 2}, {4, 7, 2}, {5, 0, 2}, {4, 9, 1}, {4, 7, 1}, {4, 9, 4},
{4, 4, 2}, {4, 7, 1}, {4, 9, 1}, {4, 7, 2}, {4, 4, 1}, {4, 2, 1}, {4, 0, 1}, {3, 9, 1}, {4, 7, 1}, {4, 4, 1}, {4, 2, 4},
{4, 2, 3}, {4, 4, 1}, {4, 7, 2}, {4, 7, 1}, {4, 9, 1}, {4, 4, 2}, {4, 2, 2}, {4, 0, 4},
{4, 7, 3}, {4, 4, 1}, {4, 2, 1}, {4, 0, 1}, {3, 9, 1}, {4, 0, 1}, {3, 7, 8},
//{9, 0, 8},
{18, 255, 0},//*/

/*虫儿飞(94)
{17, 0, 4}, {17, 65, 68}, //1
{19, 1, 5}, {16, 0x01, 0x23}, //2
{4, 4, 2}, {4, 4, 1}, {4, 4, 1}, {4, 5, 2}, {4, 7, 2}, {4, 4, 3}, {4, 2, 1}, {4, 2, 4},
{4, 0, 2}, {4, 0, 1}, {4, 0, 1}, {4, 2, 2}, {4, 4, 2}, {4, 4, 3}, {3, 11, 1}, {3, 11, 4},
{3, 9, 2}, {4, 4, 2}, {4, 2, 4},
{3, 9, 2}, {4, 4, 2}, {4, 2, 4},
{3, 9, 2}, {4, 4, 2}, {4, 2, 3}, {4, 0, 1}, {4, 0, 8}, //27
{4, 4, 2}, {4, 4, 1}, {4, 4, 1}, {4, 5, 2}, {4, 7, 2}, {4, 4, 3}, {4, 2, 1}, {4, 2, 4},
{4, 0, 2}, {4, 0, 1}, {4, 0, 1}, {4, 2, 2}, {4, 4, 2}, {4, 4, 3}, {3, 11, 1}, {3, 11, 4},
{3, 9, 2}, {4, 4, 2}, {4, 2, 4},
{3, 9, 2}, {4, 4, 2}, {4, 2, 4},

Next
Pg.: 1 2 3 4 5 6


Back to home | File page

Subscribe | Register | Login | N