FPGA简易加减法计算器设计

2023-12-18 03:12

本文主要是介绍FPGA简易加减法计算器设计,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目要求:
(1)设计10以内的加减法计算器。
(2)1个按键用于指定加法或减法,一个用于指定加数或被加数,还有两个分别控制加数或被加数的增加或减少。
(3)设置的结果和计算的结果用数码管显示。

本实验我还是将其视作Mealy型向量机,具体的见我之前关于秒表的内容:VHDL实验:基于有限状态机实现秒表
按照题目意思,有4个键是必不可少的,但我还是决定增加两个推键,本实验状态图如下:
在这里插入图片描述
S0:初态模式,所有数码管置零
S1:计算模式,等待用户设置并计算
这两者之间的转换我用开发板上的推键来完成。
另一个推键指示是进行整数运算还是一位小数。

我的代码:(抱歉注释是全英文的)

library ieee ;
use ieee.std_logic_1164.all ;
use ieee.std_logic_unsigned.all ;
use ieee.std_logic_arith.all ;entity Computer isport (key3 : in std_logic ;						-- is addition or subtraction?key2 : in std_logic ;						-- who is augend or minuend?key1 : in std_logic ;						-- change the value of augend or minuendkey0 : in std_logic ;						-- change the value of addend or subtrahendsw0 : in std_logic ;						-- change the state of circuitsw1 : in std_logic ;first1 : out std_logic_vector(0 to 6) ;first2 : out std_logic_vector(0 to 6) ;second1 : out std_logic_vector(0 to 6) ;second2 : out std_logic_vector(0 to 6) ;negative : out std_logic_vector(0 to 6) ;	-- Is the result a negative number?empty : out std_logic_vector(0 to 6) ;result1 : out std_logic_vector(0 to 6) ;	-- the result of computingresult2 : out std_logic_vector(0 to 6) ;	-- the result of computingPoint : out std_logic_vector(7 downto 0) ;	-- Radix pointledg8 : out std_logic ;						-- if substractionledr16 : out std_logic ;					-- it is augend or minuendledr13 : out std_logic 						-- it is augend or minuend) ;
end Computer ;architecture mathematic of Computer isconstant matrix_num : integer := 9 ;TYPE Number is array (0 to matrix_num) of std_logic_vector(0 to 6);signal Display : Number := (('0', '0', '0', '0', '0', '0', '1'),		-- 0('1', '0', '0', '1', '1', '1', '1'),			-- 1('0', '0', '1', '0', '0', '1', '0'),			-- 2('0', '0', '0', '0', '1', '1', '0'),			-- 3('1', '0', '0', '1', '1', '0', '0'),			-- 4('0', '1', '0', '0', '1', '0', '0'),			-- 5('0', '1', '0', '0', '0', '0', '0'),			-- 6('0', '0', '0', '1', '1', '1', '1'),			-- 7('0', '0', '0', '0', '0', '0', '0'),			-- 8('0', '0', '0', '0', '1', '0', '0')			-- 9) ;TYPE state_type is (s0, s1) ;		-- how many states does the circuit have?signal current_state : state_type ;-- all of them below are middle datasignal neg : std_logic_vector(0 to 6) := ('1', '1', '1', '1', '1', '1', '1') ;signal led8 : std_logic ;						signal led16 : std_logic ;					signal led13 : std_logic ;signal p : std_logic_vector(7 downto 0) ;					
beginprocess(sw0)											 -- to change the state of circuitbeginif (sw0 = '0') thencurrent_state <= s0 ;elsecurrent_state <= s1 ;end if ;end process ;process(current_state, key3, key2, key1, key0, sw1) -- take action according to statevariable First : integer := 0 ;variable Second : integer := 0 ;variable Result : integer := 0 ;variable num3 : integer := 0 ;variable num2 : integer := 0 ;beginif (current_state = s0) thenFirst := 0 ;Second:= 0 ;Result:= 0 ;num3  := 0 ;num2  := 0 ;neg <= ('1', '1', '1', '1', '1', '1', '1') ;					p <= ('1', '1', '1', '1', '1', '1', '1', '1') ;led8 <= '0' ;led16 <= '0' ;				led13 <= '0' ;elsif (current_state = s1) thenif (sw1 = '1') then			-- make sure integer or floatp <= ('0', '1', '0', '1', '1', '1', '0', '1') ;else p <= ('1', '1', '1', '1', '1', '1', '1', '1') ;end if ;if falling_edge(key2) then	-- make sure who is augend or minuend?num2 := num2 + 1 ;end if ;if ((num2 > 0) and(num2 MOD 2 = 0)) thenled16 <= '0' ;led13 <= '1' ;elsif (num2 MOD 2 = 1) thenled16 <= '1' ;led13 <= '0' ;end if ;if falling_edge(key1) then		-- decide the value of first numberFirst := First + 1 ;if (First > 10) thenFirst := 0 ;end if ;end if ;if falling_edge(key0) then 		-- decide the value of second numberSecond := Second + 1 ;if (Second > 10) thenSecond := 0 ;end if ;end if ;if falling_edge(key3) thennum3 := num3 + 1 ;end if ;if (num3 MOD 2 = 1) thenled8 <= '0' ;neg(6) <= '1' ;Result := First + Second ;elsif ((num3>0) and (num3 MOD 2 = 0)) thenled8 <= '1' ;if (led13 = '1') thenif (Second < first) thenneg(6) <= '0' ;Result := First - Second ;elseneg(6) <= '1' ;Result := Second - First ;end if ;elsif (led16 = '1') thenif (first < Second) thenneg(6) <= '0' ;Result := Second - First ;elseneg(6) <= '1' ;Result := First - Second ;end if ;end if ;end if ;end if ;empty <= ('1', '1', '1', '1', '1', '1', '1') ;first1 <= Display(First/10) ;first2 <= Display(First MOD 10) ;second1 <= Display(Second/10) ;second2 <= Display(Second MOD 10) ;negative <= neg ;result1 <= Display(Result/10) ;result2 <= Display(Result MOD 10);Point <= p ;ledg8 <= led8 ;ledr16 <= led16 ;ledr13 <= led13 ;end process ;
end mathematic ;

