FPGA学习笔记2.2——用Verilog实现七段管的工作逻辑
生活随笔
收集整理的這篇文章主要介紹了
FPGA学习笔记2.2——用Verilog实现七段管的工作逻辑
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
目錄
設計思路:
原理圖:
Task下的調(diào)用:
功能模塊代碼:?
測試模塊代碼:
運行圖:?
Module下的調(diào)用:
功能模塊代碼:
測試模塊代碼:
運行圖:?
設計思路:
一個七段管使用7bit信號控制7段LED燈的亮滅。若每段LED燈賦值為0,燈亮;賦值為1時燈滅。則Hex=7‘b1111001,其中hex[6]—hex[5]…..hex[0]分別對應下圖1中七段管中的編號是6543210的信號。那么該信號hex[6]=1? hex[5]=1? hex[4]=1? hex[3]=1? hex[2]=0? hex[1]=0?? hex[0]=1。
原理圖:
Task下的調(diào)用:
功能模塊代碼:?
module BCDto7(in,out1,out2,out3);input [7:0] in; // 8路輸入,高電平1為有效電平output reg[6:0] out1; //個位的數(shù)碼管output reg[6:0] out2; // 十位的數(shù)碼管output reg[6:0] out3; // 百位的數(shù)碼管wire[3:0] bai; wire[3:0] shi; wire[3:0] ge; assign ge=in%10; // 個位賦值assign shi=(in/10)%10; // 十位賦值assign bai=in/100; // 百位賦值always@(in)beginif(in<10) beginshow(ge,out1); // 第一個七段管 顯示個位out2=7'b1111111; // 第二個七段管不顯示out3=7'b1111111; // 第三個七段管不顯示endelse if(in<100) beginshow(ge,out1); // 第一個七段管 顯示個位show(shi,out2); // 第二個七段管 顯示十位out3=7'b1111111; // 第三個七段管不顯示endelse beginshow(ge,out1); // 第一個七段管 顯示個位show(shi,out2); // 第二個七段管 顯示十位show(bai,out3); // 第三個七段管 顯示百位endendtask show;input integer decc; // 輸入,十進制數(shù)output reg[6:0] outt; // 輸出,7位二進制數(shù)值case(decc)4'd0: outt=7'b1000000; // 七段管顯示04'd1: outt=7'b1111001; // 七段管顯示14'd2: outt=7'b0100100; // 七段管顯示24'd3: outt=7'b0110000; // 七段管顯示34'd4: outt=7'b0011001; // 七段管顯示44'd5: outt=7'b0010010; // 七段管顯示54'd6: outt=7'b0000010; // 七段管顯示64'd7: outt=7'b1111000; // 七段管顯示74'd8: outt=7'b0000000; // 七段管顯示84'd9: outt=7'b0011000; // 七段管顯示9default:outt=7'b1111111; // 七段管不顯示endcaseendtaskendmodule測試模塊代碼:
// Copyright (C) 2017 Intel Corporation. All rights reserved. // Your use of Intel Corporation's design tools, logic functions // and other software and tools, and its AMPP partner logic // functions, and any output files from any of the foregoing // (including device programming or simulation files), and any // associated documentation or information are expressly subject // to the terms and conditions of the Intel Program License // Subscription Agreement, the Intel Quartus Prime License Agreement, // the Intel FPGA IP License Agreement, or other applicable license // agreement, including, without limitation, that your use is for // the sole purpose of programming logic devices manufactured by // Intel and sold by Intel or its authorized distributors. Please // refer to the applicable agreement for further details.// ***************************************************************************** // This file contains a Verilog test bench template that is freely editable to // suit user's needs .Comments are provided in each section to help the user // fill out necessary details. // ***************************************************************************** // Generated on "03/31/2022 11:37:13"// Verilog Test Bench template for design : BCDto7 // // Simulation tool : ModelSim-Altera (Verilog) // `timescale 1 ps/ 1 ps module BCDto7_vlg_tst(); // constants // general purpose registers reg eachvec; // test vector input registers reg [7:0] in; // wires wire [6:0] out1; wire [6:0] out2; wire [6:0] out3; wire[3:0] bai; wire[3:0] shi; wire[3:0] ge; // assign statements (if any) BCDto7 i1 ( // port map - connection between master ports and signals/registers .in(in),.out1(out1),.out2(out2),.out3(out3) ); initial begin // code that executes only once // insert code here --> begin // --> end $display("Running testbench"); for(in=8'b00000000;in<=8'b11111111;in=in+1) begin #1; end end initial begin $monitor($realtime,,,"input:%b; output:%b %b %b",in,out3,out2,out1); #256 $stop; end always // optional sensitivity list // @(event1 or event2 or .... eventn) begin // code executes for every event on sensitivity list // insert code here --> begin @eachvec; // --> end end endmodule運行圖:?
循環(huán)測試所有情況Module下的調(diào)用:
功能模塊代碼:
module bcdyyf(in8,out71,out72,out73); input[7:0] in8; output [6:0] out71,out72,out73; reg [3:0] a1,a2,a3; always@(*) begina1=in8/100; //百位數(shù)a2=(in8-(100*a1))/10; //十位數(shù)a3=in8%10; //個位數(shù) end bcd accbcd1(a1,out71); //模塊調(diào)用注意位置即可(不注意容易出問題,不能放在always前,也不可放在begin end內(nèi)部) bcd accbcd2(a2,out72); bcd accbcd3(a3,out73); endmodulemodule bcd(tt,out7);input [3:0] tt;output reg [6:0] out7; always@(*) begincase(tt) //低電平有效4'b0000:out7=7'b1000000;4'b0001:out7=7'b1111001;4'b0010:out7=7'b0100100;4'b0011:out7=7'b0110000;4'b0100:out7=7'b0011001;4'b0101:out7=7'b0010010;4'b0110:out7=7'b0000010;4'b0111:out7=7'b1111000;4'b1000:out7=7'b0000000;4'b1001:out7=7'b0010000; default:out7=7'b0001001; //其他情況顯示Hendcase end endmodule測試模塊代碼:
`timescale 1 ps/ 1 ps module bcdyyf_vlg_tst(); reg eachvec; reg [7:0] in8; wire [6:0] out71; wire [6:0] out72; wire [6:0] out73; bcdyyf i1 ( .in8(in8),.out71(out71),.out72(out72),.out73(out73) ); initial begin $display("Running testbench"); for(in8=8'b00000000;in8<=8'b11111111;in8=in8+1) begin #1; end end initial begin $monitor($realtime,,,"input:%b; output:%b %b %b",in8,out71,out72,out72); #256 $stop; end endmodule運行圖:?
本次實驗主要是Module的調(diào)用注意他的位置,極其容易出差錯(就是因為一開始不會module模塊調(diào)用,就走了task的調(diào)用)。
總結(jié)
以上是生活随笔為你收集整理的FPGA学习笔记2.2——用Verilog实现七段管的工作逻辑的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux下ifconfig不显示ip地
- 下一篇: 洽洽:成于瓜子,困于瓜子