进程4 LED动态、静态显示
动态显示:
module scan_led(clk,rst,sm_seg,sm_bit);
input clk,rst;
output[7:0] sm_seg;
output[7:0] sm_bit;
reg[7:0] sm_seg;
reg[7:0] sm_bit;
reg[15:0] cnt_scan;
reg[4:0] dataout_buf;
always@(posedge clk or negedge rst)
begin
if(!rst) begin
cnt_scan<=0;
end
else begin
cnt_scan<=cnt_scan+1'b1;
end
end
always @(cnt_scan)
begin
case(cnt_scan[15:13])
3'b000 :
sm_bit = 8'b1111_1110;
3'b001 :
sm_bit = 8'b0111_1111;
3'b010 :
sm_bit = 8'b1011_1111;
3'b011 :
sm_bit = 8'b1101_1111;
3'b100 :
sm_bit = 8'b1110_1111;
3'b101 :
sm_bit = 8'b1111_0111;
3'b110 :
sm_bit = 8'b1111_1011;
3'b111 :
sm_bit = 8'b1111_1101;
default :
sm_bit = 8'b1111_1110;
endcase
end
always@(sm_bit)
begin
case(sm_bit)
8'b1111_1110:
dataout_buf=8;
8'b1111_1101:
dataout_buf=7;
8'b1111_1011:
dataout_buf=6;
8'b1111_0111:
dataout_buf=5;
8'b1110_1111:
dataout_buf=4;
8'b1101_1111:
dataout_buf=3;
8'b1011_1111:
dataout_buf=2;
8'b0111_1111:
dataout_buf=1;
default:
dataout_buf=0;
endcase
end
always@(dataout_buf)
begin
case(dataout_buf)
4'h0 : sm_seg = 8'hc0; // "0"
4'h1 : sm_seg = 8'hf9; // "1"
4'h2 : sm_seg = 8'ha4; // "2"
4'h3 : sm_seg = 8'hb0; // "3"
4'h4 : sm_seg = 8'h99; // "4"
4'h5 : sm_seg = 8'h92; // "5"
4'h6 : sm_seg = 8'h82; // "6"
4'h7 : sm_seg = 8'hf8; // "7"
4'h8 : sm_seg = 8'h80; // "8"
4'h9 : sm_seg = 8'h90; // "9"
4'ha : sm_seg = 8'h88; // "a"
4'hb : sm_seg = 8'h83; // "b"
4'hc : sm_seg = 8'hc6; // "c"
4'hd : sm_seg = 8'ha1; // "d"
4'he : sm_seg = 8'h86; // "e"
4'hf : sm_seg = 8'h8e; // "f"
endcase
end
endmodule
图1 生成的顶层原理图
图2 运行结果
静态显示:
module led_display(sm_seg,sm_bit,clk,);
input clk;
output [7:0] sm_seg; //
output [7:0] sm_bit; //
reg [7:0] sm_seg;
reg [7:0] sm_bit;
reg [3:0] disp_dat;
reg [36:0] count;
always @ (posedge clk )
begin
count = count + 1'b1;
sm_bit = 8'b00000000;
end
always @ (count[24])
begin
disp_dat = {count[28:25]};
end
always @ (disp_dat)
begin
case (disp_dat)
4'h0 : sm_seg = 8'hc0; // "0"
4'h1 : sm_seg = 8'hf9; // "1"
4'h2 : sm_seg = 8'ha4; // "2"
4'h3 : sm_seg = 8'hb0; // "3"
4'h4 : sm_seg = 8'h99; // "4"
4'h5 : sm_seg = 8'h92; // "5"
4'h6 : sm_seg = 8'h82; // "6"
4'h7 : sm_seg = 8'hf8; // "7"
4'h8 : sm_seg = 8'h80; // "8"
4'h9 : sm_seg = 8'h90; // "9"
4'ha : sm_seg = 8'h88; // "a"
4'hb : sm_seg = 8'h83; // "b"
4'hc : sm_seg = 8'hc6; // "c"
4'hd : sm_seg = 8'ha1; // "d"
4'he : sm_seg = 8'h86; // "e"
4'hf : sm_seg = 8'h8e; // "f"
endcase
end
endmodule
生成顶层原理图(图1)与动态式相同
图3 运行结果
tcl_script.tcl文件
#Pin_Setup.tcl
# Setup pin setting
set_global_assignment -name RESERVE_ALL_UNUSED_PINS "AS INPUT TRI-STATED"
set_global_assignment -name ENABLE_INIT_DONE_OUTPUT ON
set_location_assignment PIN_129 -to clk
set_location_assignment PIN_191 -to sm_seg[0]
set_location_assignment PIN_197 -to sm_seg[1]
set_location_assignment PIN_205 -to sm_seg[2]
set_location_assignment PIN_200 -to sm_seg[3]
set_location_assignment PIN_198 -to sm_seg[4]
set_location_assignment PIN_193 -to sm_seg[5]
set_location_assignment PIN_206 -to sm_seg[6]
set_location_assignment PIN_201 -to sm_seg[7]
set_location_assignment PIN_188 -to sm_bit[7]
set_location_assignment PIN_189 -to sm_bit[6]
set_location_assignment PIN_192 -to sm_bit[5]
set_location_assignment PIN_195 -to sm_bit[4]
set_location_assignment PIN_199 -to sm_bit[3]
set_location_assignment PIN_203 -to sm_bit[2]
set_location_assignment PIN_207 -to sm_bit[1]
set_location_assignment PIN_208 -to sm_bit[0]