这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 电子DIY » bingxue1682002进程贴

共11条 2/2 1 2 跳转至
菜鸟
2013-03-29 17:10:16     打赏
11楼


视频地址:http://player.youku.com/player.php/sid/XNTM0NTQ0NzQ4/v.swf

乐曲自动演奏

module key_piano(sys_clk    ,
                 sys_rstn   ,
                 key_in     ,
                 beep);
                 
input               sys_clk      ;
input               sys_rstn     ;
input    [7:0]      key_in       ;
output              beep         ;


reg                 beep         ;
reg      [15:0]     delay_cnt    ;
reg      [15:0]     delay_end    ;
reg      [24:0]     delay_1s     ;
reg      [5:0]      auto         ;


always@(posedge sys_clk or negedge sys_rstn)
begin
    if(!sys_rstn)
       delay_cnt<=16'd0;
    else
       if((delay_cnt==delay_end)&(!(delay_end==16'hffff)))
          begin
              delay_cnt<=16'd0;
              beep<=~beep;
          end
       else
          delay_cnt<=delay_cnt+1'b1;
end
always@(posedge sys_clk or negedge sys_rstn)
begin
     if(!sys_rstn)
        delay_1s<=25'd0;
      else
         begin
             if(delay_1s==25'd24999999)
                delay_1s<=25'd0;
             else
                 delay_1s<=delay_1s+1'd1;
          end
end
always@(posedge sys_clk or negedge sys_rstn)
begin
    if(!sys_rstn)
       auto<=6'd0;
    else
       begin
           if(delay_1s==25'd24999999)
              begin
                  if(auto==6'd38)
                     auto<=6'd0;
                  else
                     auto<=auto+1'b1;
              end
           else
              auto<=auto;
       end
end
always@(posedge sys_clk or negedge sys_rstn)
begin
    case(auto)
         6'd00:delay_end = 16'd47774;//1
         6'd01:delay_end = 16'd42568;//2
         6'd02:delay_end = 16'd37919;//3
         6'd03:delay_end = 16'd47774;//1
         6'd04:delay_end = 16'd65535;
         6'd05:delay_end = 16'd47774;//1
         6'd06:delay_end = 16'd42568;//2
         6'd07:delay_end = 16'd37919;//3
         6'd08:delay_end = 16'd47774;//1
         6'd09:delay_end = 16'd65535;
         6'd10:delay_end = 16'd37919;//3
         6'd11:delay_end = 16'd35791;//4
         6'd12:delay_end = 16'd31888;//5
         6'd13:delay_end = 16'd65535;
         6'd14:delay_end = 16'd37919;//3
         6'd15:delay_end = 16'd35791;//4
         6'd16:delay_end = 16'd31888;//5
         6'd17:delay_end = 16'd65535;
         6'd18:delay_end = 16'd31888;//5
         6'd19:delay_end = 16'd28409;//6
         6'd20:delay_end = 16'd31888;//5
         6'd21:delay_end = 16'd35791;//4
         6'd22:delay_end = 16'd37919;//3
         6'd23:delay_end = 16'd47774;//1
         6'd24:delay_end = 16'd65535;
         6'd25:delay_end = 16'd31888;//5
         6'd26:delay_end = 16'd28409;//6
         6'd27:delay_end = 16'd31888;//5
         6'd28:delay_end = 16'd35791;//4
         6'd29:delay_end = 16'd37919;//3
         6'd30:delay_end = 16'd47774;//1
         6'd31:delay_end = 16'd65535;
         6'd32:delay_end = 16'd47774;//1
         6'd33:delay_end = 16'd31888;//5
         6'd34:delay_end = 16'd47774;//1
         6'd35:delay_end = 16'd65535;
         6'd36:delay_end = 16'd47774;//1
         6'd37:delay_end = 16'd31888;//5
         6'd38:delay_end = 16'd47774;//1
       default:delay_end = 16'd65535;
     endcase
end                      
endmodule


共11条 2/2 1 2 跳转至

回复

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