当前位置:网站首页>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
边栏推荐
- Identifier, keyword, data type
- Installation and configuration of clion under win10
- 標識符、關鍵字、數據類型
- Thought of reducing Governance -- detailed summary of binary search
- VS Studio 修改C语言scanf等报错
- Key point detection of human hand based on mediapipe
- Express中间件①(中间件的使用)
- What if you encounter symbols you don't know in mathematical formulas
- The latest price trend chart and trading points of London Silver
- Opencv4 QR code recognition test
猜你喜欢

Wechat applet cloud database value assignment to array error

作为一名码农,女友比自己更能码是一种什么体验?

【NeurIPS 2019】Self-Supervised Deep Learning on Point Clouds by Reconstructing Space

使用大华设备开发行AI人流量统计出现时间不正确的原因分析

SQL learning record

Source code and update details of new instance segmentation network panet (path aggregation network for instance segmentation)

ROS series (III): introduction to ROS architecture

中国移动日赚2.85亿很高?其实是5G难带来更多利润,那么钱去哪里了?
![[latex] differences in the way scores are written](/img/77/3aebc8812f3e2d239187b95d3bd49f.png)
[latex] differences in the way scores are written

变量、常量、运算符
随机推荐
A sword is a sword. There is no difference between a wooden sword and a copper sword
Win10 boot VMware virtual machine boot seconds blue screen problem perfect solution
OpenCV----YOLACT实例分割模型推理
将编译安装的mysql加入PATH环境变量
ERROR: Could not find a version that satisfies the requirement win32gui
Express middleware ② (classification of Middleware)
Summary of knowledge map (I)
Alibaba cloud IOT transfer to PostgreSQL database scheme
中国移动日赚2.85亿很高?其实是5G难带来更多利润,那么钱去哪里了?
Qt程序集成EasyPlayer-RTSP流媒体播放器出现画面闪烁是什么原因?
Numpy's broadcasting mechanism (with examples)
【测绘程序设计】坐标方位角推算神器(C#版)
TreeSet课后练习
What is software acceptance testing? What are the benefits of acceptance testing conducted by third-party software testing institutions?
Seekbar custom style details
ROS series (4): ROS communication mechanism series (4): topic communication practice
Network principle | connection management mechanism in TCP / IP important protocol and core mechanism
[AI vision · quick review of robot papers today, issue 30] Thu, 14 APR 2022
PolarMask is not in the models registry
UDP协议与TCP协议