///////////////////////////////////////////////////////////////////////////////////////////////////
// File: hex_to_ascii.v
//-------------------------------------------------------------------
//                                                                 
//  © 2022 Microchip Technology Inc. and its subsidiaries
//  All rights reserved.
//                                                                  
//  ANY USE OR REDISTRIBUTION IN PART OR IN WHOLE MUST BE HANDLED IN 
//  ACCORDANCE WITH THE MICROCHIP LICENSE AGREEMENT AND MUST BE APPROVED 
//  IN ADVANCE IN WRITING.
//
//------------------------------------------------------------------
// Title       : hex_to_ascii.v
// Created     : November-2018
// Description : The hex_to_ascii module Convert 8-bit hex to 16-bit ascii value and ASCII Output is swapted so that UART can print MSB and LSB.
//    
// Revision    : 1.0 Initial Release
// Hierarchy   :
//                 -- binary_to_ascii_apb
//                   -- hex_to_ascii
//                       
/////////////////////////////////////////////////////////////////////////////////////////////////// 

`timescale 1ns / 100ps

// Hex_to_ascii.v
module Binary2Ascii(ascii, binary);

	output [15:0] ascii;
	input  [7:0] binary;

	// ASCII Output is swapted so that UART can print MSB and LSB then
	Nibble2Ascii MSB 
	(.ascii(ascii[7:0]), .nibble(binary[7:4]));

	Nibble2Ascii LSB 
	(.ascii(ascii[15:8]), .nibble(binary[3:0]));



endmodule

module Nibble2Ascii(ascii, nibble);

	parameter LO = 1'b0, HI = 1'b1;

	output [7:0] ascii;
	input  [3:0] nibble;

	wire IsDecimal;

	assign IsDecimal = ((nibble < 4'd10)? HI : LO);

	assign ascii[7:4] = ((IsDecimal == HI)? 4'b0011:4'b0110);
	assign ascii[3:0] = nibble - ((IsDecimal == HI)? 4'd0:4'd9);

endmodule