这篇关于FPGA简易加减法计算器设计的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/506845

相关文章

不懂推荐算法也能设计推荐系统

本文以商业化应用推荐为例,告诉我们不懂推荐算法的产品,也能从产品侧出发, 设计出一款不错的推荐系统。 相信很多新手产品,看到算法二字,多是懵圈的。 什么排序算法、最短路径等都是相对传统的算法(注:传统是指科班出身的产品都会接触过)。但对于推荐算法,多数产品对着网上搜到的资源,都会无从下手。特别当某些推荐算法 和 “AI”扯上关系后,更是加大了理解的难度。 但,不了解推荐算法,就无法做推荐系

怎么让1台电脑共享给7人同时流畅设计

在当今的创意设计与数字内容生产领域,图形工作站以其强大的计算能力、专业的图形处理能力和稳定的系统性能,成为了众多设计师、动画师、视频编辑师等创意工作者的必备工具。 设计团队面临资源有限,比如只有一台高性能电脑时,如何高效地让七人同时流畅地进行设计工作,便成为了一个亟待解决的问题。 一、硬件升级与配置 1.高性能处理器(CPU):选择多核、高线程的处理器,例如Intel的至强系列或AMD的Ry

基于51单片机的自动转向修复系统的设计与实现

文章目录 前言资料获取设计介绍功能介绍设计清单具体实现截图参考文献设计获取 前言 💗博主介绍:✌全网粉丝10W+,CSDN特邀作者、博客专家、CSDN新星计划导师,一名热衷于单片机技术探索与分享的博主、专注于 精通51/STM32/MSP430/AVR等单片机设计 主要对象是咱们电子相关专业的大学生,希望您们都共创辉煌!✌💗 👇🏻 精彩专栏 推荐订阅👇🏻 单片机

