这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » easyarm2131 用easyarm2131开发板演奏音乐《八月桂花香》(原

共3条 1/1 1 跳转至

easyarm2131 用easyarm2131开发板演奏音乐《八月桂花香》(原程序)

院士
2006-09-17 18:14:16     打赏
easyarm2131 用easyarm2131开发板演奏音乐《八月桂花香》(原程序)



关键词: easyarm2131     开发     演奏     音乐     八月桂花    

院士
2006-12-22 22:43:00     打赏
2楼
问 此音乐程序基于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

专家
2016-08-19 14:10:32     打赏
3楼
是螺纹的八月桂花香?!

共3条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]