Abstract
暫存器,聽起來好像很高深的東西,其實只要多個D-FF,就可以組成暫存器了。IntroductionMethod 1:使用always block
reg8.v / Verilog
1 /* 2 (C) OOMusou 2008 http://oomusou.cnblogs.com 3 4 Filename : reg8.v 5 Compiler : Quartus II 7.2 SP3 6 Description : Demo how to write 8 bit register 7 Release : 08/11/2008 1.0 8 */ 9 10 module reg8 ( 11 input clk, 12 input rst_n, 13 input en, 14 input [ 7 : 0 ] d, 15 output reg [ 7 : 0 ] q 16 ); 17 18 always @( posedge clk, negedge rst_n) begin 19 if ( ! rst_n) 20 q <= 0 ; 21 else if (en) 22 q <= d; 23 end 24 25 endmodule
Method 2:使用Mega function reg8_mf.v / Verilog
1 /* 2 (C) OOMusou 2008 http://oomusou.cnblogs.com 3 4 Filename : reg8_mf.v 5 Compiler : Quartus II 7.2 SP3 6 Description : Demo how to write 8 bit register with Mega function 7 Release : 08/11/2008 1.0 8 */ 9 10 module reg8_mf ( 11 input clk, 12 input rst_n, 13 input en, 14 input [ 7 : 0 ] d, 15 output reg [ 7 : 0 ] q 16 ); 17 18 lpm_ff # (.lpm_width( 8 )) 19 df ( 20 .clock(clk), 21 .aclr( ! rst_n), 22 .enable(en), 23 .data(d), 24 .q(q) 25 ); 26 27 endmodule
完整程式碼下載
See Also
Reference