// ARM project Easter 2003 // Week 1 // Your crsid your given name your family name // Year-month-day // // This program is free software, released under GNU GPL version 2 // hextoleds.v // Originally written by Richard van der Hoff; minor revision by Frank Stajano. // TUT: comments marked as 'TUT' in these instructor-supplied files // are there for tutorial purposes. Do copy the style of any other // comments, but not of these. If you base your work on this code, remove // the 'TUT' comments. // TUT: never exceed 79 characters per line in your source code (columns 0-78) // 1 2 3 4 5 6 7 // 3456789012345678901234567890123456789012345678901234567890123456789012345678 // Use 4 spaces (no tabs!) for each indent level. module hexToLeds(byte, led1, led0); // Dual LED display driver. // Take an 8-bit input 'byte' and generate the bit patterns to display // it as two hex digits on two adjacent 7-segment LED displays. input [7:0] byte; output [6:0] led1, led0; nibbleToLed n0(byte[3:0], led0); nibbleToLed n1(byte[7:4], led1); endmodule module nibbleToLed(n, led); // Single LED display driver. // Take a 4-bit input 'n' and generate the bit pattern to display it // on a 7-segment display 'led'. Treat the output as 7 bits wide, i.e. // do not drive the decimal point. // seven segment layout: // |-0-| // 5 1 // |-6-| // 4 2 // |-3-| 7 input [3:0] n; output [6:0] led; // A segment is on iff the glyph depicting 'n' contains it. assign led[0] = ~( n == 0 || n == 2 || n == 3 || n == 5 || n == 6 || n == 7 || n == 8 || n == 9 || n == 4'ha || n == 4'he || n == 4'hf ); assign led[1] = ~( n == 0 || n == 1 || n == 2 || n == 3 || n == 4 || n == 7 || n == 8 || n == 9 || n == 4'ha || n == 4'hd ); assign led[2] = ~( n == 0 || n == 1 || n == 3 || n == 4 || n == 5 || n == 6 || n == 7 || n == 8 || n == 9 || n == 4'ha || n == 4'hb || n == 4'hd ); assign led[3] = ~( n == 0 || n == 2 || n == 3 || n == 5 || n == 6 || n == 8 || n == 9 || n == 4'hb || n == 4'hc || n == 4'hd || n == 4'he ); assign led[4] = ~( n == 0 || n == 2 || n == 6 || n == 8 || n == 4'ha || n == 4'hb || n == 4'hc || n == 4'hd || n == 4'he || n == 4'hf ); assign led[5] = ~( n == 0 || n == 4 || n == 5 || n == 6 || n == 8 || n == 9 || n == 4'ha || n == 4'hb || n == 4'he || n == 4'hf ); assign led[6] = ~( n == 2 || n == 3 || n == 4 || n == 5 || n == 6 || n == 8 || n == 9 || n == 4'ha || n == 4'hb || n == 4'hc || n == 4'hd || n == 4'he || n == 4'hf ); endmodule