當復位時,Q_out<=0;其他時輸出結果為Q_out<=in^Q_out。
T觸發器模塊,代碼:
module T_trigger(rst,in,Q_out);
input rst,in;
output Q_out;
reg Q_out;
always@(in or rst)
begin
if(!rst)Q_out<=0;
else Q_out<=in^Q_out;
end
endmodule
至於,數碼管顯示,可參考我下面的程序看看:
module shumaguan(data,rst,m1,m2);
input rst;
input[4:0]data;
output[6:0]m1,m2;
reg[6:0]m1,m2;
reg[3:0]n1,n2;
reg[7:0]db[9:0];
parameter
db[0]=7'b1000000;db[1]=7'b1111001;db[2]=7'b0100100;db[3]=7'b0110000;db[4]=7'b0011001;
db[5]=7'b0010010;db[6]=7'b0000010;db[7]=7'b1111000;db[8]=7'b0000000;db[9]=7'b0010000;
always@(data)
begin
if(!rst)
begin
m1<=db[0];
m2<=db[0];
end
else
begin
n1<=data/'d10;
n2<=data%'d10;
m1<=db[n1];
m2<=db[n2];
end
end
endmodule