--- /dev/null
+/* ****************************************************************************\r
+-- Source file: mesa_ascii2nibble.v \r
+-- Date: October 4, 2015\r
+-- Author: khubbard\r
+-- Description: Convert an ASCII character to a binary nibble.\r
+-- Language: Verilog-2001 and VHDL-1993\r
+-- Simulation: Mentor-Modelsim \r
+-- Synthesis: Lattice \r
+-- License: This project is licensed with the CERN Open Hardware Licence\r
+-- v1.2. You may redistribute and modify this project under the\r
+-- terms of the CERN OHL v.1.2. (http://ohwr.org/cernohl).\r
+-- This project is distributed WITHOUT ANY EXPRESS OR IMPLIED\r
+-- WARRANTY, INCLUDING OF MERCHANTABILITY, SATISFACTORY QUALITY\r
+-- AND FITNESS FOR A PARTICULAR PURPOSE. Please see the CERN OHL\r
+-- v.1.2 for applicable Conditions.\r
+--\r
+-- Revision History:\r
+-- Ver# When Who What\r
+-- ---- -------- -------- ---------------------------------------------------\r
+-- 0.1 10.04.15 khubbard Creation\r
+-- ***************************************************************************/\r
+`default_nettype none // Strictly enforce all nets to be declared\r
+\r
+module mesa_ascii2nibble\r
+(\r
+ input wire clk,\r
+ input wire rx_char_en,\r
+ input wire [7:0] rx_char_d,\r
+ output reg rx_nib_en,\r
+ output reg [3:0] rx_nib_d\r
+);// module mesa_ascii2nibble\r
+\r
+ reg [4:0] rx_nib_bin; // MSB is Valid Char Flag for "0"-"F"\r
+\r
+\r
+//-----------------------------------------------------------------------------\r
+// When UART receives an ASCII char, see if it is 0-9,a-f,A-F else toss \r
+//-----------------------------------------------------------------------------\r
+always @ ( posedge clk ) begin : proc_rx \r
+ rx_nib_d <= rx_nib_bin[3:0];\r
+ rx_nib_en <= rx_char_en & rx_nib_bin[4];\r
+end\r
+\r
+\r
+//-----------------------------------------------------------------------------\r
+// Convert ASCII to binary nibbles. Toss and ignore all other received chars\r
+// 0x30 = "0"\r
+// 0x39 = "9"\r
+// 0x41 = "A"\r
+// 0x46 = "F"\r
+// 0x61 = "a"\r
+// 0x66 = "f"\r
+//-----------------------------------------------------------------------------\r
+always @ ( * ) begin : proc_lut\r
+ begin\r
+ case( rx_char_d[7:0] )\r
+ 8'h30 : rx_nib_bin[4:0] <= 5'h10;// 0\r
+ 8'h31 : rx_nib_bin[4:0] <= 5'h11;\r
+ 8'h32 : rx_nib_bin[4:0] <= 5'h12;\r
+ 8'h33 : rx_nib_bin[4:0] <= 5'h13;\r
+ 8'h34 : rx_nib_bin[4:0] <= 5'h14;\r
+ 8'h35 : rx_nib_bin[4:0] <= 5'h15;\r
+ 8'h36 : rx_nib_bin[4:0] <= 5'h16;\r
+ 8'h37 : rx_nib_bin[4:0] <= 5'h17;\r
+ 8'h38 : rx_nib_bin[4:0] <= 5'h18;\r
+ 8'h39 : rx_nib_bin[4:0] <= 5'h19;// 9\r
+\r
+ 8'h41 : rx_nib_bin[4:0] <= 5'h1A;// A\r
+ 8'h42 : rx_nib_bin[4:0] <= 5'h1B;\r
+ 8'h43 : rx_nib_bin[4:0] <= 5'h1C;\r
+ 8'h44 : rx_nib_bin[4:0] <= 5'h1D;\r
+ 8'h45 : rx_nib_bin[4:0] <= 5'h1E;\r
+ 8'h46 : rx_nib_bin[4:0] <= 5'h1F;// F\r
+\r
+ 8'h61 : rx_nib_bin[4:0] <= 5'h1A;// a\r
+ 8'h62 : rx_nib_bin[4:0] <= 5'h1B;\r
+ 8'h63 : rx_nib_bin[4:0] <= 5'h1C;\r
+ 8'h64 : rx_nib_bin[4:0] <= 5'h1D;\r
+ 8'h65 : rx_nib_bin[4:0] <= 5'h1E;\r
+ 8'h66 : rx_nib_bin[4:0] <= 5'h1F;// f\r
+\r
+ default : rx_nib_bin[4:0] <= 5'h0F;\r
+ endcase\r
+ end\r
+end // proc_lut\r
+\r
+\r
+endmodule // mesa_ascii2nibble\r