verilog程序-流水燈_第1頁(yè)
verilog程序-流水燈_第2頁(yè)
verilog程序-流水燈_第3頁(yè)
verilog程序-流水燈_第4頁(yè)
全文預(yù)覽已結(jié)束

下載本文檔

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

文檔簡(jiǎn)介

1、/* 程序功能:流水燈 版本:1.1 版權(quán):分享快樂(lè)*/module liu_shui_deng( input wire pin_clk_in, input wire pin_rest_n , input wire 1:0 pin_ctrl, output reg 7:0 pin_led_out );wire clk ; reg 31: 0 counter32;always (posedge pin_clk_in or negedge pin_rest_n) begin if(pin_rest_n=1b0) begin counter32 = 32b0; end else begin coun

2、ter32 = counter32+1b1; end end assign clk = counter323 ; reg 2:0 cur_sta,stateparameter 2:0 IDLE =3b000;parameter 2:0 RIGHT =5b001;parameter 2:0 LEFT =5b010;parameter 2:0 DOUB_LEFT =5b011;parameter 2:0 ERROR =5b100;always (posedge clk or negedge pin_rest_n) beginif(pin_rest_n=1b0) beginstate = IDLE

3、;endelse begincase (state) IDLE : beginif (pin_ctrl=2b00) beginstate = LEFT ;endelse if (pin_ctrl=2b01) beginstate = RIGHT ;endelse if (pin_ctrl=2b10) beginstate = DOUB_LEFT ;endelse beginstate = ERROR ;endend LEFT : beginif (pin_ctrl=2b00) beginstate = LEFT ;endelse if (pin_ctrl=2b01) beginstate =

4、RIGHT ;endelse if (pin_ctrl=2b10) beginstate = DOUB_LEFT ; end else beginstate = ERROR ;endend RIGHT : beginif (pin_ctrl=2b00) beginstate = LEFT ;endelse if (pin_ctrl=2b01) beginstate = RIGHT ;endelse if (pin_ctrl=2b10) beginstate = DOUB_LEFT ;endelse beginstate = ERROR ;endend DOUB_LEFT : beginif (

5、pin_ctrl=2b00) beginstate = LEFT ;endelse if (pin_ctrl=2b01) beginstate = RIGHT ;endelse if (pin_ctrl=2b10) beginstate = DOUB_LEFT ;endelse beginstate = ERROR ;endend ERROR : beginif (pin_ctrl=2b00) beginstate = LEFT ;endelse if (pin_ctrl=2b01) beginstate = RIGHT ; end else if (pin_ctrl=2b10) begin

6、state = DOUB_LEFT ; endelse beginstate = ERROR ;endend default: state = IDLE ;endcase end endalways (posedge clk or negedge pin_rest_n) begin if (pin_rest_n = 1b0) begin pin_led_out7:0=8b0000_0000 ; end else begin case (state) IDLE : begin pin_led_out 7:0 =8b0000_0000 ; end LEFT : begin if (pin_led_

7、out0+pin_led_out1+pin_led_out2+pin_led_out3+pin_led_out4+pin_led_out5+pin_led_out6+pin_led_out7)!=8d1 ) beginpin_led_out7:0 = 8b0000_0001; end else beginpin_led_out7:1 = pin_led_out6:0;pin_led_out0 = pin_led_out7; end end RIGHT : begin if(pin_led_out0+pin_led_out1+pin_led_out2+pin_led_out3+pin_led_o

8、ut4+pin_led_out5+pin_led_out6+pin_led_out7)!=8d1 ) begin pin_led_out 7:0 = 8b0000_0001 ; endelse begin pin_led_out 6:0 = pin_led_out 7:1 ; pin_led_out 7 = pin_led_out 0 ; end end DOUB_LEFT : begin if (pin_led_out0+pin_led_out1+pin_led_out2+pin_led_out3+pin_led_out4+pin_led_out5+pin_led_out6+pin_led_out7)!=8d2 ) begin pin_led_out 7:0 = 8b0000_0011 ; endelse begin pin_led_out 7:1 = pin_led_out 6:0 ; pin_led_out 0 = pin_l

溫馨提示

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

評(píng)論

0/150

提交評(píng)論