|
本帖最后由 huangyijunok 于 2010-12-16 22:46 编辑
主程序:
module writing ( reset,clk,address,data,sda,ack ) ;
input reset ,clk ;
input[7:0] address,data ;
inout sda,ack;
reg link_write ;
reg [3:0] state ;
reg [4:0] sh8out_state;
reg [7:0] sh8out_buf ;
reg finish_F;
reg ack;
parameter
idle = 0 , addr_write = 1 ,data_write = 2 , stop_ack = 3 ;
parameter
bit0 = 1 , bit1 = 2 ,bit2 = 3 ,bit3 = 4 ,bit4 = 5 ,bit5 = 6 ,bit6 = 7 ,bit7 = 8 ;
assign sda = link_write ? sh8out_buf[7]:1'bz;
always @ ( posedge clk )
begin
if( !reset )
begin
link_write <= 0 ;
state <= idle ;
finish_F <= 0 ;
sh8out_state <= idle ;
ack <= 0 ;
sh8out_buf <= 0 ;
end
else
case ( state )
idle :
begin
link_write <= 0 ;
finish_F <=0 ;
sh8out_state <= idle ;
ack <= 0 ;
sh8out_buf <= address ;
state <= addr_write ;
end
addr_write:
begin
if ( finish_F == 0 )
begin shift8_out ;
end
else
begin
sh8out_state <= idle ;
sh8out_buf <= data ;
state <= data_write ;
finish_F <= 0 ;
end
end
data_write:
begin
if(finish_F == 0)
begin
shift8_out ;
end
else
begin
link_write <= 0 ;
state <= stop_ack ;
finish_F <= 0 ;
ack <= 1 ;
end
end
stop_ack:
begin
ack <= 0 ;
state <= idle ;
end
endcase
end
task shift8_out ;
begin
case ( sh8out_state )
idle :
begin
link_write <= 1 ;
sh8out_state <= bit7 ;
end
bit7:
begin
link_write <= 1 ;
sh8out_state <=bit6 ;
sh8out_buf <= sh8out_buf << 1 ;
end
bit6:
begin
sh8out_state <= bit5;
sh8out_buf <= sh8out_buf << 1 ;
end
bit5:
begin
sh8out_state <=bit4;
sh8out_buf <= sh8out_buf << 1 ;
end
bit4:
begin
sh8out_state <=bit3;
sh8out_buf <= sh8out_buf << 1 ;
end
bit3:
begin
sh8out_state <=bit2;
sh8out_buf <= sh8out_buf << 1 ;
end
bit2:
begin
sh8out_state <=bit1;
sh8out_buf <= sh8out_buf << 1 ;
end
bit1:
begin
sh8out_state <=bit0;
sh8out_buf <= sh8out_buf << 1 ;
end
bit0:
begin
link_write <= 0 ;
finish_F <= 1 ;
end
endcase
end
endtask
endmodule
测试程序:
`timescale 1 ps/ 1 ps
`define clk_cycle 50
module writing_vlg_tst();
reg [7:0] address;
reg clk;
reg [7:0] data;
reg reset;
// wires
wire ack;
wire sda;
assign #`clk_cycle clk = ~clk ;
writing i1 (
// port map - connection between master ports and signals/registers
.ack(ack),
.address(address),
.clk(clk),
.data(data),
.reset(reset),
.sda(sda)
);
initial
begin
clk = 0 ;
reset = 1 ;
data = 0 ;
address = 0 ;
#( 2*`clk_cycle ) reset = 0 ;
#( 2*`clk_cycle ) reset = 1 ;
#( 100*`clk_cycle ) $stop ;
end
always @ ( posedge ack )
begin
data = data + 1 ;
address = address + 1 ;
end
endmodule
编译后产生的警告:
Warning: The following nodes have both tri-state and non-tri-state drivers
Warning: Inserted always-enabled tri-state buffer between "ack" and its non-tri-state driver.
Warning: TRI or OPNDRN buffers permanently enabled
Warning: Node "ack~synth"
Warning: No exact pin location assignment(s) for 20 pins of 20 total pins
Info: Pin sda not assigned to an exact location on the device
Info: Pin ack not assigned to an exact location on the device
Info: Pin clk not assigned to an exact location on the device
Info: Pin data[7] not assigned to an exact location on the device
Info: Pin address[7] not assigned to an exact location on the device
Info: Pin reset not assigned to an exact location on the device
Info: Pin data[6] not assigned to an exact location on the device
Info: Pin address[6] not assigned to an exact location on the device
Info: Pin data[5] not assigned to an exact location on the device
Info: Pin address[5] not assigned to an exact location on the device
Info: Pin data[4] not assigned to an exact location on the device
Info: Pin address[4] not assigned to an exact location on the device
Info: Pin data[3] not assigned to an exact location on the device
Info: Pin address[3] not assigned to an exact location on the device
Info: Pin data[2] not assigned to an exact location on the device
Info: Pin address[2] not assigned to an exact location on the device
Info: Pin data[1] not assigned to an exact location on the device
Info: Pin address[1] not assigned to an exact location on the device
Info: Pin data[0] not assigned to an exact location on the device
Info: Pin address[0] not assigned to an exact location on the device
Warning: Found 2 output pins without output pin load capacitance assignment
Info: Pin "sda" has no specified output pin load capacitance -- assuming default load capacitance of 0 pF for timing analysis
Info: Pin "ack" has no specified output pin load capacitance -- assuming default load capacitance of 0 pF for timing analysis
Warning: Following 1 pins have no output enable or a GND or VCC output enable - later changes to this connectivity may change fitting results
Info: Pin ack has a permanently enabled output enable
Warning: Found pins functioning as undefined clocks and/or memory enables
Info: Assuming node "clk" is an undefined clock |
|