这类数据处理用verilog语言应该如何实现
[我使用的是verilog语言]想对一组8位二进制数据进行以下处理:
1.先将输入的二进制转换为十进制
2.然后分别取出其个位十位(XY) 【PS:原始数据不大于99】
3.然后再将X、Y分别用四位二进制数表示出来。
例如:输入0101_0101
1.转为十进制=85
2.X=8 Y=5;
3.X=1000 Y=0101;(输出~)
初学verilog,想问一下大家这样的数据处理应该如何实现? 查表吧,占不了多少资源 如果对转换时间要求不高,可以用计数的方法,这样占用的资源非常少,如下:
module Hex2Dec(
//Clocks
iClk_40, //Clock
iReset_N,//Reset
//Hex intput
iHex, //Hex input
//Decimal output
oDigit0, //Digit 0
oDigit1 //Digit 1
);
/* PORT declarations
*/
//Clocks input
input iClk_40; //Clock
input iReset_N;//Reset
//Hex intput
input[ 7: 0] iHex; //Hex input
//Decimal output
output reg [ 3: 0] oDigit0; //Digit 0
output reg [ 3: 0] oDigit1; //Digit 1
/* REG/WIRE declarations
*/
reg[ 7: 0] hexCnt; //Hex counter
reg[ 7: 0] decCnt; //Decimal counter
wire endOfCnt; //End of counting
/* LOGIC Descriptions
*/
//Decimal output
always @(posedge iClk_40)
if(endOfCnt) begin
oDigit0 <= decCnt[ 3: 0];
oDigit1 <= decCnt[ 7: 4];
end
//Hex down-counting
always @(posedge iClk_40 or negedge iReset_N)
if(!iReset_N) begin
hexCnt <= 8'h00;
end
else if(endOfCnt) begin
hexCnt <= iHex;
end
else begin
hexCnt <= hexCnt - 8'h01;
end
//End of counting
assign endOfCnt = (hexCnt == 8'h00);
//Decimal up-counting
always @(posedge iClk_40 or negedge iReset_N)
if(!iReset_N) begin
decCnt <= 8'd0;
end
else if(endOfCnt) begin
decCnt <= 8'd0;
end
else begin
//Digit 0
if(decCnt == 4'd9) decCnt <= 4'd0;
else decCnt <= decCnt + 4'd1;
//Digit 1
if(decCnt == 4'd9) decCnt <= decCnt + 4'd1;
end
endmodule //Hex2Dec mitchell 发表于 2013-6-1 23:23 static/image/common/back.gif
如果对转换时间要求不高,可以用计数的方法,这样占用的资源非常少,如下:
module Hex2Dec(
谢谢~我去捣鼓一下~! 给个思路,你这个最好是按 二进制转BCD码的方式,其后你可以取高4位就是了。 二进制转BCD码有专用的74IC,应该不难,查一下算法 参考这个文章 http://www.dzsc.com/data/html/2010-9-1/85277.html 就是把十进制转换为BCD码嘛!我记得书上一般会讲到的! 计数的方法好
页:
[1]