Shift Register using for loop in verilog
//======================================
module shift_reg_for_loop(
input CLK,
input RST,
input DATA_IN,
output BIT_OUT,
output [7:0] BYTE_OUT
);
//shift register signals
reg [7:0] bitShiftReg;
reg [7:0] byteShiftReg[3:0]; //4 x 8bit = 4 bytes
integer i;
//shift register
always @(posedge CLK or negedge RST) begin
if (~RST) begin
bitShiftReg=8'b0000_0000;
byteShiftReg[0]=8'b0000_0000;
byteShiftReg[1]=8'b0000_0000;
byteShiftReg[2]=8'b0000_0000;
byteShiftReg[3]=8'b0000_0000;
end
else
begin
//bit shift register
bitShiftReg <= {bitShiftReg[6:0],DATA_IN};
//byte shift register
byteShiftReg[0] <= bitShiftReg;
for(i=1;i<4;i=i+1)
byteShiftReg[i] <= byteShiftReg[i-1];
end
end
//module output wires
assign BIT_OUT = bitShiftReg[7];
assign BYTE_OUT = byteShiftReg[3];
endmodule
//======================================
// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps
module Test_bench;
/*
module shift_reg_for_loop(
input CLK,
input RST,
input DATA_IN,
output BIT_OUT,
output [7:0] BYTE_OUT);
*/
// Inputs
reg CLK=1'b0, RST=1'b1;
reg DATA_IN=1'b0;
// Outputs
wire BIT_OUT ;
wire [7:0] BYTE_OUT ;
integer i;
// Instantiate the Unit Under Test (UUT)
shift_reg_for_loop UUT (CLK, RST, DATA_IN, BIT_OUT , BYTE_OUT);
initial begin
$monitor (CLK, RST, DATA_IN, BIT_OUT , BYTE_OUT);
// Initialize Inputs
#4 RST=0;
#9 RST=1;
end
always #5 CLK= ~CLK;
initial begin
for(i =0; i<=20; i=i+1)
begin
#20 DATA_IN = ~DATA_IN;
end
#20 DATA_IN =1;
#20 DATA_IN = 1;
#20 DATA_IN =0;
#20 DATA_IN =1;
#20 DATA_IN = 1;
#20 DATA_IN =0;
#20 DATA_IN =1;
#20 DATA_IN = 1;
#20 DATA_IN =0;
end
initial
begin
#420 // Final time: 300 ns
$stop;
end
endmodule
訂閱:
張貼留言 (Atom)
WOKWI DHT22 & LED , Node-Red + SQLite database
WOKWI DHT22 & LED , Node-Red + SQLite database Node-Red程式 [{"id":"6f0240353e534bbd","type":"comment&...
-
python pip 不是内部或外部命令 -- 解決方法 要安裝 Pyqt5 1. 首先,開啟命令提示字元。 2. 輸入 pip3 install pyqt5 好像不能執行 ! ! 錯誤顯示 : ‘ pip3 ’ 不是內部或外部命令、可執行的程式或批...
-
課程講義 下載 11/20 1) PPT 下載 + 程式下載 http://www.mediafire.com/file/cru4py7e8pptfda/106%E5%8B%A4%E7%9B%8A2-1.rar 11/27 2) PPT 下載...
-
• 認 識 PreFix、InFix、PostFix PreFix(前序式):* + 1 2 + 3 4 InFix(中序式): (1+2)*(3+4) PostFix(後序式):1 2 + 3 4 + * 後 序式的運算 例如: 運算時由 後序式的...
沒有留言:
張貼留言