?? fifo.txt
字號:
步FIFO( Verilog HDL )
發表時間:2007年11月21日 20時12分30秒 本文鏈接:http://user.qzone.qq.com/334982024/blog/1195647150評論/閱讀(0/2)
同步FIFO( Verilog HDL )
module fifo (clk,rstp,din,writep,readp,dout,emptyp,fullp);
input clk;
input rstp;
input[15:0] din;
input readp;
input writep;
output[15:0] dout;
output emptyp;
output fullp;
//定義字數
parameter DEPTH=2,
MAX_COUNT=2'b11;
reg emptyp;
reg fullp;
//寄存器型輸出
reg[15:0] dout;
//定義FIFO的指針
reg[(DEPTH-1):0] tail;
reg[(DEPTH-1):0] head;
//定義FIFO計數器
reg[(DEPTH-1):0] count;
//定義寄存器容量
reg [15:0] fifomem[0:MAX_COUNT];
//Dout是記錄和取得指向RIGHT NOW底部的值
always @(posedge clk) begin;
if (rstp==1) begin
dout <=16'h0000;
end
else begin
dout<=fifomem[tail];
end
end
//更新FIFO寄存器
always @(posedge clk) begin
if (rstp==1'b0 && writep==1'b1 &&fullp==1'b0 )begin
fifomem [head] <=din;
end
end
//更新頂部寄存器
always @(posedge clk) begin
if (rstp==1'b1) begin
head<=2'b00;
end
else begin
if (writep==1'b1 && fullp == 1'b1) begin
//寫
head<=head+1;
end
end
end
//更新底部寄存器
always @(posedge clk) begin
if (rstp==1'b1) begin
tail <=2'b00;
end
else begin
if (readp==1'b1 && emptyp == 1'b0) begin
//讀
end
end
end
//更新計數寄存器
always @(posedge clk) begin
if (rstp ==1'b1) begin
count <=2'b00;
end
else begin
case ({readp,writep})
2'b00:count <=count;
2'b01:
//寫
if (count!=MAX_COUNT)
count <=count+1;
2'b10:
//讀
if (count !=2'b00)
count <=count-1;
2'b11:
//同時讀寫,在計數器方面沒有改變
count <=count;
endcase
end
//更新標志
//首先更新空標志
always @(count) begin
if (count == 2'b00)
emptyp <= 1'b1;
case
emptyp <= 1'b0;
end
//更新滿標志
always @(count) begin
if (count == MAX_COUNT)
fullp <= 1'b0;
end
endmodule
PIC系列單片機,最小的只有四個引腳,可以用于最簡單的邏輯控制,雖然PIC系列也有高檔次的單片機,但和專業從事高檔次的單片機的來說就差得遠了.
發表評論 共 0篇評論,第 1頁/共 0頁
第一頁 上一頁 下一頁 最后頁
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -