源代码如下
module miaobiao(
input up,down,left,right,clk,rst,stop,
output led,
output display_out
);
reg[3:0] led;
reg[10:0] display_out;
reg[30:0] cnt_1s;
reg[20:0] clk_1s;
reg[30:0] cnt_1ms;
reg[20:0] clk_1ms;
wire [4:0] secondL;
wire [3:0] secondH;
wire [4:0] minuteL;
wire [3:0] minuteH;
reg [10:0] minute;
reg [10:0] second;
reg up;
reg down;
reg left;
reg right;
reg [2:0] stop;
//1hz分频
always@(posedge clk or negedge rst)
begin
if(!rst)
clk_1s <= 1'b0;
else if (stop==1'b1)
clk_1s <= clk_1s;
else if (cnt_1s==31'd99999999)begin
cnt_1s <= 1'b0;
clk_1s <= ~clk_1s;end
else if (cnt_1s<31'd99999999)
cnt_1s <= cnt_1s+1'b1;
end
//1khz分频
always@(posedge clk or negedge rst)
begin
if(!rst)
clk_1ms <= 1'b0;
else if (stop==1'b1)
clk_1ms <= clk_1ms;
else if (cnt1==31'd99999)begin
cnt_1ms <= 1'b0;
clk_1ms <= ~clk_1ms;end
else
cnt_1ms <= cnt_1ms+1'b1;
end
//计时部分
always@(posedge clk_1s or negedge rst)
begin
if (!rst)begin
secondL <= 1'b0;
secondH <= 1'b0;
minuteL <= 1'b0;
minuteH <= 1'b0;
clk <= 1'b0;end
else if (stop)
second <= second;
minute <= minute;
if(second==59)//秒针进位
begin
second<=0;
if(minute==59)
begin
minute<=0;
end
else if(minute<59)//分钟数进位
begin
minute<=minute+1;
end
end
else if (second<59)
begin
second<=second+1;
end
//显示
assign secondL = second%10;
assign secondH = second/10;
assign minuteL = minute%10;
assign minuteH = minute/10;
always @(posedge clk_1ms or negedge rst)
begin
if (!rst)begin
second <= 0;
minute <= 0;
end
else if (stop==1)begin
display_out <= display_out;end
else begin
case(secondL)
1'd0: display_out <=11'b1110_0000001;
1'd1: display_out <=11'b1110_1001111;
1'd2: display_out <=11'b1110_0010010;
1'd3: display_out <=11'b1110_0000110;
1'd4: display_out <=11'b1110_1001100;
1'd5: display_out <=11'b1110_0100100;
1'd6: display_out <=11'b1110_0100000;
1'd7: display_out <=11'b1110_0001111;
1'd8: display_out <=11'b1110_0000000;
1'd9: display_out <=11'b1110_0000100;
endcase
case (secondH)
1'd0: display_out <=11'b1101_0000001;
1'd1: display_out <=11'b1101_1001111;
1'd2: display_out <=11'b1101_0010010;
1'd3: display_out <=11'b1101_0000110;
1'd4: display_out <=11'b1101_1001100;
1'd5: display_out <=11'b1101_0100100;
endcase
case (minuteL)
1'd0: display_out <=11'b1011_0000001;
1'd1: display_out <=11'b1011_1001111;
1'd2: display_out <=11'b1011_0010010;
1'd3: display_out <=11'b1011_0000110;
1'd4: display_out <=11'b1011_1001100;
1'd5: display_out <=11'b1011_0100100;
1'd6: display_out <=11'b1011_0100000;
1'd7: display_out <=11'b1011_0001111;
1'd8: display_out <=11'b1011_0000000;
1'd9: display_out <=11'b1011_0000100;
endcase
case (minuteH)
1'd0: display_out <=11'b0111_0000001;
1'd1: display_out <=11'b0111_1001111;
1'd2: display_out <=11'b0111_0010010;
1'd3: display_out <=11'b0111_0000110;
1'd4: display_out <=11'b0111_1001100;
1'd5: display_out <=11'b0111_0100100;
endcase
end
end
//左移、右移
always @(posedge clk_1ms)
begin
if (!rst)
led <= 4'b0000;
else begin
led <= 4'b0001;
if (led == 4'b0001)begin
if (left==1)
led <= led <<1;
else if (right==1)
led <= led;
end
else if (led == 4'b1000)begin
if (left==1)
led <= led;
else if (right==1)
led <= led >>1;
end
else if (led == 4'b0100 || led == 4'b0010)begin
if (left==1)
led <= led <<1;
else if (right==1)
led <= led >>1;
end
end
end
//调整数字
always @(posedge clk_1ms)
begin
if (stop==1) begin
if(led == 4'b1000)begin
if(up == 1'b1)
minuteH <= minuteH + 1 ;
else if (down == 1'b1)
minuteH <= minuteH - 1;
end
else if(led == 4'b0100)begin
if (up==1'b1)
minuteL<= minuteL+ 1 ;
else if (down == 1'b1)
minuteL<= minuteL- 1;
end
else if(led == 4'b0010)begin
if(up == 1'b1)
secondH <= secondH + 1 ;
else if (down == 1'b1)
secondH <= secondH - 1;
end
else if(led == 4'b0001)begin
if(up == 1'b1)
secondL <= secondL + 1 ;
else if (down == 1'b1)
secondL <= secondL - 1;
end
end
end
endmodule
错误信息如下
[HDL 9-806] Syntax error near "always" . [miaobiao.v:109]
[HDL 9-806] Syntax error near "always" . [miaobiao.v:162]
[HDL 9-806] Syntax error near "always" . [miaobiao.v:190]
[HDL 9-806] Syntax error near "endmodule" . [miaobiao.v:220]
第一个always是在assign语句下面那个 ,然后后面的always都是紧跟着的后面的always 。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
是不是always和@之间有空格会有问题
一周热门 更多>