/*2017.3.22 zc in xidian
方法为左移动加三
binary to BCD (只限255以内的数)
输入是几个bit二进制 则移动几次
enable 是输出标志 为1表示可以读转换后的数据的了*/
module shift_division(input clk_50M,
input reset,
input [7:0]data,
output reg [3:0] bai,
output reg [3:0] shi,
output reg [3:0] ge,
output enable);
reg [15:0] cnt;
reg [19:0] later_data;
always@(posedge clk_50M or negedge reset)
begin
if(!reset)
cnt<=0;
else
if(cnt<=10)
cnt<=cnt+1;
else
cnt<=0;
end
always@(posedge clk_50M or negedge reset)
begin
if(!reset)
begin later_data=0; end
else
if(clk_50M==1)
if(cnt==0) later_data={12'd0,data};
else
if(cnt<=8)
begin
if(later_data[11:8]>=5)
later_data[11:8]=later_data[11:8]+3;
if(later_data[15:12]>=5)
later_data[15:12]=later_data[15:12]+3;
if(later_data[19:16]>=5)
later_data[19:16]=later_data[19:16]+3;
later_data=later_data<<1;
end
end
always@(posedge clk_50M or negedge reset)
begin
if(!reset)
begin bai<=0;ge<=0;shi<=0; end
else
if(cnt==9)
begin
bai<=later_data[19:16];
shi<=later_data[15:12];
ge<=later_data[11:8];
end
end