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

共40条 4/4 |‹ 1 2 3 4 跳转至
工程师
2012-11-26 10:08:49     打赏
31楼

作业(自动演奏音乐)



源代码:

module music(clk,beep,led);       
input clk;       
output beep;
output [7:0]led;       
reg   beep_r;      
reg[7:0] state;       
reg[16:0]count_end;
reg [16:0]count;
reg[23:0]count1;
reg [7:0]led;


parameter L1=17'd95566,
          L2=17'd85121,
          L3=17'd75850,
    L4=17'd71592,
    L5=17'd85616,
    L6=17'd56818,
    L7=17'd50618,
   
    M1=17'd47774,
    M2=17'd42568,
    M3=17'd37919,
    M4=17'd35791,
    M5=17'd31888,
    M6=17'd28409,
    M7=17'd25309,
   
    H1=17'd23912,
    H2=17'd21282,
    H3=17'd18961,
    H4=17'd17897,
    H5=17'd15994,
    H6=17'd14025,
    H7=17'd12655;
          
parameter TIME = 12000000;   
         
assign beep = beep_r;     

always@(posedge clk)
begin
 count <= count + 1'b1;    
 if(count == count_end)
 begin
  count <= 17'd0;     
  beep_r <= !beep_r;    
 end
end

always @(posedge clk)
begin
 if(count1 < TIME)     
  count1 = count1 + 1'b1;
 else
 begin
  count1 = 24'd0;
  if(state == 8'd86)
   state = 8'd0;
  else
   state = state + 1'b1;
  case(state)
   8'd0,8'd1                       :count_end=M7;
    8'd2,8'd3                       :count_end=H1;
    8'd4,8'd5,8'd6                  :count_end=H2;
    8'd7,8'd8,8'd9,8'd10            :count_end=H3;
    8'd11,8'd12,8'd13,8'd14,8'd15  :count_end=H2;
    8'd17                           :count_end=M7;
    8'd18                           :count_end=M5;
    8'd19,8'd20,8'd21                :count_end=M6;
    8'd22,                          :count_end=M3;
    8'd23                           :count_end=M2;
    8'd24,8'd25,8'd26,8'd27         :count_end=M3;
    8'd28,8'd29,8'd30               :count_end=M5;
    8'd31,8'd32,8'd33               :count_end=M6;
    8'd34                           :count_end=H1;
    8'd35                           :count_end=M7;
    8'd36,8'd37                     :count_end=H1;
    8'd38,8'd39                     :count_end=H7;
    8'd40,8'd41,8'd42,8'd43         :count_end=H1;
   
   
    8'd44,8'd45                     :count_end=M7;
    8'd46,8'd47                     :count_end=H1;
    8'd48,8'd49,8'd50               :count_end=H2;
    8'd51,8'd52,8'd53,8'd54         :count_end=H3;
    8'd55,8'd56,8'd57,8'd58,8'd59   :count_end=H2;
    8'd60                           :count_end=H1;
    8'd61                           :count_end=M7;
    8'd62,8'd63                     :count_end=H1;
    8'd64,8'd65,8'd66,8'd67         :count_end=M7;
    8'd68                           :count_end=M3;
    8'd69                           :count_end=M2;
    8'd70,8'd71,8'd73               :count_end=M3;
    8'd74,8'd75,8'd76               :count_end=M5;
    8'd77,8'd78,8'd79               :count_end=M6;
    8'd80                           :count_end=L5;
    8'd81                           :count_end=L6;
    8'd82                           :count_end=M1;
    8'd83                           :count_end=M2;
    8'd84                           :count_end=M3;
    8'd85                           :count_end=M5;
    8'd86,8'd87,8'd88,8'd89         :count_end=H1;
   
  endcase
 end
end
 always@(count_end)
    begin
      case(count_end)
            L5   : led=8'b1111_1111;
    L6   : led=8'b0111_1111;
    
    
    M1,L7: led=8'b0011_1111;
    M2,M3: led=8'b0001_1111;
    M4,M5: led=8'b0000_1111;
    M6,M7: led=8'b0000_0111;
    
    H1   : led=8'b0000_0011;
    H2   : led=8'b0000_0001;
    H3   : led=8'b0000_0000;
    
    
        default :led=8'bx;
    endcase
    end
 
endmodule


实现视频:



视频地址:http://union.bokecc.com/flash/single/290666218ACBA694_5654B80E28DB3436_false_EEA982EE6B20F4D1_1/player.swf



分享源代码:music2.rar


工程师
2012-12-03 09:34:58     打赏
32楼

作业LED灯1秒闪烁

源代码:


module ledflicker(sys_clk,
                  sys_rstn,
      LED
      );
input sys_clk;
input sys_rstn;
output[7:0]LED;
reg[7:0]LED;
reg[25:0]delay_cnt;

always@(posedge sys_clk or negedge sys_rstn)
      begin
      if(!sys_rstn)
        delay_cnt<=26'd0;
     else
       begin 
         if(delay_cnt==26'd49999999)
          delay_cnt<=26'd0;
       else
       delay_cnt<=delay_cnt+1'b1;
     end
   end
always@(posedge sys_clk or negedge sys_rstn)
      begin
      if(!sys_rstn)
       LED<=8'b11111111;
    else
            begin
            if(delay_cnt==26'd49999999)
                LED<=~LED;
        else
               LED<=LED;
      end
  end
endmodule  


实现视频



视频地址:http://union.bokecc.com/flash/single/290666218ACBA694_8F2BEFD2C1601F3F_false_EEA982EE6B20F4D1_1/player.swf


源工程文件分享:
作业lLED灯1秒闪烁


高工
2012-12-03 11:03:11     打赏
33楼
是什么?来瞅瞅

工程师
2012-12-04 13:20:26     打赏
34楼
作业LCD1602显示字符

   用教程的代码改的


关键代码:
always @(char_cnt)   
begin
 case (char_cnt)
 6'd0: data_disp  = "I"; 
 6'd1: data_disp  = " "; 
 6'd2: data_disp  = "L"; 
 6'd3: data_disp  = "O"; 
 6'd4: data_disp  = "V"; 
 6'd5: data_disp  = "E"; 
 6'd6: data_disp  = " "; 
 6'd7: data_disp  = "D"; 
 6'd8: data_disp  = "I"; 
 6'd9: data_disp  = "Y"; 
 6'd10: data_disp = " "; 
 6'd11: data_disp = "F"; 
 6'd12: data_disp = "P"; 
 6'd13: data_disp = "G"; 
 6'd14: data_disp = "A"; 
 6'd15: data_disp = " "; 
 6'd16: data_disp = "W"; 
 6'd17: data_disp = "a"; 
 6'd18: data_disp = "n"; 
 6'd19: data_disp = "g"; 
 6'd20: data_disp = "1"; 
 6'd21: data_disp = "1"; 
 6'd22: data_disp = "1"; 
 6'd23: data_disp = "3"; 
 6'd24: data_disp = " ";
 6'd25: data_disp = "H";
 6'd26: data_disp = "E";
 6'd27: data_disp = "L";
 6'd28: data_disp = "L";
 6'd29: data_disp = "O";
 6'd30: data_disp = "W";
 6'd30: data_disp = " ";
 default :   data_disp =" "; 
 endcase


实现的图片:




工程文件分享:lcd1602.rar

工程师
2012-12-04 14:25:36     打赏
35楼

教程实现的功能我就不上传了,教程发有完整的工程文件


工程师
2012-12-06 12:40:27     打赏
36楼
作业LCD1602向左滚动显示字符

关键代码:
shift: begin      
     state <= set_ddram1;
     lcd_rs<=1'b0;
     lcd_data <= 8'b0001_1000;   
    end  

粉色的部分是调整向左还是向右滚动显示的:
10是向左滚动显示
01是向右滚动显示。
这是我用的LCD1602的说明书LCD1602字符手册.rar


实现的视频:




视频地址:http://union.bokecc.com/flash/single/290666218ACBA694_D45CD80219A7A26E_false_EEA982EE6B20F4D1_1/player.swf


工程文件分享:lcd1602.rar

工程师
2012-12-07 23:05:20     打赏
37楼

作业LCD12864中文显示
我的是带字库的,将文字转换为十六进制来显示的。
转换用的软件:ASCII


关键代码:
always @(posedge clkr)
begin
 current=next;
  case(current)
    set0:   begin  rs<=0; dat<=8'h31; next<=set1; end 
    set1:   begin  rs<=0; dat<=8'h0C; next<=set2; end  
    set2:   begin  rs<=0; dat<=8'h6; next<=set3; end  
    set3:   begin  rs<=0; dat<=8'h1; next<=dat0; end  

    dat0:   begin  rs<=1; dat<=8'hce; next<=dat1; end
    dat1:   begin  rs<=1; dat<=8'hd2; next<=dat2; end
    dat2:   begin  rs<=1; dat<=8'hb0; next<=dat3; end
    dat3:   begin  rs<=1; dat<=8'hae;next<=dat4; end
    dat4:   begin  rs<=1; dat<=8'hb5; next<=dat5; end
    dat5:   begin  rs<=1; dat<=8'he7; next<=dat6; end
    dat6:   begin  rs<=1; dat<=8'hd7; next<=dat7; end
    dat7:   begin  rs<=1; dat<=8'hd3;next<=dat8; end
    dat8:   begin  rs<=1; dat<=8'hb2; next<=dat9; end
    dat9:   begin  rs<=1; dat<=8'hfa;next<= dat10 ; end
   
    dat10:   begin  rs<=1; dat<=8'hc6; next<=dat11; end
    dat11:   begin  rs<=1; dat<=8'hb7; next<=dat12; end
 
    dat12:   begin  rs<=1; dat<=8'hca;next<=dat13; end
    dat13:   begin  rs<=1; dat<=8'hc0; next<=dat14; end
    dat14:   begin  rs<=1; dat<=8'hbd; next<=dat15; end
    dat15:   begin  rs<=1; dat<=8'he7; next<=set4; end

    set4:   begin  rs<=0; dat<=8'h90; next<=dat16; end

    dat16:   begin  rs<=1; dat<="D"; next<=dat17; end
    dat17:   begin  rs<=1; dat<="I"; next<=dat18; end
    dat18:   begin  rs<=1; dat<="Y"; next<=dat19; end
    dat19:   begin  rs<=1; dat<="-"; next<=dat20; end
    dat20:   begin  rs<=1; dat<="F"; next<=dat21; end
    dat21:   begin  rs<=1; dat<="P"; next<=dat22; end
    dat22:   begin  rs<=1; dat<="G"; next<=dat23; end
    dat23:   begin  rs<=1; dat<="A"; next<=dat24; end
    dat24:   begin  rs<=1; dat<=8'hbf; next<=dat25; end
    dat25:   begin  rs<=1; dat<=8'haa; next<=dat26 ; end
   
    dat26:   begin  rs<=1; dat<=8'hb7; next<=dat27; end
    dat27:   begin  rs<=1; dat<=8'ha2; next<=dat28; end 
   
    dat28:   begin  rs<=1; dat<=8'hb0; next<=dat29; end
    dat29:   begin  rs<=1; dat<=8'he5; next<=dat30; end
   
    dat30:   begin  rs<=1; dat<=8'hd6; next<=dat31; end
    dat31:   begin  rs<=1; dat<=8'hae; next<=set5 ; end

   set5:   begin  rs<=0; dat<=8'h88; next<=dat32; end


    dat32:   begin  rs<=1; dat<="L"; next<=dat33; end
    dat33:   begin  rs<=1; dat<="C"; next<=dat34; end
    dat34:   begin  rs<=1; dat<="D"; next<=dat35; end
    dat35:   begin  rs<=1; dat<="-"; next<=dat36; end
    dat36:   begin  rs<=1; dat<="1"; next<=dat37;   end
    dat37:   begin  rs<=1; dat<="2"; next<=dat38;   end

    dat38:   begin  rs<=1; dat<="8"; next<=dat39;   end
    dat39:   begin  rs<=1; dat<="6"; next<=dat40;   end
    dat40:   begin  rs<=1; dat<="4"; next<=dat41;   end
  dat41:   begin  rs<=1; dat<=""; next<=dat42;   end
    dat42:   begin  rs<=1; dat<=8'hca; next<=dat43;   end
  dat43:   begin  rs<=1; dat<=8'hb5; next<=dat44;   end
  dat44:   begin  rs<=1; dat<=8'hd1; next<=dat45;   end
  dat45:   begin  rs<=1; dat<=8'he9; next<=set6;   end
 set6:   begin  rs<=0; dat<=8'h9c; next<=dat46; end

    dat46:   begin  rs<=1; dat<="W"; next<=dat47; end
    dat47:   begin  rs<=1; dat<="a"; next<=dat48; end
    dat48:   begin  rs<=1; dat<="n"; next<=dat49; end
    dat49:   begin  rs<=1; dat<="g"; next<=dat50;   end
    dat50:   begin  rs<=1; dat<="1"; next<=dat51;   end
    dat51:   begin  rs<=1; dat<="1"; next<=dat52;   end
  dat52:   begin  rs<=1; dat<="1"; next<=dat53;   end
    dat53:   begin  rs<=1; dat<="3"; next<=nul;   end
     nul:   begin rs<=0;  dat<=8'h00;                  
              if(cnt!=2'h2)
      begin 
                       e<=0;next<=set0;cnt<=cnt+1; 
                  end 
                   else 
                     begin next<=nul; e<=1;
                    end   
              end
   default:   next=set0;
    endcase
 end
assign en=clkr|e;
assign rw=0; 


实验显示图片:





工程文件共享:作业LCD12864显示中文


工程师
2012-12-22 12:39:41     打赏
38楼

作业LCD12864显示其他图片

主要代码:

调用rom的部分:
wire [7:0] showdata;
rom rom (.address (cnt),
   .clock (sys_clk),
   .q (showdata)
   );

 
endmodule

实现图片:





工程文件分享:lcd12864_3.rar


工程师
2012-12-22 12:40:47     打赏
39楼
前几天儿子生病没有更新,谢谢斑竹的提醒

工程师
2012-12-22 14:02:19     打赏
40楼

VGA显示彩条

通过拨段开关7、8可以实现棋盘四种模式:横条、竖条、棋盘格A、棋盘格B的显示


关键代码:
//vga行、场扫描
parameter hsync_end   = 10'd95,
   hdat_begin  = 10'd143,
   hdat_end  = 10'd783,
   hpixel_end  = 10'd799,
   vsync_end  = 10'd1,
   vdat_begin  = 10'd34,
   vdat_end  = 10'd514,
   vline_end  = 10'd524;


always @(posedge clock)
begin
 vga_clk = ~vga_clk;
end

//行扫描
always @(posedge vga_clk)
begin
 if (hcount_ov)
  hcount <= 10'd0;
 else
  hcount <= hcount + 10'd1;
end
assign hcount_ov = (hcount == hpixel_end);
//场扫描
always @(posedge vga_clk)
begin
 if (hcount_ov)
 begin
  if (vcount_ov)
   vcount <= 10'd0;
  else
   vcount <= vcount + 10'd1;
 end
end
assign  vcount_ov = (vcount == vline_end);
//数据、同步信号输
assign dat_act =    ((hcount >= hdat_begin) && (hcount < hdat_end))
     && ((vcount >= vdat_begin) && (vcount < vdat_end));
assign hsync = (hcount > hsync_end);
assign vsync = (vcount > vsync_end);
assign disp_RGB = (dat_act) ?  data : 3'h00;       
always @(posedge vga_clk)
begin
 case(switch[1:0])
  2'd0: data <= h_dat;     
  2'd1: data <= v_dat;    
  2'd2: data <= (v_dat ^ h_dat);
  2'd3: data <= (v_dat ~^ h_dat);
 endcase
end

always @(posedge vga_clk) 
begin
 if(hcount < 223)
  v_dat <= 3'h7;    
 else if(hcount < 303)
  v_dat <= 3'h6;  
 else if(hcount < 383)
  v_dat <= 3'h5;  
 else if(hcount < 463)
  v_dat <= 3'h4;   
 else if(hcount < 543)
  v_dat <= 3'h3;  
 else if(hcount < 623)
  v_dat <= 3'h2;  
 else if(hcount < 703)
  v_dat <= 3'h1; 
 else
  v_dat <= 3'h0;  
end

always @(posedge vga_clk) 
begin
 if(vcount < 94)
  h_dat <= 3'h7;      
 else if(vcount < 154)
  h_dat <= 3'h6; 
 else if(vcount < 214)
  h_dat <= 3'h5;  
 else if(vcount < 274)
  h_dat <= 3'h4;   
 else if(vcount < 334)
  h_dat <= 3'h3; 
 else if(vcount < 394)
  h_dat <= 3'h2;  
 else if(vcount < 454)
  h_dat <= 3'h1;  
 else
  h_dat <= 3'h0;  
end


实现图片:

















工程文件分享:vga.rar


共40条 4/4 |‹ 1 2 3 4 跳转至

回复

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