共3条
1/1 1 跳转至页
easyarm2131 用easyarm2131开发板演奏音乐《八月桂花香》(原程序)
问
此音乐程序基于easyARM2131开发板
听起来效果不好。希望有兴趣的网友把它改好。
#include "config.h"
#define BEEP 1 << 7 // P0.7控制蜂鸣器,低电平蜂鸣
#define LED1 1 << 18 // P1.18控制LED1,低电平点亮
#define LED2 1 << 19
#define CPLIO1(LED1)\
{\
if((IO1SET&(LED1))==0) IO1SET =(LED1);\
else IO1CLR =(LED1);\
}
#define CPLIO0(BEEP) \
{\
if((IO0SET&(BEEP))==0) IO0SET =(BEEP);\
else IO0CLR =(BEEP); \
}
unsigned char rhythm; //节拍计数
/*
*********************************************************************************************************
** 函数名称 :DelayNS()
** 函数功能 :长软件延时
** 入口参数 :dly 延时参数,值越大,延时越久
** 出口参数 :无
*********************************************************************************************************
*/
void DelayNS (uint32 dly)
{
uint32 i;
for ( ; dly>0; dly--)
//for (i=0; i<50000; i++);
for (i=0; i<50; i++);
}
/*
*********************************************************************************************************
** 函数名称 :IRQ_Timer0()
** 函数功能 :定时器0中断服务程序,取反LED9控制口。
** 入口参数 :无
** 出口参数 :无
*********************************************************************************************************
*/
void __irq IRQ_Timer0 (void)
{
rhythm++;
CPLIO1(LED2);
T0IR = 0x01; /* 清除中断标志 */
VICVectAddr = 0x00; /* 通知VIC中断处理结束 */
}
/*
*********************************************************************************************************
** 函数名称 :main()
** 函数功能 :用P0.7控制BEEP,让BEEP鸣叫。
** 调试说明 :需将跳线JP5和LED短接。
*********************************************************************************************************
*/
//曲目《八月桂花香〉 音符——节拍 数组
const unsigned char music[]={
0x18, 0x30, 0x1C, 0x10,
0x20, 0x40, 0x1C, 0x10,
0x18, 0x10, 0x20, 0x10,
0x1C, 0x10, 0x18, 0x40,
0x1C, 0x20, 0x20, 0x20,
0x1C, 0x20, 0x18, 0x20,
0x20, 0x80, 0x0FF, 0x20,
0x30, 0x1C, 0x10 , 0x18,
0x20, 0x15, 0x20 , 0x1C,
0x20, 0x20, 0x20 , 0x26,
0x40, 0x20 , 0x20 , 0x2B,
0x20, 0x26, 0x20 , 0x20,
0x20, 0x30 , 0x80 , 0x0FF,
0x20, 0x20, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x20,
0x26, 0x20 , 0x2B , 0x20,
0x30, 0x20 , 0x2B , 0x40,
0x20, 0x20 , 0x1C , 0x10,
0x18, 0x10, 0x0, 0x20,
0x26, 0x20 , 0x2B, 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20 , 0x15 , 0x20,
0x1C, 0x20 , 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30 , 0x80,
0x20, 0x30, 0x1C , 0x10,
0x20, 0x10, 0x1C , 0x10,
0x20, 0x20, 0x26 , 0x20,
0x2B, 0x20, 0x30 , 0x20,
0x2B, 0x40, 0x20 , 0x15,
0x1F, 0x05, 0x20 , 0x10,
0x1C, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20 , 0x15 , 0x20,
0x1C, 0x20 , 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30, 0x30,
0x20, 0x30, 0x1C, 0x10,
0x18, 0x40, 0x1C, 0x20,
0x20, 0x20, 0x26, 0x40,
0x13, 0x60, 0x18 , 0x20,
0x15, 0x40, 0x13 , 0x40,
0x18, 0x80, 0x00,
};
int main (void)
{
int i;
PINSEL0 = 0x00000000; // 设置管脚连接GPIO
IO0DIR = BEEP; // 设置BEEP控制口为输出
PINSEL2 = PINSEL2 & (~0x08);// P1[25:16]连接GPIO
IO1DIR |= LED1; // 设置LED1控制口为输出
IO1DIR |= LED2; // 设置LED2控制口为输出
IRQEnable(); /* IRQ中断使能 */
/* 定时器0初始化 */
T0TC = 0; /* 定时器设置为0 */
T0PR = 0; /* 时钟不分频 */
T0MCR = 0x03; /* 设置T0MR0匹配后复位T0TC,并产生中断标志 */
T0MR0 = Fpclk / 150; /* 10mS胫佣ㄊ? */
//T0TCR = 0x01; /* 启动定时器 */
/* 设置定时器0中断IRQ */
VICIntSelect = 0x00; /* 所有中断通道设置为IRQ中断 */
VICVectCntl0 = 0x20 | 0x04; /* 设置定时器0中断通道分配最高优先级 */
VICVectAddr0 = (uint32)IRQ_Timer0; /* 设置中断服务程序地址 */
VICIntEnable = 1 << 0x04;
i=0;
while(1){
if(music[i]==0x00) //是结束符00H,
{ DelayNS(10);//1S
i=0;
continue;
}
else if(music[i]==0xff) //是体止符#0FFH
{
T0TCR &=~ 0x01; // stop 定时器
DelayNS(20);//100mS
}
else
{
T0TCR = 0x01; // 启动定时器
CPLIO1(LED1);//;// LED = ~LED;
do{
CPLIO0(BEEP); //输出音符
DelayNS(music[i]);
}while(music[i+1]!=rhythm);//节拍到了吗?
rhythm=0;
}
i++;
//if(music[i]==0x00)i=0;
// DelayNS(330);
// LED = ~SW1;
}
return 0;
}
答 1: 沙发做做我去试试看! 答 2: 再补充一首《祝你平安〉(51汇编格式)祝你平安
db 26h,20h,20h,20h,20h,20h,26h,10h,20h,10h,20h,80h,26h,20h,30h,20h
db 30h,20h,39h,10h,30h,10h,30h,80h,26h,20h,20h,20h,20h,20h,1ch,20h
db 20h,80h,2bh,20h,26h,20h,20h,20h,2bh,10h,26h,10h,2bh,80h,26h,20h
db 30h,20h,30h,20h,39h,10h,26h,10h,26h,60h,40h,10h,39h,10h,26h,20h
db 30h,20h,30h,20h,39h,10h,26h,10h,26h,80h,26h,20h,2bh,10h,2bh,10h
db 2bh,20h,30h,10h,39h,10h,26h,10h,2bh,10h,2bh,20h,2bh,40h,40h,20h
db 20h,10h,20h,10h,2bh,10h,26h,30h,30h,80h,18h,20h,18h,20h,26h,20h
db 20h,20h,20h,40h,26h,20h,2bh,20h,30h,20h,30h,20h,1ch,20h,20h,20h
db 20h,80h,1ch,20h,1ch,20h,1ch,20h,30h,20h,30h,60h,39h,10h,30h,10h
db 20h,20h,2bh,10h,26h,10h,2bh,10h,26h,10h,26h,10h,2bh,10h,2bh,80h
db 18h,20h,18h,20h,26h,20h,20h,20h,20h,60h,26h,10h,2bh,20h,30h,20h
db 30h,20h,1ch,20h,20h,20h,20h,80h,26h,20h,30h,10h,30h,10h,30h,20h
db 39h,20h,26h,10h,2bh,10h,2bh,20h,2bh,40h,40h,10h,40h,10h,20h,10h
db 20h,10h,2bh,10h,26h,30h,30h,80h,00H
听起来效果不好。希望有兴趣的网友把它改好。
#include "config.h"
#define BEEP 1 << 7 // P0.7控制蜂鸣器,低电平蜂鸣
#define LED1 1 << 18 // P1.18控制LED1,低电平点亮
#define LED2 1 << 19
#define CPLIO1(LED1)\
{\
if((IO1SET&(LED1))==0) IO1SET =(LED1);\
else IO1CLR =(LED1);\
}
#define CPLIO0(BEEP) \
{\
if((IO0SET&(BEEP))==0) IO0SET =(BEEP);\
else IO0CLR =(BEEP); \
}
unsigned char rhythm; //节拍计数
/*
*********************************************************************************************************
** 函数名称 :DelayNS()
** 函数功能 :长软件延时
** 入口参数 :dly 延时参数,值越大,延时越久
** 出口参数 :无
*********************************************************************************************************
*/
void DelayNS (uint32 dly)
{
uint32 i;
for ( ; dly>0; dly--)
//for (i=0; i<50000; i++);
for (i=0; i<50; i++);
}
/*
*********************************************************************************************************
** 函数名称 :IRQ_Timer0()
** 函数功能 :定时器0中断服务程序,取反LED9控制口。
** 入口参数 :无
** 出口参数 :无
*********************************************************************************************************
*/
void __irq IRQ_Timer0 (void)
{
rhythm++;
CPLIO1(LED2);
T0IR = 0x01; /* 清除中断标志 */
VICVectAddr = 0x00; /* 通知VIC中断处理结束 */
}
/*
*********************************************************************************************************
** 函数名称 :main()
** 函数功能 :用P0.7控制BEEP,让BEEP鸣叫。
** 调试说明 :需将跳线JP5和LED短接。
*********************************************************************************************************
*/
//曲目《八月桂花香〉 音符——节拍 数组
const unsigned char music[]={
0x18, 0x30, 0x1C, 0x10,
0x20, 0x40, 0x1C, 0x10,
0x18, 0x10, 0x20, 0x10,
0x1C, 0x10, 0x18, 0x40,
0x1C, 0x20, 0x20, 0x20,
0x1C, 0x20, 0x18, 0x20,
0x20, 0x80, 0x0FF, 0x20,
0x30, 0x1C, 0x10 , 0x18,
0x20, 0x15, 0x20 , 0x1C,
0x20, 0x20, 0x20 , 0x26,
0x40, 0x20 , 0x20 , 0x2B,
0x20, 0x26, 0x20 , 0x20,
0x20, 0x30 , 0x80 , 0x0FF,
0x20, 0x20, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x20,
0x26, 0x20 , 0x2B , 0x20,
0x30, 0x20 , 0x2B , 0x40,
0x20, 0x20 , 0x1C , 0x10,
0x18, 0x10, 0x0, 0x20,
0x26, 0x20 , 0x2B, 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20 , 0x15 , 0x20,
0x1C, 0x20 , 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30 , 0x80,
0x20, 0x30, 0x1C , 0x10,
0x20, 0x10, 0x1C , 0x10,
0x20, 0x20, 0x26 , 0x20,
0x2B, 0x20, 0x30 , 0x20,
0x2B, 0x40, 0x20 , 0x15,
0x1F, 0x05, 0x20 , 0x10,
0x1C, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20 , 0x15 , 0x20,
0x1C, 0x20 , 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30, 0x30,
0x20, 0x30, 0x1C, 0x10,
0x18, 0x40, 0x1C, 0x20,
0x20, 0x20, 0x26, 0x40,
0x13, 0x60, 0x18 , 0x20,
0x15, 0x40, 0x13 , 0x40,
0x18, 0x80, 0x00,
};
int main (void)
{
int i;
PINSEL0 = 0x00000000; // 设置管脚连接GPIO
IO0DIR = BEEP; // 设置BEEP控制口为输出
PINSEL2 = PINSEL2 & (~0x08);// P1[25:16]连接GPIO
IO1DIR |= LED1; // 设置LED1控制口为输出
IO1DIR |= LED2; // 设置LED2控制口为输出
IRQEnable(); /* IRQ中断使能 */
/* 定时器0初始化 */
T0TC = 0; /* 定时器设置为0 */
T0PR = 0; /* 时钟不分频 */
T0MCR = 0x03; /* 设置T0MR0匹配后复位T0TC,并产生中断标志 */
T0MR0 = Fpclk / 150; /* 10mS胫佣ㄊ? */
//T0TCR = 0x01; /* 启动定时器 */
/* 设置定时器0中断IRQ */
VICIntSelect = 0x00; /* 所有中断通道设置为IRQ中断 */
VICVectCntl0 = 0x20 | 0x04; /* 设置定时器0中断通道分配最高优先级 */
VICVectAddr0 = (uint32)IRQ_Timer0; /* 设置中断服务程序地址 */
VICIntEnable = 1 << 0x04;
i=0;
while(1){
if(music[i]==0x00) //是结束符00H,
{ DelayNS(10);//1S
i=0;
continue;
}
else if(music[i]==0xff) //是体止符#0FFH
{
T0TCR &=~ 0x01; // stop 定时器
DelayNS(20);//100mS
}
else
{
T0TCR = 0x01; // 启动定时器
CPLIO1(LED1);//;// LED = ~LED;
do{
CPLIO0(BEEP); //输出音符
DelayNS(music[i]);
}while(music[i+1]!=rhythm);//节拍到了吗?
rhythm=0;
}
i++;
//if(music[i]==0x00)i=0;
// DelayNS(330);
// LED = ~SW1;
}
return 0;
}
答 1: 沙发做做我去试试看! 答 2: 再补充一首《祝你平安〉(51汇编格式)祝你平安
db 26h,20h,20h,20h,20h,20h,26h,10h,20h,10h,20h,80h,26h,20h,30h,20h
db 30h,20h,39h,10h,30h,10h,30h,80h,26h,20h,20h,20h,20h,20h,1ch,20h
db 20h,80h,2bh,20h,26h,20h,20h,20h,2bh,10h,26h,10h,2bh,80h,26h,20h
db 30h,20h,30h,20h,39h,10h,26h,10h,26h,60h,40h,10h,39h,10h,26h,20h
db 30h,20h,30h,20h,39h,10h,26h,10h,26h,80h,26h,20h,2bh,10h,2bh,10h
db 2bh,20h,30h,10h,39h,10h,26h,10h,2bh,10h,2bh,20h,2bh,40h,40h,20h
db 20h,10h,20h,10h,2bh,10h,26h,30h,30h,80h,18h,20h,18h,20h,26h,20h
db 20h,20h,20h,40h,26h,20h,2bh,20h,30h,20h,30h,20h,1ch,20h,20h,20h
db 20h,80h,1ch,20h,1ch,20h,1ch,20h,30h,20h,30h,60h,39h,10h,30h,10h
db 20h,20h,2bh,10h,26h,10h,2bh,10h,26h,10h,26h,10h,2bh,10h,2bh,80h
db 18h,20h,18h,20h,26h,20h,20h,20h,20h,60h,26h,10h,2bh,20h,30h,20h
db 30h,20h,1ch,20h,20h,20h,20h,80h,26h,20h,30h,10h,30h,10h,30h,20h
db 39h,20h,26h,10h,2bh,10h,2bh,20h,2bh,40h,40h,10h,40h,10h,20h,10h
db 20h,10h,2bh,10h,26h,30h,30h,80h,00H
共3条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
【换取逻辑分析仪】自制底板并驱动ArduinoNanoRP2040ConnectLCD扩展板被打赏47分 | |
【分享评测,赢取加热台】RISC-V GCC 内嵌汇编使用被打赏38分 | |
【换取逻辑分析仪】-基于ADI单片机MAX78000的简易MP3音乐播放器被打赏48分 | |
我想要一部加热台+树莓派PICO驱动AHT10被打赏38分 | |
【换取逻辑分析仪】-硬件SPI驱动OLED屏幕被打赏36分 | |
换逻辑分析仪+上下拉与多路选择器被打赏29分 | |
Let'sdo第3期任务合集被打赏50分 | |
换逻辑分析仪+Verilog三态门被打赏27分 | |
换逻辑分析仪+Verilog多输出门被打赏24分 | |
【分享评测,赢取加热台】使用8051单片机驱动WS2812被打赏40分 |