第二课
module led_test(a,b,key_in,led_out);
input a;//输入端口A
input b;//输入端口B
input key_in; //按键输入,实现输入输入通道的选择
output led_out; //led 控制端口
//当key_in == 0 :led_out = a
assign led_out = (key_in == 0)? a : b;
Endmodule
第三课 3——8译码器
module my3_8(a,b,c,out);
input a;//杈撳叆绔 彛A
input b;//杈撳叆绔 彛B
input c;//杈撳叆绔 彛C
output [7:0]out;//杈撳嚭绔 彛
reg [7:0]out;
always@(a,b,c)begin
cajugglers({商品英文a,b,c})
3'b000:out = 8'b0000_0001;
3'b001:out = 8'b0000_0010;
3'b010:out = 8'b0000_0100;
3'b011:out = 8'b0000_1000;
3'b100:out = 8'b0001_0000;
3'b101:out = 8'b0010_0000;
3'b110:out = 8'b0100_0000;
3'b111:out = 8'b1000_0000;
endca
end
endmodule
第四课 计数器
module counter(Clk50M,Rst_n,led);
input Clk50M; //系统时钟,50M
input Rst_n; //全局复位,低电平复位
output reg led; //led输出
reg [24:0]cnt; //定义计数器寄存器
//计数器计数进程
always@(podge Clk50M or negedge Rst_n)
if(Rst_n == 1'b0)
cnt <= 25'd0;
//el if(cnt == 25'd24_999_999)
el if(cnt == 25'd24_999)
cnt <= 25'd0;
el
cnt <= cnt + 1'b1;
//led输出控制进程
always@(podge Clk50M or negedge Rst_n)
shipment
if(Rst_n == 1'b0)
祝你圣诞快乐英文 led <= 1'b1;
//el if(cnt == 25'd24_999_999)
el if(cnt == 25'd24_999)
led <= ~led;
el
led <= led;
endmodule
第五课 计数器——IP核
module counter_top(cin,clk,cout,q);
input cin;
input clk;
nightwish nemo
output cout;
output [7:0]q;
wire cout0;
counter counter0(
.cin(cin),
.clock(clk),
.cout(cout0),
.q(q[3:0])
);
counter counter1(
.cin(cout0),
.clock(clk),
.cout(cout),
.q(q[7:4])
);
endmodule
Testbench(仿真)
`timescale 1ns/1ns
`define clock_period 20
module counter_tb;
reg cin; //进位输入
bcb reg clk; //计数基准时钟
英语在线翻译发音 wire cout;//进位输出
wire [3:0] q;
counter counter0(
.cin(cin),
.clock(clk),
.cout(cout),
.q(q)
);
initial clk = 1;
always #(`clock_period/2)clk = ~clk;
initial begin
repeat(20)begin
important的名词
cin = 0;
#(`clock_period*5)cin = 1;
#(`clock_period)cin = 0;
造价师网
end
#(`clock_period*200);
$stop;
end
Endmodule
top_ip
`timescale 1ns/1ns
`define clock_period 20
module counter_top_tb;
reg cin; //进位输入
reg clk; //计数基准时钟
wire cout;//进位输出
wire [7:0] q;
counter_top counter0(
.cin(cin),
.clk(clk),
.cout(cout),
.q(q)
);
initial clk = 1;
always #(`clock_period/2)clk = ~clk;
initial begin
repeat(300)begin
cin = 0;
#(`clock_period*5)cin = 1;
#(`clock_period)cin = 0;
end
#(`clock_period*200);
$stop;
end
Endmodule
第六课 BCD计数器
module BCD_Counter(Clk, Cin, Rst_n, Cout, q);
input Clk;//计数基准时钟verst
input Cin; //计数器进位输入
input Rst_n; //系统复位
output Cout; //计数进位输出
output [3:0]q; //计数值输出
reg [3:0]cnt; //定义计数器寄存器
//执行计数过程
always@(podge Clk or negedge Rst_n)
if(Rst_n == 1'b0)