设计思路:
0-7 编码输入端(低电平有效)74LS148真值表:
EI 选通输入端(低电平有效)
A0、A1、A2 三位二进制编码输出信号即编码 输 出 端(低电平有效)
GS 片优先编码输出端即宽展端(低电平有效)
EO 选通输出端,即使能输出端
输入 |
输出 |
||||||||||||
EI |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
A2 |
A1 |
A0 |
GS |
EO |
1 |
X |
X |
X |
X |
X |
X |
X |
X |
1 |
【FPGA学习指南|FPGA学习笔记2.1——用Verilog实现74LS148的功能定义并测试】1 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
0 |
X |
X |
X |
X |
X |
X |
X |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
X |
X |
X |
X |
X |
X |
0 |
1 |
0 |
0 |
1 |
0 |
1 |
0 |
X |
X |
X |
X |
X |
0 |
1 |
1 |
0 |
1 |
0 |
0 |
1 |
0 |
X |
X |
X |
X |
0 |
1 |
1 |
1 |
0 |
1 |
1 |
0 |
1 |
0 |
X |
X |
X |
0 |
1 |
1 |
1 |
1 |
1 |
0 |
0 |
0 |
1 |
0 |
X |
X |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
1 |
0 |
1 |
0 |
X |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
0 |
1 |
0 |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
1 |
原理图:
文章图片
功能模块代码:
module code83(in8,out3,EI,GS,EO);
input[7:0] in8;
input EI;
output reg[2:0] out3;
output reg GS;
output reg EO;
always@(in8,EI)
begin
out3=3'b111;
EO=1;
GS=1;
if(~EI)
begin
GS=0;
case(in8)
8'b11111111:begin
EO=0;
GS=1;
out3=3'b111;
end
8'b00000000: out3=3'b000;
8'b10000000: out3=3'b001;
8'b11000000: out3=3'b010;
8'b11100000: out3=3'b011;
8'b11110000: out3=3'b100;
8'b11111000: out3=3'b101;
8'b11111100: out3=3'b110;
8'b11111110: out3=3'b111;
default: out3=3'b111;
endcase
end
end
endmodule
测试模块代码:
// Copyright (C) 2017Intel 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/30/2022 22:16:56"// Verilog Test Bench template for design : code83
//
// Simulation tool : ModelSim-Altera (Verilog)
// `timescale 1 ps/ 1 ps
module code83_vlg_tst();
// constants
// general purpose registers
reg eachvec;
// test vector input registers
reg EI;
reg [7:0] in8;
// wires
wire EO;
wire GS;
wire [2:0]out3;
// assign statements (if any)
code83 i1 (
// port map - connection between master ports and signals/registers
.EI(EI),
.EO(EO),
.GS(GS),
.in8(in8),
.out3(out3)
);
initial
begin
// code that executes only once
// insert code here --> begin// --> end
$display("Running testbench");
EI=1;
in8=8'b0;
#5;
EI=0;
in8=8'b11111111;
#16 $stop;
end
always
// optional sensitivity list
// @(event1 or event2 or .... eventn)
begin
// code executes for every event on sensitivity list
// insert code here --> begin
#2 $display("EI:%b;
input:%b;
output:%b GS:%b;
EO:%b",EI,in8,out3,GS,EO);
in8=in8<<1;
@eachvec;
// --> end
end
endmodule
运行图:
文章图片
文章图片
推荐阅读
- FPGA学习指南|FPGA | Verilog学习的各大修炼圣地(推荐篇)
- STM32|STM32GPIO模式的理解
- stm32|stm32学习之路,方法很重要
- MCU项目技术总结|基于stm32F4的项目总结(控制层设计(四)直流有刷电机驱动原理及驱动器选型)
- 单片机毕业设计|800多套单片机毕业设计
- 嵌入式|网上五花八门的单片机教程,到底应该怎么整理学习过程
- 嵌入式|单片机有没有想象中那么好学,很迷茫有说正面有说负面
- 蓝桥杯单片机真题|第十三届蓝桥杯单片机省赛模拟题(客观题程序题)
- 蓝桥杯单片机|【蓝桥杯单片机的备赛旅行日记系列】之省赛初赛代码免费下载