当前位置:网站首页>VHDL语言实现32位二进制数转BCD码
VHDL语言实现32位二进制数转BCD码
2022-04-23 03:56:00 【Chenxr32】
使用FPGA开发板上的数码管显示数值,需要将数值转换成对应的BCD码,再通过七段译码器将数值显示在数码管上。我用除十取余的方法,用VHDL写了32位二进制数转BCD码代码。
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
ENTITY BIN32_TO_BCD1 IS
PORT(
BIN: IN STD_LOGIC_VECTOR(31 DOWNTO 0);
BCD: OUT STD_LOGIC_VECTOR(39 DOWNTO 0)
);
END ENTITY BIN32_TO_BCD1;
ARCHITECTURE RTL OF BIN32_TO_BCD1 IS
BEGIN
PROCESS(BIN)
VARIABLE TEMP: INTEGER;
VARIABLE BIN_TEMP: INTEGER;
VARIABLE BCD_TEMP: STD_LOGIC_VECTOR(39 DOWNTO 0);
BEGIN
BCD_TEMP:=X"0000000000";
BIN_TEMP:=CONV_INTEGER(BIN);
FOR K IN 0 TO 9 LOOP
TEMP:=BIN_TEMP REM 10;
BCD_TEMP(3+4*K DOWNTO K*4):=CONV_STD_LOGIC_VECTOR(TEMP,4);
BIN_TEMP:=(BIN_TEMP-TEMP)/10;
IF BIN_TEMP=0 THEN
EXIT;
END IF;
END LOOP;
BCD<=BCD_TEMP;
END PROCESS;
END RTL;
本来想用左移加3的算法,但没有成功。上面这个除十取余的方法是将STD_LOGIC_VECTOR转换成INTEGER,然后除十取余提出逐个十进制位。限于VHDL的INTEGER为有符号整型,以上代码其实只能实现31位无符号二进制转BCD码。
版权声明
本文为[Chenxr32]所创,转载请带上原文链接,感谢
https://blog.csdn.net/QDchenxr/article/details/91348999
边栏推荐
- Express中间件①(中间件的使用)
- Opencv4 QR code recognition test
- Instructions for fastmock
- SQL topic exercise summary
- [AI vision · quick review of NLP natural language processing papers today, issue 30] Thu, 14 APR 2022
- Cmake qmake simple knowledge
- Mysql出现2013 Lost connection to MySQL server during query
- [string] ranking of country names ----- problem solving notes
- VS Studio 修改C語言scanf等報錯
- According to the category information and coordinate information of the XML file, the category area corresponding to the image is pulled out and stored in the folder.
猜你喜欢
(valid for personal testing) compilation guide of paddedetection on Jetson
将编译安装的mysql加入PATH环境变量
創下國產手機在海外市場銷量最高紀錄的小米,重新關注國內市場
What if you encounter symbols you don't know in mathematical formulas
Seekbar custom style details
【ICCV 2019】MAP-VAE:Multi-Angle Point Cloud-VAE: Unsupervised Feature Learning for 3D Point Clouds..
Source code and update details of new instance segmentation network panet (path aggregation network for instance segmentation)
AI CC 2019 installation tutorial under win10 (super detailed - small white version)
Now is the best time to empower industrial visual inspection with AI
Variables, constants, operators
随机推荐
ROS series (IV): ROS communication mechanism series (5): Service Communication Practice
QtSpim手册-中文翻译
RuntimeError: output with shape [4, 1, 512, 512] doesn‘t match the broadcast shape[4, 4, 512, 512]
[AI vision · quick review of NLP natural language processing papers today, issue 29] Mon, 14 Feb 2022
Win10 boot VMware virtual machine boot seconds blue screen problem perfect solution
C语言 字符常量
【NeurIPS 2019】Self-Supervised Deep Learning on Point Clouds by Reconstructing Space
Activity supports multi window display
标识符、关键字、数据类型
【BIM+GIS】ArcGIS Pro2.8如何打开Revit模型,BIM和GIS融合?
抽象类、接口、常用关键字
Wechat applet cloud database value assignment to array error
Mysql出现2013 Lost connection to MySQL server during query
Express中间件①(中间件的使用)
Use of rotary selector wheelpicker
[AI vision · quick review of today's sound acoustic papers issue 1] Thu, 14 APR 2022
ROS series (III): introduction to ROS architecture
標識符、關鍵字、數據類型
Wechat payment iframe sub page has no response
STM32F4单片机ADC采样及ARM-DSP库的FFT