- UID
- 1029342
- 性别
- 男
|
module keyscan(kbrow,seg7_out,scan,clk,start,kbcol);
output [3:0]kbrow; //列扫描信号
output [6:0] seg7_out;
output [7:0] scan;
input clk,start;
input [3:0] kbcol;
reg [3:0] kbrow;
reg [6:0] seg7_out;
reg [7:0] scan;
reg [1:0] count;
reg [1:0] sta;
reg [6:0] seg7;
reg [4:0] dat;
regfn; //按键标志位,判断是否有键被按下
initialscan<='b10000000; //只使用一个数码管显示
[email=always@%28posedge]always@(posedge[/email]clk) //循环扫描计数器
begin
if(start==0)
begin seg7<='b0000000;end
else
begin
count<=count+1;
case(count) //循环列扫描
2'b00: beginkbrow<='b0001;sta<='b00;end
2'b01: beginkbrow<='b0010;sta<='b01;end
2'b10: beginkbrow<='b0100;sta<='b10;end
2'b11: beginkbrow<='b1000;sta<='b11;end
endcase
case(sta) //行扫描译码
2'b00:begin
case(kbcol)
4'b0001: beginseg7<='b1111001;dat<='b00011;end
4'b0010: beginseg7<='b1101101;dat<='b00010;end
4'b0100: beginseg7<='b0110000;dat<='b00001;end
4'b1000: beginseg7<='b1111110;dat<='b00000;end
default: beginseg7<='b0000000;dat<='b11111;end
endcase
end
2'b01:begin
case(kbcol)
4'b0001: beginseg7<='b1110000;dat<='b00111;end
4'b0010: beginseg7<='b1011111;dat<='b00110;end
4'b0100: beginseg7<='b1011011;dat<='b00101;end
4'b1000: beginseg7<='b0110011;dat<='b00100;end
default: beginseg7<='b0000000;dat<='b11111;end
endcase
end
2'b10:begin
case(kbcol)
4'b0001: beginseg7<='b0011111;dat<='b01011;end
4'b0010: beginseg7<='b1110111;dat<='b01010;end
4'b0100: beginseg7<='b1111011;dat<='b01001;end
4'b1000: beginseg7<='b1111111;dat<='b01000;end
default: beginseg7<='b0000000;dat<='b11111;end
endcase
end
2'b11:begin
case(kbcol)
4'b0001: beginseg7<='b1000111;dat<='b01111;end
4'b0010: beginseg7<='b1001111;dat<='b01110;end
4'b0100: beginseg7<='b0111101;dat<='b01101;end
4'b1000: beginseg7<='b1001110;dat<='b01100;end
default: beginseg7<='b0000000;dat<='b11111;end
endcase
end
default:seg7<='b0000000;
endcase
end
end
always
beginfn<=~(dat[0]&dat[1]&dat[2]&dat[3]&dat[4]);end//产生按键标志位,用于存储按键信息
[email=always@%28posedge]always@(posedge[/email]fn) //按键信息存储
begin seg7_out<=seg7;end
endmodule |
|