module mul(clk,k,kc,o,comscan);//this program is powered by tance
input clk;
input [7:0]k;
input [2:0]kc;
output reg [7:0]o;
output reg [1:0]comscan;
reg [7:0]A;
reg [7:0]B;
reg [15:0]C;
reg [3:0]CR=4'b0000;
reg [3:0]show;
reg [15:0]temp;
reg _500Hz,_250Hz;
always @(posedge clk)
begin
comscan[1:0]=comscan[1:0]+1'b1;
end
always @(posedge clk)
begin
if (kc[2]!=1) //kc【2】爲開始運算控制
begin
case(kc[1:0])
2'b01:begin B[7:0]<=k[7:0];temp[7:0]<=k[7:0];end
2'b10:begin C[7:0]<=k[7:0];temp[15:8]<=k[7:0];end
default:begin C[7:0]<=temp[15:8];B[7:0]<=temp[7:0];end
endcase
end
else
begin
if(CR<4'b1000)
begin
if (C[0]==1)
begin
C[15:8]=C[15:8]+B[7:0];
C=(C>>1);
CR=CR+1'b1;
end
else
begin
C=(C>>1);
CR=CR+1'b1;
end
end
else
begin
case(comscan[1:0]) //如果顯示倒序,請改下面的參數
2'b00:show[3:0]<=C[15:12];
2'b01:show[3:0]<=C[11:8];
2'b10:show[3:0]<=C[7:4];
2'b11:show[3:0]<=C[3:0];
endcase
end
end
end
always @(1)
begin
case(show[3:0])
4'b0000:o[7:0]<=8'h3f;//0
4'b0001:o[7:0]<=8'h06;//1
4'b0010:o[7:0]<=8'h5b;//2
4'b0011:o[7:0]<=8'h4f;//3
4'b0100:o[7:0]<=8'h66;//4
4'b0101:o[7:0]<=8'h6d;//5
4'b0110:o[7:0]<=8'h7d;//6
4'b0111:o[7:0]<=8'h07;//7
4'b1000:o[7:0]<=8'h7f;//8
4'b1001:o[7:0]<=8'h6f;//9
4'b1010:o[7:0]<=8'h77;//a
4'b1011:o[7:0]<=8'h7c;//b
4'b1100:o[7:0]<=8'h39;//v
4'b1101:o[7:0]<=8'h5e;//d
4'b1110:o[7:0]<=8'h79;//e
4'b1111:o[7:0]<=8'h71;//f
endcase
end
endmodule