module dj (clk_27m,rst_n,fangxiang,sudu,outf,outs,count_gd,HEX1,HEX2,HEX3,HEX4);
input clk_27m;
input rst_n;
input fangxiang;
input sudu;
input count_gd;
output outf,outs;
output [6:0]HEX1,HEX2,HEX3,HEX4;
reg outf;
wire outs;
reg en;
/************************************/
/*************************************/
always @ ( negedge rst_n or posedge clk_27m)
if (!rst_n)
outf<=0;
else outf<=(fangxiang?1:0);
/*************************************/
reg delay;
always @ (sudu)
case (sudu)
4'b0001:delay<=9'd100;
4'b0011:delay<=9'd200;
4'b0111:delay<=9'd300;
4'b1111:delay<=9'd400;
endcase
/*************************************/
speed_control u1(.clk(clk_27m),.rst(rst_n),.yanchi(delay),.shuchu(outs));
/*************************************/
reg count;
always @ (posedge clk_27m )
if (!rst_n) count<=0;
else if (count==27000000)
begin en<=1;count<=0;end
else
begin en<=0;count<=count+1;end
/*************************************/
reg [3:0] cs_ge;
reg [3:0] cs_shi;
reg [3:0] cs_bai;
reg [3:0] cs_qian;
always @ (negedge count_gd)
if (!rst_n)
begin
cs_ge <= 4'd0;
cs_shi <= 4'd0;
cs_bai <= 4'd0;
cs_qian <= 4'd0;
end
else if (en)
begin
cs_ge <= 4'd0;
cs_shi <= 4'd0;
cs_bai <= 4'd0;
cs_qian <= 4'd0;
end
else
begin
if(cs_ge==4'd9 && cs_shi<4'd10 && cs_bai<4'd10 && cs_qian<4'd10)
begin
cs_ge <= 4'd0;
cs_shi <= cs_shi + 4'd1;
if(cs_shi == 4'd9 && cs_bai<4'd10 && cs_qian<4'd10)
begin
cs_shi <= 4'd0;
cs_bai <= cs_bai + 4'd1;
end
if(cs_bai == 4'd9 && cs_qian<4'd10)
begin
cs_bai <= 4'd0;
cs_qian <= cs_qian + 4'd1;
end
end
else if(cs_qian==4'd10 && cs_bai==4'd9 && cs_shi==4'd9 && cs_ge==4'd9)
begin
cs_ge <= 4'd0;
cs_shi <= 4'd0;
cs_bai <= 4'd0;
cs_qian <= 4'd0;
end
else
begin
cs_ge <= cs_ge + 4'd1;
end
end
/***************************************/
reg [6:0]HEX01,HEX02,HEX03,HEX04;
always @ (cs_qian)
case (cs_qian)
4'd0:HEX01=7'd192;
4'd1:HEX01=7'd249;
4'd2:HEX01=7'd164;
4'd3:HEX01=7'd176;
4'd4:HEX01=7'd153;
4'd5:HEX01=7'd146;
4'd6:HEX01=7'd130;
4'd7:HEX01=7'd1248;
4'd8:HEX01=7'd128;
4'd9:HEX01=7'd144;
endcase
always @ (cs_bai)
case (cs_bai)
4'd0:HEX02=7'd192;
4'd1:HEX02=7'd249;
4'd2:HEX02=7'd164;
4'd3:HEX02=7'd176;
4'd4:HEX02=7'd153;
4'd5:HEX02=7'd146;
4'd6:HEX02=7'd130;
4'd7:HEX02=7'd1248;
4'd8:HEX02=7'd128;
4'd9:HEX02=7'd144;
endcase
always @ (cs_shi)
case (cs_shi)
4'd0:HEX03=7'd192;
4'd1:HEX03=7'd249;
4'd2:HEX03=7'd164;
4'd3:HEX03=7'd176;
4'd4:HEX03=7'd153;
4'd5:HEX03=7'd146;
4'd6:HEX03=7'd130;
4'd7:HEX03=7'd1248;
4'd8:HEX03=7'd128;
4'd9:HEX03=7'd144;
endcase
always @ (cs_ge)
case (cs_ge)
4'd0:HEX04=7'd192;
4'd1:HEX04=7'd249;
4'd2:HEX04=7'd164;
4'd3:HEX04=7'd176;
4'd4:HEX04=7'd153;
4'd5:HEX04=7'd146;
4'd6:HEX04=7'd130;
4'd7:HEX04=7'd1248;
4'd8:HEX04=7'd128;
4'd9:HEX04=7'd144;
endcase
assign HEX1=HEX01;
assign HEX2=HEX02;
assign HEX3=HEX03;
assign HEX4=HEX04;
/***************************************/
endmodule
module speed_control (clk,rst,yanchi,shuchu);
input clk;
input rst;
input yanchi;
output shuchu;
wire shuchu;
reg shuch;
reg wahaha;
always@(posedge clk)
if (!rst)
shuch<=0;
else if(wahaha==yanchi)
begin shuch<=1;wahaha=0;end
else begin shuch<=0;wahaha<=wahaha+1;end
assign shuchu=shuch;
endmodule
这是测试的脚本
initial
begin
rst_n=0;
#10 rst_n=1;
fangxiang=1;
clk_27m=0;
count_gd=0;
sudu=4'b0001;
end
always
// optional sensitivity list
// @(event1 or event2 or .... eventn)
begin
#10 clk_27m=~clk_27m;
#10 count_gd=~count_gd;
end
此帖出自
小平头技术问答
请问下 为什么我这么改了还是无法计数。。。
/*************************************/
reg [3:0] cs_ge;
reg [3:0] cs_shi;
reg [3:0] cs_bai;
reg [3:0] cs_qian;
always@(posedge clk1)
if (!rst) en=0;
else
if (en==27000000)
en=0;
else
en=en+1;
always@(posedge clk1)
begin
if(cs_ge>9)
cs_ge<=0;
else if (en==0)
cs_ge<=cs_ge+1;
else
cs_ge<=cs_ge;
end
always@(posedge clk1)
begin
if(cs_shi>9)
cs_shi=0;
else if((cs_ge==9)&(en==0))
cs_shi=cs_shi+1;
else
cs_shi=cs_shi;
end
always@(posedge clk1)
begin
if(cs_bai>9)
cs_bai=0;
else if ((cs_ge==9)&(cs_shi==9)&(en==0))
cs_bai=cs_bai+1;
else
cs_bai=cs_bai;
end
always@(posedge clk1)
begin
if (cs_qian==9)cs_qian=0;
else if((cs_ge==9)&(cs_shi==9)&(cs_bai==9)&(en==0))
cs_qian=cs_qian+1;
else
cs_qian=cs_qian;
end
/***************************************/
smg m1(.hex11(hex001),.clkk(clk1),.smg_zhi(cs_qian),.rstt(rst));
smg m2(.hex11(hex002),.clkk(clk1),.smg_zhi(cs_bai),.rstt(rst));
smg m3(.hex11(hex003),.clkk(clk1),.smg_zhi(cs_shi),.rstt(rst));
smg m4(.hex11(hex004),.clkk(clk1),.smg_zhi(cs_ge),.rstt(rst));
/***************************************/
endmodule
module smg(hex11,clkk,smg_zhi,rstt);
input rstt;
output hex11;
wire hex11;
reg [6:0]hex;
input clkk;
assign hex11=hex;
parameter seg0=~7'h3f,
seg1=~7'h06,
seg2=~7'h5b,
seg3=~7'h4f,
seg4=~7'h66,
seg5=~7'h6d,
seg6=~7'h7d,
seg7=~7'h07,
seg8=~7'h7f,
seg9=~7'h6f,
sega=~7'h77,
segb=~7'h7c,
segc=~7'h39,
segd=~7'h5e,
sege=~7'h79,
segf=~7'h71;
input [6:0] smg_zhi;
always @ (posedge clkk or negedge rstt )
if(!rstt) hex<=seg1;
else
case (smg_zhi)
4'd0:hex=seg0;
4'd1:hex=seg1;
4'd2:hex=seg2;
4'd3:hex=seg3;
4'd4:hex=seg4;
4'd5:hex=seg5;
4'd6:hex=seg6;
4'd7:hex=seg7;
4'd8:hex=seg8;
4'd9:hex=seg9;
endcase
endmodule
一周热门 更多>