北邮22信通一枚~
跟随课程进度更新北邮信通院数字系统设计的笔记、代码和文章
持续关注作者 迎接数电实验学习~
获取更多文章,请访问专栏:
北邮22级信通院数电实验_青山如墨雨如画的博客-CSDN博客
目录
一.代码部分
二.管脚分配
三.实验效果
一.代码部分
rainbow_breathing_light.v
module pwm
(input [7:0] duty,input clk,output reg out
);reg [7:0] buffer;always @ (posedge clk)begin buffer <= buffer + 1;if(buffer < duty)begin out <= 0;endelsebegin out <= 1;endend
endmodulemodule rainbow_breathing_light(clk,red,green,blue);input clk;output red,green,blue;reg [15:0] wheel_position;reg [7:0] wheel_position_buffer;reg [7:0] red_buffer,green_buffer,blue_buffer;reg [31:0] divide_buffer;wire clk;reg divide_clk;pwm pwm_red(red,red_buffer,clk);pwm pwm_green(green,green_buffer,clk);pwm pwm_blue(blue,blue_buffer,clk);always @ (posedge clk)begin if(divide_buffer < 50000)begin divide_buffer <= divide_buffer + 1;endelsebegin divide_clk <= ~divide_clk;divide_buffer <= 0;endendalways @ (posedge divide_clk)begin if(wheel_position < 765)wheel_position <= wheel_position + 1;elsewheel_position <= 0;if(wheel_position < 255)begin red_buffer <= 255 - wheel_position;green_buffer <= 0;blue_buffer <= wheel_position;endelse if(wheel_position < 510)begin red_buffer <= 0;green_buffer <= wheel_position - 255;blue_buffer <= 255 - (wheel_position - 255);endelsebeginred_buffer <= wheel_position - 510;green_buffer <= 255 - (wheel_position - 510);blue_buffer <= 0;endend
endmodule
二.管脚分配
三.实验效果
彩虹呼吸灯。