SprinBoot+Vue网络商城海鲜市场的设计与实现

目录 1 项目介绍2 项目截图3 核心代码3.1 Controller3.2 Service3.3 Dao3.4 application.yml3.5 SpringbootApplication3.5 Vue 4 数据库表设计5 文档参考6 计算机毕设选题推荐7 源码获取 1 项目介绍 博主个人介绍:CSDN认证博客专家,CSDN平台Java领域优质创作者,全网30w+

单片机毕业设计基于单片机的智能门禁系统的设计与实现

文章目录 前言资料获取设计介绍功能介绍程序代码部分参考 设计清单具体实现截图参考文献设计获取 前言 💗博主介绍:✌全网粉丝10W+,CSDN特邀作者、博客专家、CSDN新星计划导师,一名热衷于单片机技术探索与分享的博主、专注于 精通51/STM32/MSP430/AVR等单片机设计 主要对象是咱们电子相关专业的大学生,希望您们都共创辉煌!✌💗 👇🏻 精彩专栏 推荐订

Spring的设计⽬标——《Spring技术内幕》

读《Spring技术内幕》第二版,计文柯著。 如果我们要简要地描述Spring的设计⽬标,可以这么说,Spring为开发者提供的是⼀个⼀站式的轻量级应⽤开发框架(平台)。 作为平台,Spring抽象了我们在 许多应⽤开发中遇到的共性问题;同时,作为⼀个轻量级的应⽤开发框架,Spring和传统的J2EE开发相⽐,有其⾃⾝的特点。 通过这些⾃⾝的特点,Spring充分体现了它的设计理念:在

开题报告中的研究方法设计:AI能帮你做什么?

AIPaperGPT,论文写作神器~ https://www.aipapergpt.com/ 大家都准备开题报告了吗?研究方法部分是不是已经让你头疼到抓狂? 别急,这可是大多数人都会遇到的难题!尤其是研究方法设计这一块,选定性还是定量,怎么搞才能符合老师的要求? 每次到这儿,头脑一片空白。 好消息是,现在AI工具火得一塌糊涂,比如ChatGPT,居然能帮你在研究方法这块儿上出点主意。是不

创业者该如何设计公司的股权架构

本文来自七八点联合IT橘子和车库咖啡的一系列关于设计公司股权结构的讲座。 主讲人何德文: 在公司发展的不同阶段,创业者都会面临公司股权架构设计问题: 1.合伙人合伙创业第一天,就会面临股权架构设计问题(合伙人股权设计); 2.公司早期要引入天使资金,会面临股权架构设计问题(天使融资); 3.公司有三五十号人,要激励中层管理与重要技术人员和公司长期走下去,会面临股权架构设计问题(员工股权激

分布式文件系统设计

分布式文件系统是分布式领域的一个基础应用,其中最著名的毫无疑问是 HDFS/GFS。如今该领域已经趋向于成熟,但了解它的设计要点和思想,对我们将来面临类似场景 / 问题时,具有借鉴意义。并且,分布式文件系统并非只有 HDFS/GFS 这一种形态,在它之外,还有其他形态各异、各有千秋的产品形态,对它们的了解,也对扩展我们的视野有所俾益。本文试图分析和思考,在分布式文件系统领域,我们要解决哪些问题、有

(入门篇)JavaScript 网页设计案例浅析-简单的交互式图片轮播

网页设计已经成为了每个前端开发者的必备技能,而 JavaScript 作为前端三大基础之一,更是为网页赋予了互动性和动态效果。本篇文章将通过一个简单的 JavaScript 案例,带你了解网页设计中的一些常见技巧和技术原理。今天就说一说一个常见的图片轮播效果。相信大家在各类电商网站、个人博客或者展示页面中,都看到过这种轮播图。它的核心功能是展示多张图片,并且用户可以通过点击按钮,左右切换图片。