verilog求模运算求解
`timescale 1ns / 1ps
module seg(
input clk,
input sw,
output [7:0] qg,qs,qb,qq
);
reg [31:0] count;
reg [13:0] cnt;
reg [3:0] g,s,b,q;
always@(posedge clk,negedge sw)
begin
if(!sw)
begin
count <= 0;
cnt <= 0;
end
else if(count == 50_000_000) //delay 1s
begin
count <= 0;
cnt <= cnt + 1;
g <= cnt % 10;
s <= cnt / 10 % 10;
b <= cnt / 100 % 10;
q <= cnt / 1000 % 10;
end
else if(cnt == 9999)
cnt <= 0;
else
count <= count + 1;
end
//assign g = cnt % 10;
//assign s = cnt / 10 % 10;
//assign b = cnt / 100 % 10;
//assign q = cnt / 1000 % 10;
assign qg = seg(g);
assign qs = seg(s);
assign qb = seg(b);
assign qq = seg(q);
function [7:0] seg;
input [3:0] temp;
case(temp)
4'd0 : seg = 8'h3f;
4'd1 : seg = 8'h06;
4'd2 : seg = 8'h5b;
4'd3 : seg = 8'h4f;
4'd4 : seg = 8'h66;
4'd5 : seg = 8'h6d;
4'd6 : seg = 8'h7d;
4'd7 : seg = 8'h07;
4'd8 : seg = 8'h7f;
4'd9 : seg = 8'h6f;
default : seg = 8'hxx;
endcase
endfunction
endmodule
这是我写的代码是一个计算0-9999的计数器,在用数码管显示的,现在这个代码有错误通不过检测
错误提示:
ERROR:Xst:867 - "seg.v" line 23: Operator % is only supported when the second operand is a power of 2.
在线等高手求解!谢谢! |