广西住建厅八大员报名网站,如何制作公司网页百度发布,后湖做网站,如何在word上做网站网址文章目录 FPGA控制RGB灯WS2812B1、简介1.1水一水1.2程序完成目标1.3项目工程结构 2、代码3、仿真代码4、结果展示 FPGA控制RGB灯WS2812B
1、简介
1.1水一水
最近在学习WS2812B手册#xff0c;是一个简单的协议编写#xff0c;做的时间也算是比较久#xff0c;相对做出了一… 文章目录 FPGA控制RGB灯WS2812B1、简介1.1水一水1.2程序完成目标1.3项目工程结构 2、代码3、仿真代码4、结果展示 FPGA控制RGB灯WS2812B
1、简介
1.1水一水
最近在学习WS2812B手册是一个简单的协议编写做的时间也算是比较久相对做出了一个较为完善的结果在此作为分享
想查看协议的可以去到下列链接
主要特点 (semiee.com)
1.2程序完成目标
1、有多种模式按下按键key[0]切换模式
2、实现灯闪烁的速度核亮度的控制
3、实现动态显示FPGA四个字符
1.3项目工程结构 2、代码
顶层模块
module top(input wire clk,input wire rst_n,input wire[2:0] key,output wire din
);
wire ready_r;
wire enbale;
wire[2:0] key_r;
wire[23:0] data;led_ws_control inst_led_ws_control (.clk (clk),.rst_n (rst_n),.ready (ready_r),.key (key_r),.enable (enable),.data_out (data));led_ws inst_led_ws (.clk (clk),.rst_n (rst_n),.data_enable (enable),.data (data),.ready (ready_r),.din (din));key_debounce #(.N(3)) inst_key_debounce (.clk (clk),.rst_n (rst_n),.key_in (key),.key_out (key_r));endmodule按键消抖模块
// -----------------------------------------------------------------------------
// Copyright (c) 2014-2023 All rights reserved
// -----------------------------------------------------------------------------
// Author : 辣子鸡味的橘子331197689qq.com
// File : key_debounce.v
// Create :
// Revise :
// Editor : sublime text4, tab size (4)
// Description:按键消抖模块
// -----------------------------------------------------------------------------
module key_debounce #(parameter N 4,parameter TIME_20MS 1000_000)(input wire clk,input wire rst_n,input wire[N-1:0] key_in,//四个按键信号输入output reg[N-1:0] key_out//四个按键信号消抖输出
);reg[19:0] cnt;//20ms计数器
wire add_cnt;//计数开始
wire ent_cnt;//计数终止
wire nedge;//下降沿检测reg[N-1:0] key_in_r0;//同步key_in输入信号
reg[N-1:0] key_in_r1;//延迟一个周期
reg[N-1:0] key_in_r2;//延迟两个周期reg flag;//消抖开始标志信号//计数器模块当addent满足时开始计数,检测到下降沿重新计数end_ent满足时停止计数消抖完成
always (posedge clk or negedge rst_n) beginif(~rst_n) begincnt20d0;endelse if(add_cnt)beginif(ent_cnt)begincnt20d0;endelse if(nedge)begincnt20d0;endelse begincntcnt1;endendelse begincntcnt;end
endassign add_cnt flag;//计数开始条件
assign end_cnt (cnt TIME_20MS - 1)add_cnt;//终止结束条件当满足计时到20ms且满足计时条件时成立//信号延时模块
always (posedge clk or negedge rst_n) beginif(~rst_n) beginkey_in_r0{N{1b1}};key_in_r1{N{1b1}};key_in_r2{N{1b1}};endelse beginkey_in_r0key_in;key_in_r1key_in_r0;key_in_r2key_in_r1;end
end//检测下降沿当任意一个按键出现下降沿都会被检测到
assign nedge |(~key_in_r1key_in_r2);
assign podge |(key_in_r1~key_in_r2);
//消抖开始模块
always (posedge clk or negedge rst_n) beginif(~rst_n) beginflag1b0;endelse if(nedge|podge)begin//当出现下降沿开始消抖flag1b1;endelse if(end_cnt)begin//当end_cnt满足时停止消抖flag1b0;endelse beginflagflag;end
end//输出信号赋值模块,当消抖完毕标志按键按下出现一个脉冲信号表示按键按下
always (posedge clk or negedge rst_n) beginif(~rst_n) beginkey_out4b0000;endelse if(end_cnt)beginkey_out~key_in_r0;endelse beginkey_out4b0000;end
endendmodule数据转化模块
//
// Filename : led_ws.v
// Created On : 2023-08-11 16:04:12
// Last Modified : 2023-08-14 15:45:43
// Revision :
// Author : 辣子鸡味的橘子
// Email : 331197689qq.com
//
// Description : 这是led_ws模块主要的作用是将传进来的数据用fifo进行存储
// 将fifo中存储的数据转换为器件的码型输出
//
//module led_ws(input wire clk,input wire rst_n,input wire data_enable,input wire[23:0] data,//输入的RGB数据output wire ready,//一帧输出输出标志output reg din//转换过后的码
);
//定义变量参数
parameter MAX_RST d20000;
parameter MAX_BIT d23;
parameter MAX_NUM d63;
parameter MAX_T d60;
//目前的数字
wire[4:0] num;wire din_t0;//0码
wire din_t1;//1码reg[7:0] cnt_cyc;
wire add_cnt_cyc;
wire end_cnt_cyc;reg[4:0] cnt_bit;
wire add_cnt_bit;
wire end_cnt_bit;reg[7:0] cnt_num;
wire add_cnt_num;
wire end_cnt_num;reg[15:0] cnt_rst;
wire add_cnt_rst;
wire end_cnt_rst;
//****************************************************************
//--两段式状态机
//****************************************************************
//---------状态定义及状态转移条件-----------------------------------parameter IDLE 3b001,RESET 3b010,DATA 3b100;reg [2:0] state ;wire idle2reset;wire reset2data;wire data2idle;
//---------状态转移-----------------------------------always(posedge clk or negedge rst_n)if(!rst_n)state IDLE;else case(state)IDLE : if(idle2reset)beginstateRESET;endRESET : if(reset2data)beginstateDATA;endDATA : if(data2idle)beginstateIDLE;enddefault:statestate;endcase
//---------状态转移条件赋值-----------------------------------assign idle2reset state IDLEdata_enable;assign reset2data state RESETend_cnt_rst;assign data2idle state DATAend_cnt_num;
//****************************************************************
//--fifoip核
//****************************************************************
wire fifo_wr;
wire fifo_rd;
wire fifo_empty;
wire fifo_full;
wire[5:0] fifo_usdw;
wire[23:0] fifo_q;
wire[23:0] fifo_data;
assign fifo_data {data[15:8],data[23:16],data[7:0]};
assign fifo_wr data_enable;//换成持续信号
assign fifo_rd end_cnt_bit;fifo fifo_inst (.aclr ( ~rst_n ),.clock ( clk ),.data ( fifo_data ),.rdreq ( fifo_rd ),.wrreq ( fifo_wr ),.empty ( fifo_empty ),.full ( fifo_full ),.q ( fifo_q ),.usedw ( fifo_usdw ));//---------周期计数1200ns-----------------------------------always (posedge clk or negedge rst_n) beginif(~rst_n) begincnt_cycd0;endelse if(add_cnt_cyc)beginif(end_cnt_cyc)begincnt_cyc d0;endelse begincnt_cyc cnt_cyc 1b1;endendelse begincnt_cyccnt_cyc;end
end
assign add_cnt_cyc state DATA;
assign end_cnt_cyc add_cnt_cyc cnt_cyc MAX_T;//---------24bit计数-----------------------------------always (posedge clk or negedge rst_n) beginif(~rst_n) begincnt_bitd0;endelse if(add_cnt_bit)beginif(end_cnt_bit)begincnt_bit d0;endelse begincnt_bit cnt_bit 1b1;endendelse begincnt_bitcnt_bit;end
end
assign add_cnt_bit end_cnt_cyc;
assign end_cnt_bit add_cnt_bit cnt_bit MAX_BIT;
//---------64个像素计数-----------------------------------always (posedge clk or negedge rst_n) beginif(~rst_n) begincnt_numd0;endelse if(add_cnt_num)beginif(end_cnt_num)begincnt_num d0;endelse begincnt_num cnt_num 1b1;endendelse begincnt_numcnt_num;end
end
assign add_cnt_num end_cnt_bit;
assign end_cnt_num add_cnt_num cnt_num MAX_NUM;
//---------复位时间计数-----------------------------------always (posedge clk or negedge rst_n) beginif(~rst_n) begincnt_rstd0;endelse if(add_cnt_rst)beginif(end_cnt_rst)begincnt_rst d0;endelse begincnt_rst cnt_rst 1b1;endendelse begincnt_rstcnt_rst;end
end
assign add_cnt_rst state RESET;
assign end_cnt_rst add_cnt_rst cnt_rst MAX_RST;
//目前计数的数字
assign num 23 - cnt_bit;
// assign din_t0 cnt_cyc2?1b1:1b0;
// assign din_t1 cnt_cyc3?1b1:1b0;
assign din_t0 cnt_cyc15?1b1:1b0;
assign din_t1 cnt_cyc30?1b1:1b0;
//---------单项码赋值-----------------------------------
always (*) begincase(state)IDLE: din 1b0;RESET:din 1b0;DATA:beginif(fifo_q[num] 1b1)begindin din_t1;endelse begindin din_t0;endenddefault:din 1b1;endcase
end//准备条件
assign ready state IDLE;
endmodule注意其中设计到fifo的配置下列我简单截取一下fifo中的配置 数据控制模块
//
// Filename : led_ws_control.v
// Created On : 2023-08-11 16:08:30
// Last Modified : 2023-08-14 17:22:26
// Revision :
// Author : 辣子鸡味的橘子
// Email : 331197689qq.com
//
// Description :这是控制模块通过按键按下
// 1、按下key[0],显示三种状态,流水灯、彩虹灯、字体动态显示
// 2、按下key[1],控制亮度按下亮度是减小注意有限制
// 3、按下key[2],控制变换速度三档2s、1s、0.5s
//
module led_ws_control(input wire clk,input wire rst_n,input wire ready,//准备信号由led_ws发出当fifo值为空时发出,告诉控制端准备发送数据input wire[2:0] key,output wire enable,//使能信号64个周期写入63个数给fifo进行寄存output wire[23:0] data_out//输出值
);
parameter TIME_2S d99_999_999;
parameter TIME_1S d49_999_999;
parameter TIME_500MS d24_999_999;
wire[5:0] color_num;
wire[4:0] offect_num;
reg[2:0] flag_color;//控制彩灯闪烁
//亮度信号
reg[23:0] data_out_r1;
wire[23:0] data_out_r2;reg[27:0] cnt_max;//灯光时间值
reg[2:0] flag_time;//灯光时间控制状态
//---------状态定义及状态转移条件-----------------------------------parameter IDLE 3b001 ,DATA 3b010,DELAY 3b100;reg [2:0] state ;wire idle2data;wire data2delay;wire delay2idle;
//****************************************************************
//--两段式状态机
//****************************************************************
reg[7:0] cnt;
wire add_cnt;
wire end_cnt;
//ram rom读写使能信号
wire ram_rd;
wire rom_rd;
//打拍延时信号
reg enable1;
reg enbale2;
reg[2:0] flag;//控制信号
reg[23:0] model1;//模式一
reg[23:0] model2;//模式二
wire[23:0] q_out;//ram的输出
wire[23:0] q_out1;//rom的输出//---------灯光亮度调节-----------------------------------
//每次按下减小1/2超过会复位
reg[3:0] cnt_light;
wire add_cnt_light;
wire end_cnt_light;
always (posedge clk or negedge rst_n) beginif(~rst_n) begincnt_lightd0;endelse if(add_cnt_light)beginif(end_cnt_light)begincnt_light d0;endelse begincnt_light cnt_light 1;endendelse begincnt_lightcnt_light;end
end
assign add_cnt_light key[1];
assign end_cnt_light add_cnt_light cnt_light d5;
//---------灯光速度控制-----------------------------------
always (posedge clk or negedge rst_n) beginif(~rst_n)beginflag_time3b100;endelse if(key[2])beginflag_time{flag_time[0],flag_time[2:1]};endelse beginflag_timeflag_time;end
end
//---------灯光时间数据寄存-----------------------------------
always (*) begincase(flag_time)3b001:cnt_max TIME_500MS;3b010:cnt_max TIME_1S;3b100:cnt_max TIME_2S;default:cnt_max TIME_2S;endcase
end
//灯光时间time计数器
reg[27:0] cnt_time;
wire add_cnt_time;
wire end_cnt_time;
always (posedge clk or negedge rst_n) beginif(~rst_n) begincnt_timed0;endelse if(add_cnt_time)beginif(end_cnt_time)begincnt_time d0;endelse begincnt_time cnt_time 1b1;endendelse begincnt_timecnt_time;end
end
assign add_cnt_time state DELAY;
assign end_cnt_time add_cnt_time cnt_time cnt_max;//****************************************************************
//--x坐标计数器
//****************************************************************
reg[2:0] cnt_x;
wire add_cnt_x;
wire end_cnt_x;
always (posedge clk or negedge rst_n) beginif(~rst_n) begincnt_xd0;endelse if(add_cnt_x)beginif(end_cnt_x)begincnt_x d0;endelse begincnt_x cnt_x 1b1;endendelse begincnt_xcnt_x;end
end
assign add_cnt_x rom_rd;
assign end_cnt_x add_cnt_x cnt_x d7;
//****************************************************************
//--y坐标计数器
//****************************************************************
reg[2:0] cnt_y;
wire add_cnt_y;
wire end_cnt_y;
always (posedge clk or negedge rst_n) beginif(~rst_n) begincnt_yd0;endelse if(add_cnt_y)beginif(end_cnt_y)begincnt_y d0;endelse begincnt_y cnt_y 1b1;endendelse begincnt_ycnt_y;end
end
assign add_cnt_y end_cnt_x;
assign end_cnt_y add_cnt_y cnt_y d7;
//****************************************************************
//--偏移量计数器
//****************************************************************
reg[5:0] cnt_offect;
wire add_cnt_offect;
wire end_cnt_offect;
always (posedge clk or negedge rst_n) beginif(~rst_n) begincnt_offectd0;endelse if(add_cnt_offect)beginif(end_cnt_offect)begincnt_offect d0;endelse begincnt_offect cnt_offect 1b1;endendelse begincnt_offectcnt_offect;end
end
assign add_cnt_offect end_cnt_time;
assign end_cnt_offect add_cnt_offect cnt_offect d31;//更换灯光状态
//****************************************************************
//--闪烁灯效果
//****************************************************************
reg[2:0] cnt_state1;
wire add_cnt_state1;
wire end_cnt_state1;
always (posedge clk or negedge rst_n) beginif(~rst_n) begincnt_state1d0;endelse if(add_cnt_state1)beginif(end_cnt_state1)begincnt_state1 d0;endelse begincnt_state1 cnt_state1 1b1;endendelse begincnt_state1cnt_state1;end
end
assign add_cnt_state1 end_cnt_time;
assign end_cnt_state1 add_cnt_state1 cnt_state1 d8;always (*) begincase(cnt_state1)d0:model1 24b00000000_11111110_00000000; // 红d1:model1 24b11001101_11111110_00000000; // 橙d2:model1 24b11111110_11111110_00000000; // 黄d3:model1 24b11111110_00000000_00000000; // 绿d4:model1 24b11111110_00000000_11111110; // 青d5:model1 24b00000000_00000000_11111110; // 蓝d6:model1 24b00000000_11001100_11001100; // 紫d7:model1 24b11111110_11111110_11111110; // 白d8:model1 24b11111111_11111111_11111111; default:model1 24hffffff;endcase
end//更换灯光状态
//****************************************************************
//--流水灯效果
//****************************************************************
assign color_num (cnt_ycnt_offect)%8;
always (*) begincase(color_num)d7:model2 24b00000000_11111110_00000000; // 红d6:model2 24b11001101_11111110_00000000; // 橙d5:model2 24b11111110_11111110_00000000; // 黄d4:model2 24b11111110_00000000_00000000; // 绿d3:model2 24b11111110_00000000_11111110; // 青d2:model2 24b00000000_00000000_11111110; // 蓝d1:model2 24b00000000_11001100_11001100; // 紫d0:model2 24b11111110_11111110_11111110; //白default:model2 24hffffff;endcase
end//---------灯光控制信号-----------------------------------
always (posedge clk or negedge rst_n) beginif(~rst_n)beginflag3b001;endelse if(key[0])beginflag{flag[1:0],flag[2]};endelse beginflagflag;end
end
//计数器用于计算发送数据的个数
always (posedge clk or negedge rst_n) beginif(~rst_n) begincntd0;endelse if(add_cnt)beginif(end_cnt)begincnt d0;endelse begincnt cnt 1b1;endendelse begincntcnt;end
end
assign add_cnt state DATA;
assign end_cnt add_cnt cnt d63;//****************************************************************
//--延时打拍使能信号因为ram读取的信号有两拍的延时
//****************************************************************
always (posedge clk or negedge rst_n) beginif(~rst_n)beginenable11b0;enbale21b0;endelse beginenable1ram_rd;enbale2enable1;end
end//---------状态转移-----------------------------------always(posedge clk or negedge rst_n)if(!rst_n)state IDLE;else case(state)IDLE : if(idle2data)stateDATA;DATA : if(data2delay)stateDELAY;DELAY : if(delay2idle)stateIDLE;default : state IDLE;endcase
//---------状态转移条件赋值-----------------------------------assign idle2data readystateIDLE;assign data2delay end_cntstateDATA;assign delay2idle end_cnt_timestateDELAY;
//****************************************************************
//--灯光状态3
//****************************************************************
assign offect_num cnt_offectcnt_x;
rom rom_inst (.aclr ( ~rst_n ),.address ( cnt_y*32offect_num ),.clock ( clk ),.rden ( rom_rd ),.q ( q_out1 ));//读写使能定义条件
assign ram_rd state DATA;
assign rom_rd state DATA;
assign enable (flag 3b100)?enbale2:rom_rd;
//data_out_r1输出值定义
always (*) begincase(flag)3b001:data_out_r1 model1;3b010:data_out_r1 model2;3b100:beginif(enbale2)begin//data_out_r1 q_out;//RAM显示data_out_r1 q_out1;//ROM显示endelse begindata_out_r1 24h000000;endenddefault:data_out_r1 24h000000;endcase
end//---------亮度值控制-----------------------------------
assign data_out_r2[7:0] cnt_light 0?data_out_r1[7:0]:(data_out_r1[7:0]cnt_light);
assign data_out_r2[15:8] cnt_light 0?data_out_r1[15:8]:(data_out_r1[15:8]cnt_light);
assign data_out_r2[23:16] cnt_light 0?data_out_r1[23:16]:(data_out_r1[23:16]cnt_light);assign data_out data_out_r2;
endmodule这里涉及到了rom的配置我这里简单演示 mif文件内容
-- Copyright (C) 2015-Endless, CrazyBird Corporation
-- Thank you for use CrazyBirds design toolsDEPTH 256;
WIDTH 24;
ADDRESS_RADIX UNS;
DATA_RADIX HEX;CONTENT BEGIN0 : ed1c24;
1 : ed1c24;
2 : ed1c24;
3 : ed1c24;
4 : ed1c24;
5 : 000000;
6 : 000000;
7 : 000000;
8 : ed1c24;
9 : ed1c24;
10 : ed1c24;
11 : ed1c24;
12 : ed1c24;
13 : 000000;
14 : 000000;
15 : 000000;
16 : ed1c24;
17 : ed1c24;
18 : ed1c24;
19 : ed1c24;
20 : 000000;
21 : 000000;
22 : 000000;
23 : 000000;
24 : 000000;
25 : 000000;
26 : ed1c24;
27 : ed1c24;
28 : ed1c24;
29 : 000000;
30 : 000000;
31 : 000000;
32 : ed1c24;
33 : 000000;
34 : 000000;
35 : 000000;
36 : 000000;
37 : 000000;
38 : 000000;
39 : 000000;
40 : ed1c24;
41 : 000000;
42 : 000000;
43 : 000000;
44 : ed1c24;
45 : 000000;
46 : 000000;
47 : 000000;
48 : ed1c24;
49 : 000000;
50 : 000000;
51 : 000000;
52 : 000000;
53 : 000000;
54 : 000000;
55 : 000000;
56 : 000000;
57 : 000000;
58 : ed1c24;
59 : 000000;
60 : ed1c24;
61 : ed1c24;
62 : 000000;
63 : 000000;
64 : ed1c24;
65 : 000000;
66 : 000000;
67 : 000000;
68 : 000000;
69 : 000000;
70 : 000000;
71 : 000000;
72 : ed1c24;
73 : 000000;
74 : 000000;
75 : 000000;
76 : ed1c24;
77 : 000000;
78 : 000000;
79 : 000000;
80 : ed1c24;
81 : 000000;
82 : 000000;
83 : 000000;
84 : 000000;
85 : 000000;
86 : 000000;
87 : 000000;
88 : 000000;
89 : 000000;
90 : ed1c24;
91 : 000000;
92 : 000000;
93 : ed1c24;
94 : 000000;
95 : 000000;
96 : ed1c24;
97 : ed1c24;
98 : ed1c24;
99 : ed1c24;
100 : ed1c24;
101 : 000000;
102 : 000000;
103 : 000000;
104 : ed1c24;
105 : ed1c24;
106 : ed1c24;
107 : ed1c24;
108 : ed1c24;
109 : 000000;
110 : 000000;
111 : 000000;
112 : ed1c24;
113 : 000000;
114 : 000000;
115 : ed1c24;
116 : ed1c24;
117 : ed1c24;
118 : ed1c24;
119 : 000000;
120 : 000000;
121 : ed1c24;
122 : ed1c24;
123 : 000000;
124 : 000000;
125 : ed1c24;
126 : ed1c24;
127 : 000000;
128 : ed1c24;
129 : 000000;
130 : 000000;
131 : 000000;
132 : 000000;
133 : 000000;
134 : 000000;
135 : 000000;
136 : ed1c24;
137 : 000000;
138 : 000000;
139 : 000000;
140 : 000000;
141 : 000000;
142 : 000000;
143 : 000000;
144 : ed1c24;
145 : 000000;
146 : 000000;
147 : ed1c24;
148 : 000000;
149 : 000000;
150 : ed1c24;
151 : 000000;
152 : 000000;
153 : ed1c24;
154 : ed1c24;
155 : ed1c24;
156 : ed1c24;
157 : ed1c24;
158 : ed1c24;
159 : 000000;
160 : ed1c24;
161 : 000000;
162 : 000000;
163 : 000000;
164 : 000000;
165 : 000000;
166 : 000000;
167 : 000000;
168 : ed1c24;
169 : 000000;
170 : 000000;
171 : 000000;
172 : 000000;
173 : 000000;
174 : 000000;
175 : 000000;
176 : ed1c24;
177 : 000000;
178 : 000000;
179 : ed1c24;
180 : 000000;
181 : 000000;
182 : ed1c24;
183 : 000000;
184 : 000000;
185 : ed1c24;
186 : 000000;
187 : 000000;
188 : 000000;
189 : 000000;
190 : ed1c24;
191 : ed1c24;
192 : ed1c24;
193 : 000000;
194 : 000000;
195 : 000000;
196 : 000000;
197 : 000000;
198 : 000000;
199 : 000000;
200 : ed1c24;
201 : 000000;
202 : 000000;
203 : 000000;
204 : 000000;
205 : 000000;
206 : 000000;
207 : 000000;
208 : ed1c24;
209 : 000000;
210 : 000000;
211 : 000000;
212 : 000000;
213 : ed1c24;
214 : ed1c24;
215 : 000000;
216 : ed1c24;
217 : ed1c24;
218 : 000000;
219 : 000000;
220 : 000000;
221 : 000000;
222 : 000000;
223 : ed1c24;
224 : ed1c24;
225 : 000000;
226 : 000000;
227 : 000000;
228 : 000000;
229 : 000000;
230 : 000000;
231 : 000000;
232 : ed1c24;
233 : 000000;
234 : 000000;
235 : 000000;
236 : 000000;
237 : 000000;
238 : 000000;
239 : 000000;
240 : ed1c24;
241 : ed1c24;
242 : ed1c24;
243 : ed1c24;
244 : ed1c24;
245 : ed1c24;
246 : 000000;
247 : 000000;
248 : ed1c24;
249 : 000000;
250 : 000000;
251 : 000000;
252 : 000000;
253 : 000000;
254 : 000000;
255 : ed1c24;END;**注意**mif文件要放在工程目录下不然读取不到数据
3、仿真代码
这个仿真代码很简单注意各个模块中的参数值就行
timescale 1ns/1ns
module top_tb();reg clk;
reg rst_n;
reg[2:0] key;
wire din;
parameter SYS_CLK 20;
always #(SYS_CLK/2) clk ~clk;initial beginclk1b0;rst_n1b0;#(2*SYS_CLK);rst_n1b1;end
defparam inst_top.inst_led_ws_control.TIME_500MS 1000;
defparam inst_top.inst_led_ws_control.TIME_1S 2000;
defparam inst_top.inst_led_ws_control.TIME_2S 4000;
initial begin//彩虹灯模式key 3b111;#(SYS_CLK*50);key 3b110;#(SYS_CLK*50);key 3b111;#(50*SYS_CLK);//字体动态显示模式// key 3b111;// #(SYS_CLK*50);// key 3b110;// #(SYS_CLK*50);// key 3b111;// #(50*SYS_CLK);//流水灯模式// key 3b111;// #(SYS_CLK*50);// key 3b110;// #(SYS_CLK*50);// key 3b111;// #(50*SYS_CLK);#2000000;$stop;
end
top inst_top (.clk(clk), .rst_n(rst_n), .key(key), .din(din));endmodule4、结果展示
1、闪烁灯 2、彩虹灯 3、字体动态显示