This is my code
Code:`timescale 1 ns / 1 ps
module IC74LS160 (Pin_Pe,Pin_P0,Pin_P1,Pin_P2,Pin_P3,Pin_Cep,Pin_Cet,Pin_Reset,Pin_Q0,Pin_Q1,Pin_Q2,Pin_Q3,Pin_Tc,Pin_Clk);
input Pin_Pe,Pin_Cep,Pin_Cet,Pin_Reset,Pin_P0,Pin_P1,Pin_P2,Pin_P3,Pin_Clk;
output Pin_Q0,Pin_Q1,Pin_Q2,Pin_Q3,Pin_Tc;
reg Pin_Q0,Pin_Q1,Pin_Q2,Pin_Q3;
reg [3:0]dem;
initial
dem = 0;
always @(posedge Pin_Clk)
begin
casex ({Pin_Reset,Pin_Pe,Pin_Cet,Pin_Cep})
//Neu Chan Reset khong tich cuc va chan PE tich cuc thi load cac gia tri hien tai cua chan Pi vao chan Qi
4'b10xx:
begin
Pin_Q0 = Pin_P0;
Pin_Q1 = Pin_P1;
Pin_Q2 = Pin_P2;
Pin_Q3 = Pin_P3;
dem[0] = Pin_Q0;
dem[1] = Pin_Q1;
dem[2] = Pin_Q2;
dem[3] = Pin_Q3;
end
//Neu Binh thuong thi dem binh thuong
4'b1111:
begin
if (dem <9)
begin
dem = dem + 1;
Pin_Q0 = dem[0];
Pin_Q1 = dem[1];
Pin_Q2 = dem[2];
Pin_Q3 = dem[3];
end
end
//Neu Chan Reset tich cuc
4'b0xxx:
begin
dem = 0;
Pin_Q0 = 1'b0;
Pin_Q1 = 1'b0;
Pin_Q2 = 1'b0;
Pin_Q3 = 1'b0;
end
endcase
//I don't want to excute second "case ...endcase " statement
//when the program excuted first "case ...endcase" statement
//I want the program will exit out of "Always" block
//when the program excuted first "case...endcase" statement
case({Pin_Q0,Pin_Q1,Pin_Q2,Pin_Q3})
//Neu Dem den 9 thi tro ve 0 trong xung ke
4'b1001:
begin
dem = 0;
Pin_Q0 = 1'b0;
Pin_Q1 = 1'b0;
Pin_Q2 = 1'b0;
Pin_Q3 = 1'b0;
end
//Neu ban dau o 11 thi tro ve 6 trong xung ke
4'b1101:
begin
dem = 6;
Pin_Q0 = 1'b0;
Pin_Q1 = 1'b1;
Pin_Q2 = 1'b1;
Pin_Q0 = 1'b0;
end
//Neu ban dau o 13 thi tro ve 4 trong xung ke
4'b1011:
begin
dem = 4;
Pin_Q0 = 1'b0;
Pin_Q1 = 1'b0;
Pin_Q2 = 1'b1;
Pin_Q3 = 1'b0;
end
//Neu bat dau o 15 thi tro ve 2 trong xung ke
4'b1111:
begin
dem = 2;
Pin_Q0 = 1'b0;
Pin_Q1 = 1'b1;
Pin_Q2 = 1'b0;
Pin_Q3 = 1'b0;
end
//Neu ban dau o 10 thi nhay len 11 trong xung ke
4'b0101:
begin
Pin_Q0 = 1'b1;
Pin_Q1 = 1'b1;
Pin_Q2 = 1'b0;
Pin_Q3 = 1'b1;
end
//Neu ban dau la 12 thi nhay len 13 trong xung ke
4'b0011:
begin
Pin_Q0 = 1'b1;
Pin_Q1 = 1'b0;
Pin_Q2 = 1'b1;
Pin_Q3 = 1'b1;
end
//Neu ban dau la 14 thi nhay len 15 trong xung ke
4'b0111:
begin
Pin_Q0 = 1'b1;
Pin_Q1 = 1'b1;
Pin_Q2 = 1'b1;
Pin_Q3 = 1'b1;
end
endcase
end
endmodule
Thanks for your helping....