|
发表于 2011-10-3 17:00:00
|
显示全部楼层
//我的想法请大家指正
module keyboard(output a_ou,b_ou,c_ou,print,screen,
input press_1,press_2,press_#,press_0and*,clk);
// press_1代表按1键;输出结果由以下几个信号表
示,//a_ou=0,b_ou=1,c_ou=0,print=1,screen=0,这样一组输出代表输出b
reg [1:0] state;
parameter [1:0] s_idle="00",s_a="01",s_b="10",s_c="11";
always@(posedge clk)
begin
a_ou<=0;b_ou<=0;c_ou<=0;print<=0;screen<=0;
case(state)
s_idle: if(press_1) state<=s_a;
s_a : if(press_1) begin state<=s_b; a_ou<=1; end
else if(press_2) begin state<=s_idle; a_ou<=1;screen<=1; end
else if(press_#) begin state<=s_idle; a_ou<=1;print<=1;end
else begin state<=s_a;a_ou<=1;end
s_b : if(press_1) begin state<=s_c; b_ou<=1; end
else if(press_2) begin state<=s_idle; b_ou<=1;screen<=1; end
else if(press_#) begin state<=s_idle; b_ou<=1;print<=1;end
else begin state<=s_b;b_ou<=1;end
s_c: if(press_1) begin state<=s_a; c_ou<=1; end
else if(press_2) begin state<=s_idle; c_ou<=1;screen<=1; end
else if(press_#) begin state<=s_idle; c_ou<=1;print<=1;end
else begin state<=s_c;c_ou<=1;end
default:
begin a_ou<=0;b_ou<=0;c_ou<=0;print<=0;screen<=0; end
endcase
end |
|