|
刚学习Verilog,有几个问题请教大家。 以前我是用VHDL做设计,现在想多学习Verilog。 下面是一段VHDL的程序:
Port ( reset : in std_logic;
clk_16m : in std_logic;
addr : in std_logic_vector(15 downto 0);
--addr : in std_logic_vector(5 downto 0);
data : inout std_logic_vector(7 downto 0);
r_w : in std_logic;
--dta : in std_logic;
cs : in std_logic;
--ds : in std_logic;
led_run : out std_logic;
ode_en : out std_logic;
wire_master_slave : out std_logic);
signal st0_1_r_reg:
std_logic_vector(7 downto 0);
process(reset,cs,r_w,addr)
--st0_1_r_reg
0x11
begin
if reset='1' then
data <= "ZZZZZZZZ";
elsif (cs='0' and addr="0000000000010001") then
if r_w'event and r_w='1' then
--read
data <= st0_1_r_reg;
end if;
else
data <= "ZZZZZZZZ";
end if;
end process;
process(reset,cs,r_w,addr)
--st0_1_r_reg
0x11
begin
if reset='1' then
st0_1_r_reg <= "00000001";
elsif (r_w='0' and addr="0000000000010001") then
if cs'event and cs='1' then
--write
st0_1_r_reg <= data;
end if;
end if;
end process;
现在我用Verilog转换上面的程序,如下:
module DECODE(Rst_n,clk_16m,addr,r_w,cs_n,
led_run,ode_en,wire_master_slave,
data);
input
Rst_n,clk_16m,addr,r_w,cs_n;
output
led_run,ode_en,wire_master_slave;
inout [7:0]
data;
reg
led_run,ode_en,wire_master_slave;
reg
[7:0]
version_reg, st0_1_r_reg;
//st0_1_r_reg
0x11
//write
always @(posedge cs_n or negedge Rst_n)
begin
if (!Rst_n)
begin
st0_1_r_reg = 8'b00000001;
end
else
begin
if (~r_w && addr==8'b0000000000010001)
st0_1_r_reg = data;
end
end
// read
always @ (posedge r_w or negedge Rst_n)
begin
if (!Rst_n)
begin
data_st0_1_r = 8'bz;
end
else
begin
if (~cs_n && addr==8'b0000000000010001)
data_st0_1_r = st0_1_r_reg;
else
data_st0_1_r = 8'bz;
end
end
// select
always @ (addr)
case (addr)
8'b0000000000000010
: data_sel = data_version;
8'b0000000000010001
: data_sel = data_st0_1_r;
8'b0000000000010010
: data_sel = data_st2_3_r;
8'b0000000000010011
: data_sel = data_st4_5_r;
8'b0000000000010100
: data_sel = data_st6_7_r;
8'b0000000000010101
: data_sel = data_st0_1_t;
8'b0000000000010110
: data_sel = data_st2_3_t;
8'b0000000000010111
: data_sel = data_st4_5_t;
8'b0000000000011000
: data_sel = data_st6_7_t;
default
: data_sel = 8'bz;
endcase
assign data = data_sel;
请问,我这样转换有什么问题吗?我老觉得有问题,但是就是看不出来。 请大家帮我看看。谢谢啊! |
|