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

共40条 3/4 1 2 3 4 跳转至
工程师
2012-11-11 10:35:40     打赏
21楼
 作业(LED向左跑马灯)


关键代码:
always@(posedge  sys_clk)
count=count+1;
assign clk=count[24];
always@(posedge clk)
 begin
  case(state)
  3'b000:led=8'b01111111;
  3'b001:led=8'b10111111;
  3'b010:led=8'b11011111;
  3'b011:led=8'b11101111;
  3'b100:led=8'b11110111;
  3'b101:led=8'b11111011;
  3'b110:led=8'b11111101;
  3'b111:led=8'b11111110;
  endcase
   state=state+1;
 end


运行视频:



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



源程序分享:LED_pao1.rar

工程师
2012-11-11 10:47:09     打赏
22楼
作业(SW控制数码管输出1—8)

没有信号是显示F

关键代码:
always@(posedge clk or negedge rstn)
 begin
  case(sw)
      8'b11111111:sm_seg=8'h8e;//f
          8'b11111110: sm_seg=8'hf9;//1
          8'b11111101: sm_seg=8'ha4;//2
          8'b11111011: sm_seg=8'hb0;//3
          8'b11110111: sm_seg=8'h99;//4
          8'b11101111: sm_seg=8'h92;//5
          8'b11011111: sm_seg=8'h82;//6
          8'b10111111: sm_seg=8'hf8;//7
          8'b01111111: sm_seg=8'h80;//8
          endcase
        
  end 
  assign sm_dig=8'b00000000;

运行视频



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



源代码分享:swshumaguan.rar

工程师
2012-11-11 11:01:21     打赏
23楼
作业(数码管60记数器)


关键代码:
//-------------------设定扫描频率-------------------------------

always @(posedge clk or negedge rstn)
 if(!rstn) delay<=26'd0;
 else
 begin
  if(delay==26'd24999999)
  begin
  delay_1s<=~delay_1s;
  delay<=26'd0;
  end
  else
   begin
   delay<=delay+1'b1;
   end
 end
always @(posedge clk or negedge rstn)
 if(!rstn) delay_1k<=15'd0;
 else
 if(delay_1k==15'd4999)
  begin
  cnt<=~cnt;
  delay_1k<=15'd0;
  end
 else
 delay_1k<=delay_1k+1'b1;
//----------------60 S 计数器------------------------------

always@(posedge delay_1s or negedge rstn)
 if(!rstn) begin
  num_ge<=4'd0;
  num_shi<=3'd0;
  end
  else
  begin
   if(num_ge==4'd9&&num_shi<3'd5)
   begin
    num_ge<=4'd0;
    num_shi<=num_shi+3'd1;
    end
  else if(num_ge==4'd9&&num_shi==3'd5)
    begin
    num_ge<=4'd0;
    num_shi<=3'd0;
    end
   else
   begin
   num_ge<=num_ge+4'd1;
   end
  end


运行视频



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


源代码分享:jishu60.rar

工程师
2012-11-13 09:40:28     打赏
24楼
实验九(按键控制LED)


关键源代码:
always@(posedge clk or negedge rstn)
     begin
   if(!rstn)
   LED<=1'b1;
   else if(!key_in)
   LED<=~LED;
   else
   LED<=LED;
   end

实现视频:



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



分享源程序:anjiankongLED.rar

工程师
2012-11-13 11:27:38     打赏
25楼
作业(按键控制数码管输出0——9)
  

关键代码:
always@(posedge clk or negedge rstn)
     begin
     if(!rstn)
     disp_dat<=3'd0;
     else
   begin
      if(key_in)
    disp_dat<=disp_dat+1'b1;
  else if(disp_dat>=4'ha)
      disp_dat<=4'h0;
    else
     case(disp_dat)
        4'h9:sm_seg=8'h90;//9
    4'h8:sm_seg=8'h80;//8
    4'h7:sm_seg=8'hf8;//7
    4'h6:sm_seg=8'h82;//6
    4'h5:sm_seg=8'h92;//5
    4'h4:sm_seg=8'h99;//4
    4'h3:sm_seg=8'hb0;//3
    4'h2:sm_seg=8'ha4;//2
    4'h1:sm_seg=8'hf9;//1
    4'h0:sm_seg=8'hc0;//0     
       endcase      
   end
   end

视频分享:








源程序分享:anjiankongshumguan1-9.rar


工程师
2012-11-14 09:58:41     打赏
26楼
实验十(消抖KEY控制LED)

关键代码:
always@(posedge clk or negedge rstn)
   begin
     if(!rstn)
     key_samp<=1'b1;
   else
      key_samp<=key_in;
 end
always@(posedge clk or negedge rstn)
  begin
   if(!rstn)
  key_samp_r<=1'b1;
 else
   key_samp_r<=key_samp;
 end
assign key_scan=key_samp_r&(~key_samp);
always@(posedge clk or negedge rstn)
   begin
   if(!rstn)
      cnt<=20'h0;
  else if(key_scan)
  cnt<=20'h0;
  else
   cnt<=cnt+1'b1;
 end
always@(posedge clk or negedge rstn)
   begin
    if(!rstn)
   key_rstn<=1'b1;
   else if(cnt<=20'hfffff)
    key_rstn<=key_in;
 end
always@(posedge clk or negedge rstn)
    begin
     if(!rstn)
     key_rstn_r<=1'b1;
   else
    key_rstn_r<=key_rstn;
  end
assign key_low=key_rstn_r&(~key_rstn);

实现的视频:



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





程序分享:xiaodouanjiankongzhiLED.rar



工程师
2012-11-14 10:34:39     打赏
27楼
作业(按键消抖控制数码管循环显示0—9)


关键代码:
always@(posedge clk or negedge rstn)
   begin
     if(!rstn)
     key_samp<=1'b1;
   else
      key_samp<=key_in;
 end
always@(posedge clk or negedge rstn)
  begin
   if(!rstn)
  key_samp_r<=1'b1;
 else
   key_samp_r<=key_samp;
 end
assign key_scan=key_samp_r&(~key_samp);
always@(posedge clk or negedge rstn)
   begin
   if(!rstn)
      cnt<=20'h0;
  else if(key_scan)
  cnt<=20'h0;
  else
   cnt<=cnt+1'b1;
 end
always@(posedge clk or negedge rstn)
   begin
    if(!rstn)
   key_rstn<=1'b1;
   else if(cnt<=20'hfffff)
    key_rstn<=key_in;
 end
always@(posedge clk or negedge rstn)
    begin
     if(!rstn)
     key_rstn_r<=1'b1;
   else
    key_rstn_r<=key_rstn;
  end
assign key_low=key_rstn_r&(~key_rstn);
always@(posedge clk or negedge rstn)
     begin
     if(!rstn)
     disp_dat<=3'd0;
     else
   begin
      if(key_low)
    disp_dat<=disp_dat+1'b1;
  else if(disp_dat>=4'ha)
      disp_dat<=4'h0;
    else
     case(disp_dat)
        4'h9:sm_seg=8'h90;//9
    4'h8:sm_seg=8'h80;//8
    4'h7:sm_seg=8'hf8;//7
    4'h6:sm_seg=8'h82;//6
    4'h5:sm_seg=8'h92;//5
    4'h4:sm_seg=8'h99;//4
    4'h3:sm_seg=8'hb0;//3
    4'h2:sm_seg=8'ha4;//2
    4'h1:sm_seg=8'hf9;//1
    4'h0:sm_seg=8'hc0;//0     
       endcase      
   end
   end
endmodule

实现视频:






程序分享:xiaodouanjiankongshumguan1-9.rar

工程师
2012-11-26 09:38:41     打赏
28楼
实验十一(救护车声音)


实验代码:
module beep(clk,
            rstn,
    beep
    );
input clk;
input rstn;
output beep;
reg beep;
reg [24:0] div_cnt;
reg [14:0] delay_cnt;
wire [14:0] delay_end;
parameter clk_divider0=56817;
parameter clk_divider1=28408;
assign delay_end=div_cnt[24] ? clk_divider0:clk_divider1;
always @(posedge clk or negedge rstn)
  begin
      if (!rstn)
     div_cnt<=25'd0;
  else
     div_cnt<=div_cnt+1'b1;
 end
always @(posedge clk or negedge rstn)
    begin
     if (!rstn)
    delay_cnt<=delay_end;
   else if(delay_cnt==15'b0)
       begin
       beep<=~beep;
    delay_cnt<=delay_end;
     end
   else
  delay_cnt<=delay_cnt-1'b1;
 end
endmodule

实现视频:



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

源工程文件分享:jiuhuche1.rar




工程师
2012-11-26 09:43:59     打赏
29楼
作业(警车声音)


源代码:

module fengming(clk, beep);   
input clk;   
output beep;   
reg beep; 
reg [27:0] tone;
    reg [14:0] counter;
always @(posedge clk)
begin
    tone <= tone+1;
end     
wire [6:0] fastsweep = (tone[22] ? tone[21:15] : ~tone[21:15]);   
wire [6:0] slowsweep = (tone[25] ? tone[24:18] : ~tone[24:18]);   
wire [14:0] clkdivider = {2'b01, (tone[27] ? slowsweep : fastsweep), 6'b000000};   
 
always @(posedge clk)
 begin
 if(counter==0) counter <= clkdivider;
 else counter <= counter-1;
 end     
always @(posedge clk)
begin
if(counter==0)
beep <= ~beep;
end    
endmodule 



实现视频:



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



分享源代码:jingche.rar

工程师
2012-11-26 09:52:15     打赏
30楼

实验十二(简易电子琴)


源代码:

module qing(clk,key,beep,led);
input clk;                 
input[7:0]key;              
output beep;             
output[7:0] led;
reg beep_reg;           
reg[7:0]key_reg;
reg[22:0]counter,count_end;
reg key_flg;

 initial key_flg = 1'b0;
 always@(posedge clk)
 begin
  counter = counter + 1;
  if(counter==count_end)
  begin
   counter = 0;  
   if(key_flg==1'b1)
    beep_reg = ~beep_reg;
   else beep_reg = 1'b0;
  end
 end
 always@(counter[10:9])
 begin
  key_reg = key;
  if(key_reg!=8'hff)key_flg = 1'b1;
  else key_flg = 1'b0;
  case(key_reg)
    8'b11111110: count_end=20'd47774;
          8'b11111101: count_end=20'd42568;
          8'b11111011: count_end=20'd37919;
          8'b11110111: count_end=20'd35791;
          8'b11101111: count_end=20'd31888;
          8'b11011111: count_end=20'd28409;
          8'b10111111: count_end=20'd25309;
          8'b01111111: count_end=20'd23912;
          8'b01111110: count_end=20'd21282;
          8'b01111101: count_end=20'd18961;
          8'b01111011: count_end=20'h17897;
          8'b01110111: count_end=20'd15944;
          8'b01011111: count_end=20'd14205;
          8'b00111111: count_end=20'd12655;
              default: count_end=20'hfffff;
  endcase
 end
 assign beep = beep_reg;
 assign led = ~key_reg;
endmodule


实现视频:



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






分享源代码:yinjiandianziqing.rar


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

回复

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