欢迎来到天天文库
浏览记录
ID:44716189
大小:27.50 KB
页数:4页
时间:2019-10-25
《verilog- HDL实现流水灯》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、用verilog实现流水灯moduleflow_deng(inputwirepin_clk_in,inputwirepin_rest_n,inputwire[1:0]pin_ctrl,outputreg[7:0]pin_led_out);wireclk;reg[31:0]counter32;//fenpingalways@(posedgepin_clk_inornegedgepin_rest_n)beginif(pin_rest_n==1'b0)begincounter32<=32'b0;endelsebegincounter32<=counte
2、r32+1'b1;endendassignclk=counter32[3];//16fenpinreg[4:0]state;parameter[4:0]IDLE=5'b0_0001;parameter[4:0]RIGHT=5'b0_0010;parameter[4:0]LEFT=5'b0_0100;parameter[4:0]DOUB_LEFT=5'b0_1000;parameter[4:0]ERROR=5'b1_0000;reg[4:0]cur_sta;always@(posedgeclkornegedgepin_rest_n)beginif(
3、pin_rest_n==1'b0)beginstate<=IDLE;endelsebegincase(state)IDLE:beginif(pin_ctrl==2'b00)beginstate<=LEFT;endelseif(pin_ctrl==2'b01)beginstate<=RIGHT;endelseif(pin_ctrl==2'b10)beginstate<=DOUB_LEFT;endelsebeginstate<=ERROR;endendLEFT:beginif(pin_ctrl==2'b00)beginstate<=LEFT;ende
4、lseif(pin_ctrl==2'b01)beginstate<=RIGHT;endelseif(pin_ctrl==2'b10)beginstate<=DOUB_LEFT;endelsebeginstate<=ERROR;endendRIGHT:beginif(pin_ctrl==2'b00)beginstate<=LEFT;endelseif(pin_ctrl==2'b01)beginstate<=RIGHT;endelseif(pin_ctrl==2'b10)beginstate<=DOUB_LEFT;endelsebeginstate<
5、=ERROR;endendDOUB_LEFT:beginif(pin_ctrl==2'b00)beginstate<=LEFT;endelseif(pin_ctrl==2'b01)beginstate<=RIGHT;endelseif(pin_ctrl==2'b10)beginstate<=DOUB_LEFT;endelsebeginstate<=ERROR;endendERROR:beginif(pin_ctrl==2'b00)beginstate<=LEFT;endelseif(pin_ctrl==2'b01)beginstate<=RIGH
6、T;endelseif(pin_ctrl==2'b10)beginstate<=DOUB_LEFT;endelsebeginstate<=ERROR;endenddefault:state<=IDLE;endcaseendendalways@(posedgeclkornegedgepin_rest_n)beginif(pin_rest_n==1'b0)beginpin_led_out[7:0]<=8'b0000_0000;endelsebegincase(state)IDLE:beginpin_led_out[7:0]<=8'b0000_0000
7、;endLEFT:beginif((pin_led_out[0]+pin_led_out[1]+pin_led_out[2]+pin_led_out[3]+pin_led_out[4]+pin_led_out[5]+pin_led_out[6]+pin_led_out[7])!=8'd1)beginpin_led_out[7:0]<=8'b0000_0001;endelsebeginpin_led_out[7:1]<=pin_led_out[6:0];pin_led_out[0]<=pin_led_out[7];endendRIGHT:begin
8、if((pin_led_out[0]+pin_led_out[1]+pin_led_out[2]+pin_led_out[3]+pin_
此文档下载收益归作者所有