当前位置:网站首页>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
边栏推荐
- 【测绘程序设计】坐标方位角推算神器(C#版)
- Seekbar custom style details
- ERROR: Could not find a version that satisfies the requirement win32gui
- TreeSet课后练习
- Digital image processing third edition Gonzalez notes Chapter 2
- 常用的辅助类
- Zotero6. Version 0 quicklook cannot be used / Chinese garbled code will not be displayed
- Man's life
- Now is the best time to empower industrial visual inspection with AI
- Second kill all interval related problems
猜你喜欢
ROS series (IV): ROS communication mechanism series (2): Service Communication
Does China Mobile earn 285 million a day? In fact, 5g is difficult to bring more profits, so where is the money?
Second kill all interval related problems
[AI vision · quick review of NLP natural language processing papers today, issue 30] Thu, 14 APR 2022
The whole process of connecting the newly created unbutu system virtual machine with xshell and xftp
Abstract classes, interfaces and common keywords
What if you encounter symbols you don't know in mathematical formulas
【测绘程序设计】坐标反算神器V1.0(附C/C#/VB源程序)
阿里云IoT流转到postgresql数据库方案
Instructions for fastmock
随机推荐
[Li Hongyi 2022 machine learning spring] hw6_ Gan (don't understand...)
php导出Excel表格
伦敦银最新价格走势图与买卖点
Xiaomi, qui a établi le plus grand volume de ventes de téléphones portables domestiques sur le marché d'outre - mer, se concentre de nouveau sur le marché intérieur
Let matlab2018b support the mex configuration of vs2019
Second kill all interval related problems
UDP协议与TCP协议
How to introduce opencv into cmake project
ROS series (IV): ROS communication mechanism series (6): parameter server operation
Operating skills of spot gold_ Wave estimation curve
Why is it necessary to divide the variance by 255^2 when adding Gaussian noise using the imnoise function of MATLAB
【测绘程序设计】坐标方位角推算神器(C#版)
【BIM入门实战】Revit建筑墙体:构造、包络、叠层图文详解
【ICCV 2019】MAP-VAE:Multi-Angle Point Cloud-VAE: Unsupervised Feature Learning for 3D Point Clouds..
Difference between LabVIEW small end sequence and large end sequence
Paddlepaddle does not support arm64 architecture.
Cmake qmake simple knowledge
創下國產手機在海外市場銷量最高紀錄的小米,重新關注國內市場
ROS series (IV): ROS communication mechanism series (1): topic communication
Raspberry pie 3B logs into the wired end of Ruijie campus network through mentohust, creates WiFi (open hotspot) for other devices, and realizes self startup at the same time