verilog HDL 的一个动态数码显示程序,不知道哪里错了,请高手看看
今天做实验,使用的是XC95108CPLD,4个数码管动态显示0000~9999,每隔1S增加1,下面是程序,编译时没有出错,但是实际却出现问题:不受晶振发出的时钟信号的...
今天做实验,使用的是XC95108 CPLD,4个数码管动态显示0000~9999,每隔1S增加1,下面是程序,编译时没有出错,但是实际却出现问题:不受晶振发出的时钟信号的影响,固定显示不变。求高手看看,问题出在哪里,不胜感激!!!!
使用晶振为12MHZ
下面是程序
`define ZER 8'hc0
`define ONE 8'hf9
`define TWO 8'ha4
`define THR 8'hb0
`define FOU 8'h99
`define FIV 8'h92
`define SIX 8'h82
`define SEV 8'hf8
`define EIG 8'h80
`define NIG 8'h90
module actdisp (disp,out,clk);
output [7:0] out;
output [3:0] disp;
input clk;
reg [7:0] out;
reg [3:0] disp;
reg clk1,clk2;
reg [1:0]dispcount;
reg [15:0]count;
reg [3:0] dispdata;
reg [14:0] clk1count;
reg [7:0] clk2count;
initial
begin
dispcount=4'b1111;
count=0;
clk2count=0;
clk1count=0;
end
always
@(posedge clk) //全局时钟 clk1 5ms clk2 1.5s
begin
clk1count=clk1count+1'b1;
if(clk1count>59999)
begin
clk1=~clk1;
clk1count=0;
clk2count=clk2count+1'b1;
end
if (clk2count>299)
begin
clk2=~clk2;
clk2count=0;
end
end
always //定位显示记录
@ (clk1)
begin
dispcount=dispcount+1;
end
always //定位显示扫描
@ (dispcount)
begin
case (dispcount)
'd0: disp=4'b1110;
'd1: disp=4'b1101;
'd2: disp=4'b1011;
'd3: disp=4'b0111;
endcase
end
always @ (clk2) //每隔1.5s计数器+1,用BCD码进行计数
begin
count=count+1;
if(count[3:0]==4'b1010)
begin
count[3:0]=0;
count[7:4]=count[7:4]+1'b1;
end
if(count[7:4]==4'b1010)
begin
count[7:4]=0;
count[11:8]=count[11:8]+1;
end
if(count[11:8]==4'b1010)
begin
count[11:8]=0;
count[15:12]=count[15:9]+1;
end
if(count[15:12]==4'b1010)
begin
count[15:12]=0;
end
end
always //根据显示位的变化,修改显示内容
@ (disp)
begin
case (disp)
4'b1110: dispdata = count[3:0];
4'b1101: dispdata = count[7:4];
4'b1011: dispdata = count[11:8];
4'b0111: dispdata = count[15:12];
endcase
case (dispdata)
4'h0:out=`ZER;
4'h1:out=`ONE;
4'h2:out=`TWO;
4'h3:out=`THR;
4'h4:out=`FOU;
4'h5:out=`FIV;
4'h6:out=`SIX;
4'h7:out=`SEV;
4'h8:out=`EIG;
4'h9:out=`NIG;
endcase
end
endmodule 展开
使用晶振为12MHZ
下面是程序
`define ZER 8'hc0
`define ONE 8'hf9
`define TWO 8'ha4
`define THR 8'hb0
`define FOU 8'h99
`define FIV 8'h92
`define SIX 8'h82
`define SEV 8'hf8
`define EIG 8'h80
`define NIG 8'h90
module actdisp (disp,out,clk);
output [7:0] out;
output [3:0] disp;
input clk;
reg [7:0] out;
reg [3:0] disp;
reg clk1,clk2;
reg [1:0]dispcount;
reg [15:0]count;
reg [3:0] dispdata;
reg [14:0] clk1count;
reg [7:0] clk2count;
initial
begin
dispcount=4'b1111;
count=0;
clk2count=0;
clk1count=0;
end
always
@(posedge clk) //全局时钟 clk1 5ms clk2 1.5s
begin
clk1count=clk1count+1'b1;
if(clk1count>59999)
begin
clk1=~clk1;
clk1count=0;
clk2count=clk2count+1'b1;
end
if (clk2count>299)
begin
clk2=~clk2;
clk2count=0;
end
end
always //定位显示记录
@ (clk1)
begin
dispcount=dispcount+1;
end
always //定位显示扫描
@ (dispcount)
begin
case (dispcount)
'd0: disp=4'b1110;
'd1: disp=4'b1101;
'd2: disp=4'b1011;
'd3: disp=4'b0111;
endcase
end
always @ (clk2) //每隔1.5s计数器+1,用BCD码进行计数
begin
count=count+1;
if(count[3:0]==4'b1010)
begin
count[3:0]=0;
count[7:4]=count[7:4]+1'b1;
end
if(count[7:4]==4'b1010)
begin
count[7:4]=0;
count[11:8]=count[11:8]+1;
end
if(count[11:8]==4'b1010)
begin
count[11:8]=0;
count[15:12]=count[15:9]+1;
end
if(count[15:12]==4'b1010)
begin
count[15:12]=0;
end
end
always //根据显示位的变化,修改显示内容
@ (disp)
begin
case (disp)
4'b1110: dispdata = count[3:0];
4'b1101: dispdata = count[7:4];
4'b1011: dispdata = count[11:8];
4'b0111: dispdata = count[15:12];
endcase
case (dispdata)
4'h0:out=`ZER;
4'h1:out=`ONE;
4'h2:out=`TWO;
4'h3:out=`THR;
4'h4:out=`FOU;
4'h5:out=`FIV;
4'h6:out=`SIX;
4'h7:out=`SEV;
4'h8:out=`EIG;
4'h9:out=`NIG;
endcase
end
endmodule 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询