4X4键盘多功能电子琴
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
for(i=0;i<16;i++)
{
send_data(shu[i]);
//delay(10);
}
}
if(sound_add==40 )
{
send_command(0x80);
{
uint i;
US=US*5/4; //5/4是在8MHz晶振下,通过软件仿真反复实验得到的数值
for( i=0;i<US;i++);
}
/************************************************
*函数名称: void Delayms(uint16 MS)
0x2b,0x4a,0x28,0x28,0x69,0x29,0x49,0x29,0x28,
0x46,0xc6, 0x87,0x67,0x26,0x45,0x4d,0x4c,0x29,0x29,
0x6b,0x2b,0x4b,0x2a,0x29,0xfc,
0x00};
#define TI 64522 //988
#define DO_H 64578 //1046
#define RE_H 64683 //1174
#define MI_H 64776 //1318
#define FA_H 64819 //1397
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x04; //timer interrupt sources
SREG=0x80;// //全局中断开
PORTD^=BIT(4);
}
/************************************************
*函数名称: void music(void)
*入口参数: 无
*出口参数: 无
*函数功能: 音乐播放函数
*创建时间: 2009-09-01 eleShrimp
temp--;
toneconst=TONETABLE[temp];
TCNT1=toneconst;
}
temp=temp1;
temp>>=4;
temp&=0x0f;
Delayms(temp*129);//根据SOUNDTABLE中数据的高四位*5后,为音调持续时间
0x46,0x46,0x4a,0x4d,0x4c,0x2d,0x2c,0x2b,0x2b,0x2a,
0x29,0x4a,0x46, 0x20,0x4b,0x29,0x6a,0x28,0x27,0x23,
#define SO_H 64897 //1568
#define LA_H 64966 //1760
#define TI_H 65028 //1976
#define DO_HH 65057 //2093
const uchar sound[]={ //乐曲数据表
0x40,0x4c,0x4a,0x49,0xc8,0x49,0x47,0x46,
temp1=sound[sound_add];
while(temp1!=0)
{
temp=temp1;
temp&=0x0f;
if(temp!=0)
{
TIMSK|=(1<<TOIE1);//根据SOUNDTABLE中数据的低四位选择音调频率 TOIE1是TIMER1溢出中断允许
0x46,0x45,0x46,0xe6,
/***********喀秋莎*********/
0x66,0x27,0x68,0x26,0x28,0x28,0x27,0x26,0x47,0x43,
0x67,0x28,0x69,0x27,0x29,0x29,0x28,0x27,0x46,0x46,
0x4a,0x4d,0x4c,0x2d,0x2c,0x2b,0x2b,0x2a,0x29,0x4a,
0x46,0x20,0x4b,0x29,0x6a,0x28,0x27,0x23,0x28,0x27,
extern void music(void);
#define DO 63622 //523
#define RE 63831 //587
#define MI 64017 //659
#define FA 64102 //698
#define SO 64259 //784
#define LA 64398 //880
*入口参数: uint16 MS,延时的毫秒数
*出口参数: 无
*函数功能: 延时指定毫秒(8M晶振)
*创建时间: 2009-09-01 eleShrimp
*修改说明:
/************************************************/
void Delayms(uint MS)
0x26,0x18,0xe5,0x6a,0x2c,0x47,0x49,0x26,
0x28,0x85,0x33,0x15,0x43,0x25,0x26,0x27,
0x29,0xc6,0x25,0x26,0x68,0x29,0x4c,0x4a,
0x49,0x2a,0x29,0x49,0x26,0x25,0x83,0x88,
const uint TONETABLE[15]={DO,RE,MI,FA,SO,LA,TI,DO_H,
RE_H,MI_H,FA_H,SO_H,LA_H,TI_H,DO_HH};
uint toneconst;
void Delayus(uint US)
0x26,0x28,0x26,0x25,0x23,0x25,0x26,0x28,
0xc5,0x04,0x04,
/*************希望*****************/
0x49,0x4a,0x4a,0x6a,0x29,0x48,0x46,0x68,
{
uint i,j;
for( i=0;i<MS;i++)
for(j=0;j<1141;j++); //1141是在8MHz晶振下,通过软件仿真反复实验得到的数值
}
/*void delay(uint t)
{
while(t--);
}*/
void init_devices(void)
0xc5,0x26,0x28,0xe5,0x83,0x65,0x26,
0x68,0x29,0x26,0x28,0x45,0x6c,0x2f,0x3d,
0x1c,0x2a,0x2c,0xe9,0x69,0x2a,0x47,0x46,
0x65,0x26,0x48,0x49,0x43,0x48,0x36,0x15,
0x29,0xc8,0x49,0x4a,0x4a,0x6a,0x2c,0x4a,
0x4a,0x49,0x4a,0xca,0x4c,0x4d,0x4d,0x6d,
0x2c,0x4a,0x4a,0x4c,0x4d,0xcc,0x49,0x4a,
0x4a,0x69,0x2a,0x4a,0x49,0x4a,0x46,
for(i=0;i<16;i++)
{
send_data(shu[i]);
//delay(10);
}
send_command(0x90);
for(i=0;i<16;i++)
0x18,0xe6,0x29,0x29,0x29,0x28,0x46,
0x29,0x29,0x29,0x28,0x46,0x49,0x4a,
0x48,0x69,0x2a,0x4c,0x2d,0x2d,0x2d,
0x2c,0x4a,0x29,0x29,0x29,0x28,0x46,
0xe5,0x4e,0x4d,0x4e,0x6c,0x2d,0x4e,
0x4d,0x2c,0x2d,0x2e,0x2d,0x6f,0x2d,
0x2c,0x2d,0x2c,0x29,0x2a,0x2b,
0x2a,0x29,0xc8,0x4c,0x4e,0x49,0x46,0x48,
0x48,0x6b,0x2a,0x4c,0x29,0x2a,0x2a,0x29,0x89,
0x8a,0x4c,0x4e,0x6 Nhomakorabea,0x2d,0x8d,0x4c,0x2c,0x2d,
0x4e,0x2d,0x2c,0xaa, 0x6b,0x2b,0x4c,0x4d,0x4c,
0x2b,0x2a,0x89,0x47,0x27,0x26,0x45,0x46,0xa8,
0x8f,0x8d,0x6b,0x2c,0x8d,0x4e,0x2e,0x2e,0x4e,
0x2d,0x2c,0xaa, 0x8f,0x8d,0x6b,0x2c,0x8d,0x4d,
0x2d,0x2d,0x4d,0x2b,0x2a,0xf9, 0x8c,0x48,0x49,0x6a,
TIMSK&=~(1<<TOIE1);// 禁止TIMER1溢出中断允许
sound_add++;
temp1=sound[sound_add];
if(sound_add==1)
{
send_command(1);
delay_nms(10);
send_command(0x80);
*修改说明:
/************************************************/
void music(void)
{
uchar i,temp=0,temp1=0;
uint sound_add=0;
TCCR1A = 0x00;
TCCR1B =(1<<CS11);//8分频
0x28,0x27,0x46,0x46,
/*****************同一首歌**************/
0x85,0x48,0x49,0x6a,0x2b,0x4a,0x48,0x89,0x48,
0x46,0xf8, 0x85,0x48,0x49,0x4a,0x2a,0x2b,0x4c,
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void)
{
TCNT1=toneconst;
#include <iom16v.h>
#include <macros.h>
#include "12864.c"
#include "math.h"
#include "stdio.h"
#define uchar unsigned char
#define uint unsigned int
{
send_data(shu[i]);
//delay(10);
}
}
if(sound_add==40 )
{
send_command(0x80);
{
uint i;
US=US*5/4; //5/4是在8MHz晶振下,通过软件仿真反复实验得到的数值
for( i=0;i<US;i++);
}
/************************************************
*函数名称: void Delayms(uint16 MS)
0x2b,0x4a,0x28,0x28,0x69,0x29,0x49,0x29,0x28,
0x46,0xc6, 0x87,0x67,0x26,0x45,0x4d,0x4c,0x29,0x29,
0x6b,0x2b,0x4b,0x2a,0x29,0xfc,
0x00};
#define TI 64522 //988
#define DO_H 64578 //1046
#define RE_H 64683 //1174
#define MI_H 64776 //1318
#define FA_H 64819 //1397
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x04; //timer interrupt sources
SREG=0x80;// //全局中断开
PORTD^=BIT(4);
}
/************************************************
*函数名称: void music(void)
*入口参数: 无
*出口参数: 无
*函数功能: 音乐播放函数
*创建时间: 2009-09-01 eleShrimp
temp--;
toneconst=TONETABLE[temp];
TCNT1=toneconst;
}
temp=temp1;
temp>>=4;
temp&=0x0f;
Delayms(temp*129);//根据SOUNDTABLE中数据的高四位*5后,为音调持续时间
0x46,0x46,0x4a,0x4d,0x4c,0x2d,0x2c,0x2b,0x2b,0x2a,
0x29,0x4a,0x46, 0x20,0x4b,0x29,0x6a,0x28,0x27,0x23,
#define SO_H 64897 //1568
#define LA_H 64966 //1760
#define TI_H 65028 //1976
#define DO_HH 65057 //2093
const uchar sound[]={ //乐曲数据表
0x40,0x4c,0x4a,0x49,0xc8,0x49,0x47,0x46,
temp1=sound[sound_add];
while(temp1!=0)
{
temp=temp1;
temp&=0x0f;
if(temp!=0)
{
TIMSK|=(1<<TOIE1);//根据SOUNDTABLE中数据的低四位选择音调频率 TOIE1是TIMER1溢出中断允许
0x46,0x45,0x46,0xe6,
/***********喀秋莎*********/
0x66,0x27,0x68,0x26,0x28,0x28,0x27,0x26,0x47,0x43,
0x67,0x28,0x69,0x27,0x29,0x29,0x28,0x27,0x46,0x46,
0x4a,0x4d,0x4c,0x2d,0x2c,0x2b,0x2b,0x2a,0x29,0x4a,
0x46,0x20,0x4b,0x29,0x6a,0x28,0x27,0x23,0x28,0x27,
extern void music(void);
#define DO 63622 //523
#define RE 63831 //587
#define MI 64017 //659
#define FA 64102 //698
#define SO 64259 //784
#define LA 64398 //880
*入口参数: uint16 MS,延时的毫秒数
*出口参数: 无
*函数功能: 延时指定毫秒(8M晶振)
*创建时间: 2009-09-01 eleShrimp
*修改说明:
/************************************************/
void Delayms(uint MS)
0x26,0x18,0xe5,0x6a,0x2c,0x47,0x49,0x26,
0x28,0x85,0x33,0x15,0x43,0x25,0x26,0x27,
0x29,0xc6,0x25,0x26,0x68,0x29,0x4c,0x4a,
0x49,0x2a,0x29,0x49,0x26,0x25,0x83,0x88,
const uint TONETABLE[15]={DO,RE,MI,FA,SO,LA,TI,DO_H,
RE_H,MI_H,FA_H,SO_H,LA_H,TI_H,DO_HH};
uint toneconst;
void Delayus(uint US)
0x26,0x28,0x26,0x25,0x23,0x25,0x26,0x28,
0xc5,0x04,0x04,
/*************希望*****************/
0x49,0x4a,0x4a,0x6a,0x29,0x48,0x46,0x68,
{
uint i,j;
for( i=0;i<MS;i++)
for(j=0;j<1141;j++); //1141是在8MHz晶振下,通过软件仿真反复实验得到的数值
}
/*void delay(uint t)
{
while(t--);
}*/
void init_devices(void)
0xc5,0x26,0x28,0xe5,0x83,0x65,0x26,
0x68,0x29,0x26,0x28,0x45,0x6c,0x2f,0x3d,
0x1c,0x2a,0x2c,0xe9,0x69,0x2a,0x47,0x46,
0x65,0x26,0x48,0x49,0x43,0x48,0x36,0x15,
0x29,0xc8,0x49,0x4a,0x4a,0x6a,0x2c,0x4a,
0x4a,0x49,0x4a,0xca,0x4c,0x4d,0x4d,0x6d,
0x2c,0x4a,0x4a,0x4c,0x4d,0xcc,0x49,0x4a,
0x4a,0x69,0x2a,0x4a,0x49,0x4a,0x46,
for(i=0;i<16;i++)
{
send_data(shu[i]);
//delay(10);
}
send_command(0x90);
for(i=0;i<16;i++)
0x18,0xe6,0x29,0x29,0x29,0x28,0x46,
0x29,0x29,0x29,0x28,0x46,0x49,0x4a,
0x48,0x69,0x2a,0x4c,0x2d,0x2d,0x2d,
0x2c,0x4a,0x29,0x29,0x29,0x28,0x46,
0xe5,0x4e,0x4d,0x4e,0x6c,0x2d,0x4e,
0x4d,0x2c,0x2d,0x2e,0x2d,0x6f,0x2d,
0x2c,0x2d,0x2c,0x29,0x2a,0x2b,
0x2a,0x29,0xc8,0x4c,0x4e,0x49,0x46,0x48,
0x48,0x6b,0x2a,0x4c,0x29,0x2a,0x2a,0x29,0x89,
0x8a,0x4c,0x4e,0x6 Nhomakorabea,0x2d,0x8d,0x4c,0x2c,0x2d,
0x4e,0x2d,0x2c,0xaa, 0x6b,0x2b,0x4c,0x4d,0x4c,
0x2b,0x2a,0x89,0x47,0x27,0x26,0x45,0x46,0xa8,
0x8f,0x8d,0x6b,0x2c,0x8d,0x4e,0x2e,0x2e,0x4e,
0x2d,0x2c,0xaa, 0x8f,0x8d,0x6b,0x2c,0x8d,0x4d,
0x2d,0x2d,0x4d,0x2b,0x2a,0xf9, 0x8c,0x48,0x49,0x6a,
TIMSK&=~(1<<TOIE1);// 禁止TIMER1溢出中断允许
sound_add++;
temp1=sound[sound_add];
if(sound_add==1)
{
send_command(1);
delay_nms(10);
send_command(0x80);
*修改说明:
/************************************************/
void music(void)
{
uchar i,temp=0,temp1=0;
uint sound_add=0;
TCCR1A = 0x00;
TCCR1B =(1<<CS11);//8分频
0x28,0x27,0x46,0x46,
/*****************同一首歌**************/
0x85,0x48,0x49,0x6a,0x2b,0x4a,0x48,0x89,0x48,
0x46,0xf8, 0x85,0x48,0x49,0x4a,0x2a,0x2b,0x4c,
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void)
{
TCNT1=toneconst;
#include <iom16v.h>
#include <macros.h>
#include "12864.c"
#include "math.h"
#include "stdio.h"
#define uchar unsigned char
#define uint unsigned int