27,382
社区成员
发帖
与我相关
我的任务
分享
module SimHex(Hhigh,Hlow,buffer,bufH,bufL);
input Hhigh,Hlow;
output reg[3:0] bufH,bufL;
output reg[7:0] buffer;
reg[3:0] D;
parameter f=4'b0000;
parameter t=4'b0001;
parameter HF=4'b1111;
always @(bufH or buffer) begin//high-bit counter in hexdecimal
case(bufH)
4'b0000:bufH<=4'b0001;
4'b0001:bufH<=4'b0010;
4'b0010:bufH<=4'b0011;
4'b0011:bufH<=4'b0100;
4'b0100:bufH<=4'b0101;
4'b0101:bufH<=4'b0110;
4'b0110:bufH<=4'b0111;
4'b0111:bufH<=4'b1000;
4'b1000:bufH<=4'b1001;
4'b1001:bufH<=4'b1010;
4'b1010:bufH<=4'b1011;
4'b1011:bufH<=4'b1100;
4'b1100:bufH<=4'b1101;
4'b1101:bufH<=4'b1110;
4'b1110:bufH<=4'b1111;
4'b1111:bufH<=4'b0000;
default:bufH<=4'b0000;
endcase
end
always @(buffer) begin//low-bit counter in hexdecimal
case(bufL)
4'b0000:bufL<=4'b0001;
4'b0001:bufL<=4'b0010;
4'b0010:bufL<=4'b0011;
4'b0011:bufL<=4'b0100;
4'b0100:bufL<=4'b0101;
4'b0101:bufL<=4'b0110;
4'b0110:bufL<=4'b0111;
4'b0111:bufL<=4'b1000;
4'b1000:bufL<=4'b1001;
4'b1001:bufL<=4'b1010;
4'b1010:bufL<=4'b1011;
4'b1011:bufL<=4'b1100;
4'b1100:bufL<=4'b1101;
4'b1101:bufL<=4'b1110;
4'b1110:bufL<=4'b1111;
4'b1111:bufL<=4'b0000;
default:bufL<=4'b0000;
endcase
end
always @(Hhigh or Hlow) begin
buffer<={bufH,bufL};
bufH<=buffer>>4;
bufL<=buffer;
end
endmodule
module SimHex(Hout,Hctrl,Lctrl,Lout,buffer);
input Hctrl,Lctrl;
output reg[3:0] Hout,Lout;
output reg[7:0] buffer;
reg[3:0] Hin,Lin;
reg[3:0] bufH,bufL;
/*parameter f=4'b0000;
parameter t=4'b0001;
parameter HF=4'b1111;*/
always @(Hin or bufH) begin//high-bit counter in hexdecimal
case(Hin)
4'b0000:bufH<=4'b0001;
4'b0001:bufH<=4'b0010;
4'b0010:bufH<=4'b0011;
4'b0011:bufH<=4'b0100;
4'b0100:bufH<=4'b0101;
4'b0101:bufH<=4'b0110;
4'b0110:bufH<=4'b0111;
4'b0111:bufH<=4'b1000;
4'b1000:bufH<=4'b1001;
4'b1001:bufH<=4'b1010;
4'b1010:bufH<=4'b1011;
4'b1011:bufH<=4'b1100;
4'b1100:bufH<=4'b1101;
4'b1101:bufH<=4'b1110;
4'b1110:bufH<=4'b1111;
4'b1111:bufH<=4'b0000;
default:bufH<=4'b0000;
endcase
end
always @(Lin or bufL) begin//low-bit counter in hexdecimal
case(Lin)
4'b0000:bufL<=4'b0001;
4'b0001:bufL<=4'b0010;
4'b0010:bufL<=4'b0011;
4'b0011:bufL<=4'b0100;
4'b0100:bufL<=4'b0101;
4'b0101:bufL<=4'b0110;
4'b0110:bufL<=4'b0111;
4'b0111:bufL<=4'b1000;
4'b1000:bufL<=4'b1001;
4'b1001:bufL<=4'b1010;
4'b1010:bufL<=4'b1011;
4'b1011:bufL<=4'b1100;
4'b1100:bufL<=4'b1101;
4'b1101:bufL<=4'b1110;
4'b1110:bufL<=4'b1111;
4'b1111:bufL<=4'b0000;
default:bufL<=4'b0000;
endcase
end
always @(Hctrl or Lctrl) begin
Hin<=bufH;
Hout<=bufH;
//Hin<=Hout;
Lin<=bufL;
Lout<=bufL;
//Lin<=Lout;
buffer<={Hout,Lout};
end
endmodule