当前位置:网站首页>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
边栏推荐
- Matlab reads multiple fig graphs and then combines them into one graph (in the form of sub graph)
- Vs studio modifies C language scanf and other errors
- 【NeurIPS 2019】Self-Supervised Deep Learning on Point Clouds by Reconstructing Space
- 单片机串口数据处理(1)——串口中断发送数据
- How Zotero quotes in word jump to references / hyperlink
- Man's life
- The difference between lists, tuples, dictionaries and collections
- QT program integration easyplayer RTSP streaming media player screen flicker what is the reason?
- 什么是软件验收测试,第三方软件检测机构进行验收测试有什么好处?
- Basic usage of Google colab (I)
猜你喜欢

Wechat applet canvas draws a simple asymptotic color of the dashboard

知乎有问题,谁来解答?

Xiaomi, which has set the highest sales record of domestic mobile phones in overseas markets, paid renewed attention to the domestic market

Machine translation baseline

Seekbar custom style details

Opencv4 QR code recognition test
![[AI vision · quick review of NLP natural language processing papers today, issue 29] Mon, 14 Feb 2022](/img/34/1db76ac50888196515927fe51b2738.png)
[AI vision · quick review of NLP natural language processing papers today, issue 29] Mon, 14 Feb 2022

【测绘程序设计】坐标反算神器V1.0(附C/C#/VB源程序)

A sword is a sword. There is no difference between a wooden sword and a copper sword

【BIM入门实战】Revit建筑墙体:构造、包络、叠层图文详解
随机推荐
【NeurIPS 2019】Self-Supervised Deep Learning on Point Clouds by Reconstructing Space
Abstract classes, interfaces and common keywords
【BIM入门实战】Revit建筑墙体:构造、包络、叠层图文详解
Wechat applet cloud database value assignment to array error
SQL learning record
[AI vision · quick review of today's sound acoustic papers issue 1] Thu, 14 APR 2022
现货黄金基本介绍
Basic knowledge of convolutional neural network
Concepts of objects and classes
Nel ASA:挪威Herøya设施正式启用
VS Studio 修改C語言scanf等報錯
Identifier, keyword, data type
Express middleware ② (classification of Middleware)
Summary of knowledge map (3)
Key point detection of human hand based on mediapipe
C语言 字符常量
[Li Hongyi 2022 machine learning spring] hw6_ Gan (don't understand...)
Opencv4 QR code recognition test
ROS series (III): introduction to ROS architecture
变量、常量、运算符