|
頭皮發麻..... fpga的邏輯觀念比c更嚴謹
`define datalen (8-1)
module spi02( reset, data, clk, cs, miso_o );
//input
input reset
input clk;
input cs;
input [7:0] data;
//wire [7:0] data;
//output
output miso_o;
reg out;
//reg
reg [2:0] counter;
//reg [7:0] data_read;
assign miso_o <= out;
always@(posedge clk or reset) //cs的下降沿中的CS出發串行行輸出
begin
// init
if(reset) begin
counter = 0;
end
if(!cs) begin
out <= data[datalen-counter];
if(counter = datalen) counter = 0;
else counter = counter+1;
else
counter = 0;
end
end
|
|