// modelsim testbench
// 有疑问,可联系我,百度hi不方便,可以Q
module led_tb(clk,n_reset,led);
output clk;
output n_reset;
output [7:0] led;
reg clk;
reg n_reset;
led_ctrl led_inst(clk,n_reset,led);
initial
begin
n_reset = 1'b1;
#20 n_reset = 1'b0;
#60 n_reset = 1'b1;
end
initial
begin
clk = 1'b0;
forever
#10 clk = ~clk;
end
endmodule
module led_ctrl(clk,n_reset,led);
input clk;
input n_reset;
output [7:0] led;
reg [7:0] led;
reg [5:0] state;
reg next_bit;
always @(negedge n_reset,posedge clk)
if (~n_reset)
state <= 6'd0;
else
state <= state==6'd32 ? 6'd0 : state+6'd1;
always @(negedge n_reset,posedge clk)
if (~n_reset)
led <= 8'h7f;
else
if (state==6'd24)
led <= 8'h01;
else if (state==6'd32)
led <= 8'h7f;
else
led <= {led[6:0],next_bit};
always @(negedge n_reset,posedge clk)
if (~n_reset)
next_bit <= 1'b0;
else
if (state>=6'd0 && state<6'd8 )
next_bit <= 1'b1;
else if (state>=6'd8 && state<6'd16)
next_bit <= 1'b0;
else if (state>=6'd16 && state<6'd24)
next_bit <= 1'b1;
else if (state>=6'd24 && state<6'd31)
next_bit <= 1'b0;
else if (state==6'd31)
next_bit <= 1'b1;
else if (state==6'd32)
next_bit <= 1'b0;
endmodule
本回答被提问者采纳有没有参加过电子设计大赛的?
比如,要制作一串彩灯(假设为8个),当硬件制作完后,我们给单片机编写不同的程序便能控制这8个灯从左至右循环点亮、从右至左循环点亮、每隔一个点亮一个灯、每隔一定的时间让灯闪烁等。同样的一个电路,只需改变程序便能实现各种不同的功能,非常方便。(1)单片机种类市场主流的单片机包括AT89C51\/C52、AT89S51\/52、ST...