|
//大学时候写的代码,希望对大家有所帮助
/*/////////////////////////////////////////////////////////////
ram_is61lv256的verilog代码,
/////////////////////////////////////////////////////////////*/
module ram_is61lv256
(
clk, //5Mhz clock in
sys_clk, //50Mhz clock in
delay_time, //delay time control
w_dat, //12_bit data in from ad to ram
ram_dat_16, //ram's io
addr, //ram's address
ce, //chip enable
we, //read (H) and write (L)
oe, //output enable
r_dat, //12_bit data from ram out to da
ram_rst, //rest
ram_start, //ram 转换控制端
en_read,
UB,
LB
);
input clk,ram_rst,ram_start,sys_clk;
input wire[18:0] delay_time; //delay time control
input wire[11:0] w_dat;
reg[11:0] w_dat_t;
output reg[11:0] r_dat;
inout[15:0] ram_dat_16;
output reg ce,oe,we,UB,LB;
output reg [18:0] addr; //ram address
//reg[18:0] addr_w; //write address
//reg[18:0] addr_r; //read address
output reg en_read; //en_read=1 ->enable read
reg flag; //flag=1->write ram
reg[19:0] wdat_cnt; //count write_addr
reg[19:0] rdat_cnt; //count read_addr
reg[7:0] state;
parameter Idle =8'b00000001;
parameter WRITE =8'b00000010;
parameter WRITE_1 =8'b00000100;
parameter WRITE_end =8'b00001000;
parameter WR_to_RD =8'b00010000;
parameter READ_0 =8'b00100000;
parameter READ =8'b01000000;
parameter READ_end =8'b10000000;
assign ram_dat_16=flag?{4'b000,w_dat_t}:16'hzzzz; //flag=1 -> write data
////////////////////////////////////////////////////////////////////////////////
reg[2:0] ram_start_reg;
always @ ( posedge clk or negedge ram_rst )
if(!ram_rst)
ram_start_reg <= 3'b000;
else
ram_start_reg <= {ram_start_reg[1:0],ram_start};
wire ram_start_en;
assign ram_start_en = ( ram_start_reg[2:1] == 2'b01 ) ;
///////////////////////////////////////////////////////////////////////////////
reg[1:0] state_delay;
reg[18:0] delay_time_bfore;
reg[18:0] delay_time_after;
reg en_clr;
reg[20:0]cnt;
parameter before =2'b01;
parameter after =2'b10;
always @(posedge sys_clk or negedge ram_rst)
if(!ram_rst)
begin
state_delay<=before;
en_clr<=0;
cnt<=0;
delay_time_bfore<=0;
delay_time_after<=0;
end
else begin
case(state_delay)
before: begin delay_time_bfore<=delay_time; state_delay<=after; end
after: begin delay_time_after<=delay_time; state_delay<=before; end
default;
endcase
if((delay_time_bfore-delay_time_after)!=0)
begin en_clr<=1; cnt<=0; end
//if(en_clr==1) cnt<=0;
cnt<=cnt+1;
if(cnt==3125) en_clr<=0;
end
always @(posedge clk or negedge ram_rst)
if(!ram_rst)
begin
ce<=1;
wdat_cnt<=0;
rdat_cnt<=0;
en_read<=0;
flag<=0;
state<=Idle;
ce<=1;
oe<=1;
we<=1;
UB<=0;
LB<=0;
w_dat_t<=0;
end
else begin
case(state)
Idle:
begin
if(ram_start_en==1)
begin
state<=WRITE;
flag<=0;
we<=1;
ce<=1;
oe<=1;
//UB<=0;
//LB<=0;
addr<=wdat_cnt;
end
else
begin
state<=Idle;
oe<=1;
ce<=1;
we<=1;
if(en_clr)
begin
wdat_cnt<=0;
rdat_cnt<=0;
en_read<=0;
end
end
end
WRITE:
begin
we<=0;
ce<=0;
if(wdat_cnt>=delay_time)begin wdat_cnt<=0;end
else wdat_cnt<=wdat_cnt+1;
state<=WRITE_1;
end
WRITE_1:
begin
flag<=1;
w_dat_t<=w_dat;
state<=WRITE_end;
end
WRITE_end:
begin
we<=1;
ce<=1;
flag<=0;
state<=WR_to_RD;
end
WR_to_RD:
begin
w_dat_t<=0;
if(wdat_cnt>=delay_time-1)begin en_read<=1; end
if(en_read)
begin
if(rdat_cnt>=delay_time)begin rdat_cnt<=0;end
else rdat_cnt<=rdat_cnt+1;
end
else begin r_dat<=0; rdat_cnt<=0; end
state<=READ_0;
end
READ_0:
begin
addr<=rdat_cnt;
state<=READ;
end
READ:
begin
if(en_read)
begin
ce<=0;
oe<=0;
end
else r_dat<=0;
state<=READ_end;
end
READ_end:
begin
if(en_read) r_dat<=ram_dat_16[11:0];
state<=Idle;
end
default state<=Idle;
endcase
end
endmodule |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|