//input: xung Clk 40Mhz cua FPGA, tin hieu Reset tích cuc muc thap
//output: xung Clk 1Hz, tin hieu rst tich cuc muc cao
module clk(
);
input Clk40M,Reset;
output Clk1,rst;
reg Clk1;
begin
if(!Reset) count1<=28'b0;
else if(count1==19999999)
begin
Clk1<=1'b1;
count1<=count1+1'b1;
end
else if (count1==39999999)
begin
Clk1<=1'b0;
count1<=28'b0;
end
else count1<=count1+1'b1;
//counter.v
begin
if (rst)
begin
end
else
begin
// giay
s1 = s1 + 1;
s1 = 0;
s2 = s2 + 1;
end
//phut
s2 = 0;
m1 = m1 + 1;
end
m1 = 0;
m2 = m2 + 1;
end
//gio
m2 = 0;
h1 = h1 + 1;
end
h1 = 0;
h2 = h2 + 1;
end
h1 = 0;
h2 = 0;
end
end
endmodule
//led 7seg
// anode chung
input bcd;
output seg;
always @ (bcd)
begin
case(bcd)
endcase
end
endmodule
//bai3.v
module bai3 (Clk40M, Reset, 7segS1, 7segS2, 7segM1, 7segM2, 7segH1, 7segH2);
//gio
// phut
// giay
Endmodule
/clk.tv=b
`timescale 1 ns / 100 ps
//generate clock
always
begin
clk40M <= 0;
#12.5;
clk40M <= 1;
#12.5;
end
initial
begin
#12.5;
end
endmodule
Vẽ sơ đồ trạng thái Mealy và mô tả sơ đồ bằng verilog cho trường hợp sau :
Đầu ra Y = 1 khi tổng các số bit 1 nhận được chia cho 4 dư 3 ( biết các bit nhận được
theo thứ tự LSB vào trước //bai4.v
module countBit(clk,Out,newNum,count);
input clk;
output Out,newNum,count;
reg[4:0] Num;
reg[4:0] newNum;
reg Out;
reg[4:0] count;
integer index;
initial
begin
Num = 15;
count = 0;
end
newNum[index] = 1;
count = count + 1;
end
else newNum[index] = 0;
else Out = 0;
end endmodule
/bai4_tb.v
`timescale 1ns/1ps
module countBit_tb();
wire Out;
reg clk;
always
begin
#10 clk = 0;
#10 clk = 1;
end
endmodule