串口通訊的Verilog設(shè)計_第1頁
串口通訊的Verilog設(shè)計_第2頁
串口通訊的Verilog設(shè)計_第3頁
串口通訊的Verilog設(shè)計_第4頁
串口通訊的Verilog設(shè)計_第5頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、【W(wǎng)ord版本下載可任意編輯】 串口通訊的Verilog設(shè)計 module SIMO(din,clk,rst,dout_ser); input din; /串行輸入數(shù)據(jù) input clk; /時鐘信號 input vat; 復(fù)位信號 reg indata_buf; /輸入緩沖存放器,存提取的有效位 reg dout_buf; /輸出緩沖存放器,加了起停位 output reg dout_ser; /串行數(shù)據(jù)輸出 reg nclk; /提取八位有效數(shù)據(jù)的采樣時鐘.是4倍于波特率的時鐘 reg txclk; /發(fā)送數(shù)據(jù)時鐘。發(fā)數(shù)據(jù)取11.2k的波特率 integer bitpos=7; /當(dāng)前位

2、 parameter s0=0,s1=1,s2=2,s3=3; regstate; regcounter; /用來計算報頭報尾中1的個數(shù) reg tag,tag1; regcnt3; reg txdone=1b1;/一個字節(jié)數(shù)據(jù)傳輸完畢標(biāo)志 *提取有效數(shù)據(jù)位并按串行通訊格式裝載數(shù)據(jù)* always (posedge nclk or posedge rst) begin if(rst) begin state=0; counter=0; tag1=0; tag=0; indata_buf=8bz; dout_buf=10bz; bitpos=7; cnt3=0; end else case(st

3、ate) s0:begin tag=0;/表示數(shù)據(jù)沒有裝好 if(din) begin counter=counter+1; state=s0; if(counter=15)/如果檢測到16個1則轉(zhuǎn)入s1狀態(tài)檢測接下來的是不是0 begin state=s1; counter=0; end end else begin counter=0; state=s0; end end s1:if(!din)/如果是0的話,轉(zhuǎn)入s2狀態(tài),提取八位有效數(shù)據(jù) state=s2; else /否則轉(zhuǎn)到s0狀態(tài)重新檢測 state=s0; s2:if(cnt3=3)/是否采集四次數(shù)據(jù) begin cnt2=0;

4、 indata_buf=din; /先進來的是高位數(shù)據(jù) bitpos=bitpos-1; if(bitpos=-1) begin bitpos=7;state=s3;end end else cnt3=cnt3+1; s3:begin tag1=tag; tag=1b1; /標(biāo)志輸入存放器滿。說明已把有用數(shù)據(jù)裝入存放器 if(tag&tag1)&txdone) /檢測到tag的上升沿以及txdone為高才把輸入緩沖數(shù)據(jù)放到輸出緩沖去 dout_buf=1b1,indata_buf,1b0;/停止位,高位,低位,起始位 state=s0; end endcase end /*發(fā)送數(shù)據(jù)模塊 reg

5、 state_tx=0; always(posedge txclk or posedge rst) begin if(rst) begin dout_ser=1bz; state_tx=0; txdone=1; end else case(state_tx) 0:begin dout_ser=dout_buf;state_tx=state_tx+1;txdone=1b0;end 1:begin dout_ser=dout_buf;state_tx=state_tx+1;end 2:begin dout_ser=dout_buf;state_tx=state_tx+1;end 3:begin d

6、out_ser=dout_buf;state_tx=state_tx+1;end 4:begin dout_ser=dout_buf;state_tx=state_tx+1;end 5:begin dout_ser=dout_buf;state_tx=state_tx+1;end 6:begin dout_ser=dout_buf;state_tx=state_tx+1;end 7:begin dout_ser=dout_buf;state_tx=state_tx+1;end 8:begin dout_ser=dout_buf;state_tx=state_tx+1;end 9:begin dout_ser=dout_buf;state_tx=state_tx+1;end endcase end endmodule 注:兩個頻率信號nclk、txclk由相應(yīng)的分頻程序產(chǎn)生。由于篇幅所限未在文中列出。 FPGA模塊接收從RS-485發(fā)送過來的串行數(shù)據(jù)。25位為一個字符。數(shù)據(jù)的傳輸速率是700kbps,用四倍于波特率的速率開展采樣,這樣可以大大降低系統(tǒng)的噪聲。數(shù)據(jù)的串行輸出波特率選為11200bps。 由輸入輸出波形圖

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論