注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

东月之神

在单纯的观念里面,生命就容易变得比较深刻!

 
 
 

日志

 
 
关于我

别驻足,梦想要不停追逐,别认输,熬过黑暗才有日出,要记住,成功就在下一步,路很苦,汗水是最美的书!

网易考拉推荐

BASYS 2实现矩阵键盘  

2011-08-03 21:08:11|  分类: FPGA |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

主模块:

module led(clk, key_row, key_column, ledout, r, led2);
input clk;
input[3:0] key_column;
output[3:0] key_row;
output[7:0] ledout, led2;
output[3:0] r;
reg[3:0] key_scan = 0, row;
reg[25:0] n, m;

assign led2 = {key_column, key_row} ;
assign key_row = row;
always @(posedge clk)
begin
   if(m >= 100000)
 begin
  n = n + 1;
  if(n <= 300000)
  begin
   row = 4'b1110;
   if(key_column != 4'b1111)
   begin
    case(key_column )
     4'b0111: key_scan = 0;
     4'b1011: key_scan = 1;
     4'b1101: key_scan = 2;
     4'b1110: key_scan = 3;
    endcase
    m = 0;
   end
  end

  else if(n <= 600000)
  begin
   row = 4'b1101;
   if(key_column != 4'b1111)
   begin
    case(key_column )
     4'b0111: key_scan = 4;
     4'b1011: key_scan = 5;
     4'b1101: key_scan = 6;
     4'b1110: key_scan = 7;
    endcase
    m = 0;
   end
  end
 
  else if(n <= 900000)
  begin
   row = 4'b1011;
   if(key_column != 4'b1111)
   begin
    case(key_column )
     4'b0111: key_scan = 8;
     4'b1011: key_scan = 9;
     4'b1101: key_scan = 10;
     4'b1110: key_scan = 11;
    endcase
    m = 0;
   end
  end
 
  else if(n <= 1200000)
  begin
   row = 4'b0111;
   if(key_column != 4'b1111)
   begin
    case(key_column )
     4'b0111: key_scan = 12;
     4'b1011: key_scan = 13;
     4'b1101: key_scan = 14;
     4'b1110: key_scan = 15;
    endcase
    m = 0;
   end
  end
 
  else n = 0;
 end
 else
    m = m + 1;
end

weixuan ledd(.rr(r), .clk(clk), .t(key_scan), .led(ledout));
endmodule

 


数码管模块:

module weixuan(rr, clk, t, led);
input clk;
input[3:0] t;
output[3:0] rr;
output[7:0] led;
reg[7:0] led;

assign rr = 0;
always @(posedge clk)
begin
 if(t == 0)
  led = 8'b1100_0000;
 else if(t == 1)
  led = 8'b1111_1001;
 else if(t == 2)
  led = 8'b1010_0100;
 else if(t == 3)
  led = 8'b1011_0000;
 else if(t == 4)
  led = 8'b1001_1001;
 else if(t == 5)
  led = 8'b1001_0010;
 else if(t == 6)
  led = 8'b1000_0010;
 else if(t == 7)
  led = 8'b1111_1000;
 else if(t == 8)
  led = 8'b1000_0000;
 else if(t == 9)
  led = 8'b1001_1000;
 else if(t == 10)
  led = 8'b1000_1000;
 else if(t == 11)
  led = 8'b1000_0011;
 else if(t == 12)
  led = 8'b1100_0110;
 else if(t == 13)
  led = 8'b1010_0001;
 else if(t == 14)
  led = 8'b1000_0110;
 else if(t == 15)
  led = 8'b1000_1110;
end
endmodule

 

 

管脚锁定

NET "clk" LOC = B8;

NET "ledout[0]" LOC = L14;
NET "ledout[1]" LOC = H12;
NET "ledout[2]" LOC = N14;
NET "ledout[3]" LOC = N11;
NET "ledout[4]" LOC = P12;
NET "ledout[5]" LOC = L13;
NET "ledout[6]" LOC = M12;
NET "ledout[7]" LOC = N13;

NET "r[0]" LOC = K14;
NET "r[1]" LOC = M13;
NET "r[2]" LOC = J12;
NET "r[3]" LOC = F12;

NET "key_row[0]" LOC = B2;
NET "key_row[1]" LOC = A3;
NET "key_row[2]" LOC = J3;
NET "key_row[3]" LOC = B5;

NET "key_column[0]" LOC = C6;
NET "key_column[1]" LOC = B6;
NET "key_column[2]" LOC = C5;
NET "key_column[3]" LOC = B7;


NET "led2[0]" LOC = M5;
NET "led2[1]" LOC = M11;
NET "led2[2]" LOC = P7;
NET "led2[3]" LOC = P6;
NET "led2[4]" LOC = N5;
NET "led2[5]" LOC = N4;
NET "led2[6]" LOC = P4;
NET "led2[7]" LOC = G1;

  评论这张
 
阅读(179)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017