Upload
hoangthuy
View
262
Download
4
Embed Size (px)
Citation preview
CSC258H1 Final Project Report
Morse Code Decoder
Sasa Milicg3milic
Madelaine Pageg3maddie
We implemented a Morse code decoder that takesMorse code as its input and outputs the corre-sponding text.
December 3, 2013
CSC258 - Final Project Report
Introduction
Our project implements a system that translates Morse Code to text. Morsecodes are input using a single key KEY[0] (similar to a traditional “straight key”telegraph—see Figure 11) and decoded messages are shown on the LCD displayon the DE2 board.
Why this project? Why is it cool?
Figure 1: Straight telegraph key
Telegraphs using Morse Code were one ofthe first forms of communication using elec-tric signals. We believe creating a some-what simple implementation of such a de-vice is interesting firstly for historical rea-sons. As children of the information age,attempting to implement one of the earli-est forms of telecommunication offers an in-teresting perspective on today’s electroniccommunication. Even though such technol-ogy has progressed so far that we now look at a telegraph as “primative” electroniccommunication, such a relatively simple device still exhibits significant complex-ity. Our implementation gave us more appreciation for the profound complexitiesfound in today’s modern devices. This project changed us. We are better peoplenow.
How is it relevant to course material?
At a very high level, we accomplish the task of explicitly converting analog inputs(the pressing of a key for some length of time) to digital values (letters on an LCDscreen). This is essentially what we first learn in this course: how we go fromelectrical (analog) signals to discrete digital values (and then we learn about thepossibilities provided by digital logic once this transition occurs.)
A more direct overlap between our project and the material covered in this courseis the implementation of our FSMs. This project displays the power of an FSMon a small scale: we have many possible outputs (alphanumeric values) producedwith only one input source (key)! Additionally, this project requires a good handleof Verilog because all modules were implemented by us; no additional code wasused except for the LCD display code2 given in Lab 6.
1http://www.diclib.com/en_st_electrical2http://www.johnloomis.org/digitallab/lcdlab/lcdlab3/lcdlab3.html
1
CSC258 - Final Project Report
Methods
What did we do?
The “core” of our circuitry are the two FSMs. In our first FSM, states are lettersand a transition is a DOT, DASH, or GAP (a simplified version containing onlyletters E, T, I, A, N, M is shown in Figure 2; it’s easy to see how such an FSM cabe extended). The purpose of the other FSM is to translate key inputs into theseDOT s, DASH es, and GAPs (see Figure 3). At each clock pulse, depending onwhether the key input is high or not, the FSM transitions to a new state. Once atransition to low (state L) occurs, a DOT or DASH or GAP is output dependingon the previous state of the FSM.
Further implementation details can be found in following section where we offer asummary of weekly accomplishments.
ε
E
I A
T
N M
Figure 2: State diagram for the reduced Morse FSM where inputs are DOT s,DASHES, and GAPs, and the states are letters and numbers. This reduced FSMonly contains letters (states) with a code length of at most two. Transitions trig-gered by a DOT (resp. DASH, GAP) input are represented by a dotted (resp.DASH ed, thin solid) line.
How did it go?
Here we include a week-by-week description of what we implemented and how itwent (good and bad)!
Week One We implemented a full version (every alphanumeric character hada corresponding state) of the FSM in Figure 2. States were encoded by sevendigit binary numbers within the FSM. A decoder was implemented that converted
2
CSC258 - Final Project Report
L H1 H2 H31
Figure 3: State diagram for our keyer module. A transition occurs at every clockpulse and its value dictated by whether the key input is high (thick line) or low(thin line).
these state codes to the hexadecimal values required in order to display on theLCD screen. In this initial phase, the inputs to the FSM (DOT, DASH, GAP)were provided by switch inputs and a manual clock signal.
Figure 4: Morse Code
We encountered some difficulty in our at-tempts to allow number codes as well. Notein Figure 4 that each letter in the alphabet
can be produced by adding a E or a T toa previous letter’s code. And thus, if onlydisplaying letters, we can have all states inthe FSM correspond to a letter; this simpli-fies the design. However, this isn’t the casefor numbers. In order to display numbersas well, we had to create several interme-diate states (for example, BEFORETWO,which we transition to from state U after aDASH input.)
Week Two We configured the KEY button to act as our sole input signal. Theintent was to have KEY act as a traditional telegraph “straight key”. In a straightkey, the signal is high when the knob is pressed, and low when it is released. Thelength and timing of the dots and dashes are controlled by the operator. Thismeans that we had to have one of our modules recognize the length of time acertain input is produced, and convert it to one of DASH, DOT or GAP.
Timing was probably the most difficult part of this project to get right, as weexpected. We first considered options to allow for variations in speed. Initially,we allowed the user to input a speed using SW[3:0] corresponding to values from1-15 hertz. This would have allowed an operator to adjust a DOT signal from 1
3
CSC258 - Final Project Report
second to 115
of a second. The simplest way we found to do this was to use thebuilt-in division module; however, at some point later on in our implementation,during compile time we received an error somewhere within the division module.Much of that code was unintelligible to us, so we abandoned the idea of havingvariable input speeds.
This wasn’t entirely futile because it allowed us to experiment with speeds sowe settled on 6 hertz. We simply implemented a counter like in a previous lab andgenerated a 6 Hertz clock signal. This signal was displayed on LEDG[0] in orderto aid the operator when keying in values (one “flash” corresponds to the lengthof one DOT, etc.)
In another attempt to aid the user (“operator”), we have certain LEDR lights flashdepending on whether a DOT or DASH was received. That is, when an operatorholds down the key for 3 or more clock pulses and then releases, LEDR[1:0] flashto signal that a DASH input was received. Similarly, if the key is held down for 1clock pulse and is then released, LEDR[0] flashes.
Week Three The milestone for the final week was to have the LCD screen“scroll” the decoded message instead of simply displaying one letter at a time.Another milestone was to connect audio to our main module in order to have thekey output a sound when pressed down (similar to what we imagine a real tele-graph behaving like.) We initially thought this would be a simple task: simplyimplement a shift register that stores the currently displayed letters, shifting everytime a new letter occurs; however, this didn’t work initially.
We had an error where every time a new letter was input, each segment of the LCDwould display that letter. This was difficult to debug because the code (specificallythe always block used for our shift register) should have behaved a certain wayfrom our understanding of Verilog, but it did not. Under the suggestion of ourlab TA, Fernando, we created a new signal newletter that goes high whenevera new letter is output from our FSM, and remains low otherwise. The positiveedge of this signal was then used as the only signal in the always sensitivity list(replacing the letter itself). This worked. We have no clue why. This goes againstour understanding of how the always block (that it is executed every time a valuein the sensitivity list changes). We thought this change wouldn’t change the func-tionality of the circuit, but it did (and we’re glad!)
A final design choice was made towards the end of our last lab. It was clearto us that it is easy to make mistakes when keying in Morse code, especially with
4
CSC258 - Final Project Report
longer words (we think this is inherent in any Morse code system, and is not neces-sarily a problem with our particular implementation.) It seemed natural to includea reset button. And so we included an added input (KEY[1]) to our decoder usedto reset the LCD screen to an all-blank display.
We underestimated the time it would take us to add audio to our main module,and so this part of our intended milestone was unfortunately not implemented.
Conclusion
We achieved our main goals for this project. Audio could have been added tomake the project more “realistic”, but we believe this is a minor issue; the decoderfunctions in the way we had intended. What we have learned isn’t so much hard-ware technicalities, but overarching themes when it comes hardware design andthe analog-to-digital interface.
We spent a lot of time thinking about how to best convert an analog input into adigital representation. This raised many design-related questions that we realizeare always faced when doing some sort of analog-digital conversion, like in all ofour modern day electronic devices. Of course, our conversion task was relativelysimple. But at the same time it made us think about the kind of design decisionsengineers and designers make when, for example, deciding how to interpret thepressure applied on a smart phone screen as some discrete value.
5
CSC258 - Final Project Report
Appendix (Verilog code)
1 module morse decoder (input CLOCK 50, // 50 MHz c l o c k
3 input [ 3 : 0 ] KEY, // Pushbutton [ 3 : 0 ]input [ 1 7 : 0 ] SW, // Toggle Switch [ 1 7 : 0 ]
5 output [ 6 : 0 ] HEX0,HEX1,HEX2,HEX3,HEX4,HEX5,HEX6,HEX7, // SevenSegment D i g i t s
output [ 8 : 0 ] LEDG, // LED Green7 output [ 1 7 : 0 ] LEDR, // LED Red
inout [ 3 5 : 0 ] GPIO 0 ,GPIO 1 , // GPIO Connections9 // LCD Module 16X2
output LCD ON, // LCD Power ON/OFF11 output LCD BLON, // LCD Back Ligh t ON/OFF
output LCDRW, // LCD Read/Write Se l e c t , 0 = Write , 1 = Read13 output LCD EN, // LCD Enable
output LCD RS, // LCD Command/Data Se l e c t , 0 = Command, 1 = Data15 inout [ 7 : 0 ] LCD DATA, // LCD Data bus 8 b i t s
// AUDIO17 // Clock Input (50 MHz)
input CLOCK 27, // 27 MHz19 // Push Buttons
// input [ 3 : 0 ] KEY,21 // DPDT Switches
// 7−SEG Disp lays23 // output [ 6 : 0 ] HEX0, HEX1, HEX2, HEX3, HEX4, HEX5, HEX6, HEX7,
// LEDs25 // output [ 8 : 0 ] LEDG, // LED Green [ 8 : 0 ]
// output [ 1 7 : 0 ] LEDR, // LED Red [ 1 7 : 0 ]27 // TV Decoder
output TD RESET, // TV Decoder Reset29 // I2C
inout I2C SDAT , // I2C Data31 output I2C SCLK , // I2C Clock
// Audio CODEC33 output /∗ inout ∗/ AUDADCLRCK, // Audio CODEC ADC LR Clock
input AUDADCDAT, // Audio CODEC ADC Data35 output /∗ inout ∗/ AUDDACLRCK, // Audio CODEC DAC LR Clock
output AUDDACDAT, // Audio CODEC DAC Data37 inout AUD BCLK, // Audio CODEC Bit−Stream Clock
output AUDXCK // Audio CODEC Chip Clock39 // GPIO Connections
) ;41
// r e s e t de l ay g i v e s some time f o r p e r i p h e r a l s to i n i t i a l i z e43 wire DLY RST;
Reset Delay r0 ( . iCLK(CLOCK 50) , .oRESET(DLY RST) ) ;45
6
CSC258 - Final Project Report
// Send sw i t ch e s to red l e d s47 // as s i gn LEDR = SW;
49 // turn LCD ONa s s i gn LCD ON = 1 ’ b1 ;
51 a s s i gn LCD BLON = 1 ’ b1 ;/////////////////
53// A l l inout por t turn to t r i−s t a t e
55 a s s i gn GPIO 0 = 36 ’ hzzzzzzzzz ;a s s i gn GPIO 1 = 36 ’ hzzzzzzzzz ;
57wire [ 6 : 0 ] myclock ;
59 //wire RST;a s s i gn RST = KEY[ 0 ] ;
61/////////////////////////
63 // MY SHIT STARTS HERE ///////////////////////////
65wire c l k ; // c l o c k speed s p e c i f i e d by SW ( he r t z )
67 un i t count e r U (CLOCK 50, SW[ 3 : 0 ] , c l k ) ;// as s i gn LEDG[ 0 ] = c l k ;
69wire [ 1 : 0 ] beep ;
71 wire c lk2 ;a s s i gn LEDG[ 0 ] = c lk2 ; // DEBUGGING
73 a s s i gn LEDR[ 1 : 0 ] = beep ; // f o r debugg ing purposeskeyer K ( clk , ˜KEY[ 0 ] , beep , c lk2 ) ;
75wire new l e t t e r ;
77 wire [ 6 : 0 ] l e t t e r ;// as s i gn LEDR = s t a t e ; // f o r debugg ing purposes
79 // as s i gn LEDR[ 1 7 : 1 2 ] = s t a t e ;fsm F ( clk2 , beep , l e t t e r , LEDR[ 1 7 : 1 2 ] , n ew l e t t e r ) ;
81// l c d are i n i t i a l i z e d to b lank
83 reg [ 7 : 0 ] rhex0 = 8 ’ h20 ;reg [ 7 : 0 ] rhex1 = 8 ’ h20 ;
85 reg [ 7 : 0 ] rhex2 = 8 ’ h20 ;reg [ 7 : 0 ] rhex3 = 8 ’ h20 ;
87 reg [ 7 : 0 ] rhex4 = 8 ’ h20 ;reg [ 7 : 0 ] rhex5 = 8 ’ h20 ;
89 reg [ 7 : 0 ] rhex6 = 8 ’ h20 ;reg [ 7 : 0 ] rhex7 = 8 ’ h20 ;
91 reg [ 7 : 0 ] rhex8 = 8 ’ h20 ;
93 wire [ 7 : 0 ] n ew l e t t e r ;
7
CSC258 - Final Project Report
95 // crea t e r e s e t bu t tonwire r s t ;
97 a s s i gn r s t = KEY[ 1 ] ;
99// as s i gn co r r e c t l e t t e r to s t a t e
101 mux8bit9to1 MUX1 ( l e t t e r , n ew l e t t e r ) ;
103 a s s i gn LEDG[ 3 ] = new l e t t e r ;// a l l ow ’ s c r o l l i n g ’
105 always @ ( posedge new l e t t e r or negedge r s t )begin
107 i f (˜ r s t ) beginrhex8 = 8 ’ h20 ;
109 rhex7 = 8 ’ h20 ;rhex6 = 8 ’ h20 ;
111 rhex5 = 8 ’ h20 ;rhex4 = 8 ’ h20 ;
113 rhex3 = 8 ’ h20 ;rhex2 = 8 ’ h20 ;
115 rhex1 = 8 ’ h20 ;rhex0 = 8 ’ h20 ;
117 end e l s e beginrhex8 = rhex7 ;
119 rhex7 = rhex6 ;rhex6 = rhex5 ;
121 rhex5 = rhex4 ;rhex4 = rhex3 ;
123 rhex3 = rhex2 ;rhex2 = rhex1 ;
125 rhex1 = rhex0 ;rhex0 = new l e t t e r ;
127 endend
129LCD Display u1 (
131 // Host Side. iCLK 50MHZ(CLOCK 50) ,
133 . iRST N(DLY RST) ,. hex0 ( rhex0 ) ,
135 . hex1 ( rhex1 ) ,. hex2 ( rhex2 ) ,
137 . hex3 ( rhex3 ) ,. hex4 ( rhex4 ) ,
139 . hex5 ( rhex5 ) ,. hex6 ( rhex6 ) ,
141 . hex7 ( rhex7 ) ,. hex8 ( rhex8 ) ,
143 // LCD Side
8
CSC258 - Final Project Report
.DATA BUS(LCDDATA) ,145 .LCDRW(LCDRW) ,
.LCD E(LCD EN) ,147 .LCD RS(LCD RS)
) ;
morse decoder
module fsm ( clk2 , in , l e t t e r , LEDR, new l e t t e r ) ;2 input c lk2 ;
input [ 1 : 0 ] in ;4 output [ 5 : 0 ] LEDR; // DEBUGGING
output reg [ 5 : 0 ] l e t t e r = 6 ’ b000000 ;6 output reg new l e t t e r ;
reg [ 5 : 0 ] s t a t e = 6 ’ b000000 ;8
// as s i gn LEDR = s t a t e ; // DEBUGGING10
parameter [ 1 : 0 ] DOT = 2 ’ b01 ;12 parameter [ 1 : 0 ] DASH = 2 ’ b11 ;
parameter [ 1 : 0 ] GAP = 2 ’ b00 ;14
parameter [ 5 : 0 ] BLANK = 6 ’ b111111 ;16 parameter [ 5 : 0 ] A = 6 ’ b011010 ;
parameter [ 5 : 0 ] B = 6 ’ b000001 ;18 parameter [ 5 : 0 ] C = 6 ’ b000010 ;
parameter [ 5 : 0 ] D = 6 ’ b000011 ;20 parameter [ 5 : 0 ] E = 6 ’ b000100 ;
parameter [ 5 : 0 ] F = 6 ’ b000101 ;22 parameter [ 5 : 0 ] G = 6 ’ b000110 ;
parameter [ 5 : 0 ] H = 6 ’ b000111 ;24 parameter [ 5 : 0 ] I = 6 ’ b001000 ;
parameter [ 5 : 0 ] J = 6 ’ b001001 ;26 parameter [ 5 : 0 ] K = 6 ’ b001010 ;
parameter [ 5 : 0 ] L = 6 ’ b001011 ;28 parameter [ 5 : 0 ] M = 6 ’ b001100 ;
parameter [ 5 : 0 ] N = 6 ’ b001101 ;30 parameter [ 5 : 0 ] O = 6 ’ b001110 ;
parameter [ 5 : 0 ] P = 6 ’ b001111 ;32 parameter [ 5 : 0 ] Q = 6 ’ b010000 ;
parameter [ 5 : 0 ] R = 6 ’ b010001 ;34 parameter [ 5 : 0 ] S = 6 ’ b010010 ;
parameter [ 5 : 0 ] T = 6 ’ b010011 ;36 parameter [ 5 : 0 ] U = 6 ’ b010100 ;
parameter [ 5 : 0 ] V = 6 ’ b010101 ;38 parameter [ 5 : 0 ] W = 6 ’ b010110 ;
parameter [ 5 : 0 ] X = 6 ’ b010111 ;40 parameter [ 5 : 0 ] Y = 6 ’ b011000 ;
parameter [ 5 : 0 ] Z = 6 ’ b011001 ;
9
CSC258 - Final Project Report
42 parameter [ 5 : 0 ] ONE = 6 ’ b011010 ;parameter [ 5 : 0 ] TWO = 6 ’ b011011 ;
44 parameter [ 5 : 0 ] THREE = 6 ’ b011100 ;parameter [ 5 : 0 ] FOUR = 6 ’ b011101 ;
46 parameter [ 5 : 0 ] FIVE = 6 ’ b011110 ;parameter [ 5 : 0 ] SIX = 6 ’ b011111 ;
48 parameter [ 5 : 0 ] SEVEN = 6 ’ b100000 ;parameter [ 5 : 0 ] EIGHT = 6 ’ b100001 ;
50 parameter [ 5 : 0 ] NINE = 6 ’ b100010 ;parameter [ 5 : 0 ] ZERO = 6 ’ b100011 ;
52 parameter [ 5 : 0 ] BEFORETWO = 6 ’ b100100 ;parameter [ 5 : 0 ] BEFOREEIGHT = 6 ’ b100101 ;
54 parameter [ 5 : 0 ] BEFORENINE = 6 ’ b100110 ;
56 always @ ( posedge c lk2 )begin
58 new l e t t e r = 0 ;case ( s t a t e )
60 // l e t t e r s are shown in order o f morse code l en g t hBLANK: case ( in )
62 DOT: s t a t e = E;DASH: s t a t e = T;
64 d e f au l t : begin new l e t t e r =1;l e t t e r = BLANK;
66 endendcase
68E: case ( in )
70 DOT: s t a t e = I ;DASH: s t a t e = A;
72 d e f au l t : begin new l e t t e r =1;l e t t e r = E;
74 s t a t e = BLANK;end
76 endcase
78 T: case ( in )DOT: s t a t e = N;
80 DASH: s t a t e = M;de f au l t : begin new l e t t e r =1;
82 l e t t e r = T;s t a t e = BLANK;
84 endendcase
86I : case ( in )
88 DOT: s t a t e = S ;DASH: s t a t e = U;
90 d e f au l t : begin new l e t t e r =1;
10
CSC258 - Final Project Report
l e t t e r = I ;92 s t a t e = BLANK;
end94 endcase
96 A: case ( in )DOT: s t a t e = R;
98 DASH: s t a t e = W;de f au l t : begin new l e t t e r =1;
100 l e t t e r = A;s t a t e = BLANK;
102 endendcase
104N: case ( in )
106 DOT: s t a t e = D;DASH: s t a t e = K;
108 d e f au l t : begin new l e t t e r =1;l e t t e r = N;
110 s t a t e = BLANK;end
112 endcase
114 M: case ( in )DOT: s t a t e = G;
116 DASH: s t a t e = O;d e f au l t : begin new l e t t e r =1;
118 l e t t e r = M;s t a t e = BLANK;
120 endendcase
122S : case ( in )
124 DOT: s t a t e = H;DASH: s t a t e = V;
126 d e f au l t : begin new l e t t e r =1;l e t t e r = S ;
128 s t a t e = BLANK;end
130 endcase
132 R: case ( in )DOT: s t a t e = L ;
134 d e f au l t : begin new l e t t e r =1;l e t t e r = R;
136 s t a t e = BLANK;end
138 endcase
11
CSC258 - Final Project Report
140 U: case ( in )DOT: s t a t e = P;
142 DASH: s t a t e = BEFORETWO;de f au l t : begin new l e t t e r =1;
144 l e t t e r = U;s t a t e = BLANK;
146 endendcase
148W: case ( in )
150 DOT: s t a t e = P;DASH: s t a t e = J ;
152 d e f au l t : begin new l e t t e r =1;l e t t e r = W;
154 s t a t e = BLANK;end
156 endcase
158 D: case ( in )DOT: s t a t e = B;
160 DASH: s t a t e = X;d e f au l t : begin new l e t t e r =1;
162 l e t t e r = D;s t a t e = BLANK;
164 endendcase
166K: case ( in )
168 DOT: s t a t e = C;DASH: s t a t e = Y;
170 d e f au l t : begin new l e t t e r =1;l e t t e r = K;
172 s t a t e = BLANK;end
174 endcase
176 G: case ( in )DOT: s t a t e = Z ;
178 DASH: s t a t e = Q;d e f au l t : begin new l e t t e r =1;
180 l e t t e r = G;s t a t e = BLANK;
182 endendcase
184J : case ( in )
186 DASH: s t a t e = ONE;d e f au l t : begin new l e t t e r =1;
188 l e t t e r = J ;
12
CSC258 - Final Project Report
s t a t e = BLANK;190 end
endcase192
V: case ( in )194 DASH: s t a t e = THREE;
d e f au l t : begin new l e t t e r =1;196 l e t t e r = V;
s t a t e = BLANK;198 end
endcase200
H: case ( in )202 DOT: s t a t e = FIVE ;
DASH: s t a t e = FOUR;204 d e f au l t : begin new l e t t e r =1;
l e t t e r = H;206 s t a t e = BLANK;
end208 endcase
210 B: case ( in )DOT: s t a t e = SIX ;
212 d e f au l t : begin new l e t t e r =1;l e t t e r = B;
214 s t a t e = BLANK;end
216 endcase
218 Z : case ( in )DOT: s t a t e = SEVEN;
220 d e f au l t : begin new l e t t e r =1;l e t t e r = Z ;
222 s t a t e = BLANK;end
224 endcase
226 O: case ( in )DOT: s t a t e = BEFOREEIGHT;
228 DASH: s t a t e = BEFORENINE;d e f au l t : begin new l e t t e r =1;
230 l e t t e r = O;s t a t e = BLANK;
232 endendcase
234C: case ( in )
236 d e f au l t : begin new l e t t e r =1;l e t t e r = C;
13
CSC258 - Final Project Report
238 s t a t e = BLANK;end
240 endcase
242 BEFORETWO: case ( in )DASH: s t a t e = TWO;
244 de f au l t : s t a t e = s t a t e ;endcase
246BEFOREEIGHT: case ( in )
248 DASH: s t a t e = EIGHT;d e f au l t : s t a t e = s t a t e ;
250 endcase
252 BEFORENINE: case ( in )DOT: s t a t e = NINE;
254 DASH: s t a t e = ZERO;d e f au l t : s t a t e = s t a t e ;
256 endcase
258 TWO: case ( in )GAP: begin
260 l e t t e r = TWO;s t a t e = BLANK;
262 endde f au l t : s t a t e = s t a t e ;
264 endcase
266 d e f au l t : begins t a t e = BLANK;
268 new l e t t e r =1;end
270 endcaseend
272endmodule
morsefsm.v
1 module un i t count e r ( c lk , un i t f r e q , ou t c l k ) ;input c l k ;
3 input [ 3 : 0 ] u n i t f r e q ; // he r t zoutput reg ou t c l k = 0 ;
5reg [ 3 1 : 0 ] counter = 0 ;
7always @ ( posedge c l k ) begin
9 case ( counter )//5000000 ∗ ( u n i t f r e q )
14
CSC258 - Final Project Report
11 15000000 : beginou t c l k = 1 ;
13 counter = 0 ;end
15 // 2500000 ∗ ( u n i t f r e q )7500000 : begin
17 ou t c l k = 0 ;counter = counter + 1 ;
19 end
21 de f au l t : counter = counter + 1 ;
23 endcaseend
25 endmodule
unit counter.v
1 module mux8bit9to1 ( s e l e c t , q ) ;input [ 8 : 0 ] s e l e c t ;
3 output [ 7 : 0 ] q ;
5 reg [ 7 : 0 ] q ;
7 parameter [ 5 : 0 ] BLANK = 6 ’ b000000 ;parameter [ 5 : 0 ] A = 6 ’ b011010 ;
9 parameter [ 5 : 0 ] B = 6 ’ b000001 ;parameter [ 5 : 0 ] C = 6 ’ b000010 ;
11 parameter [ 5 : 0 ] D = 6 ’ b000011 ;parameter [ 5 : 0 ] E = 6 ’ b000100 ;
13 parameter [ 5 : 0 ] F = 6 ’ b000101 ;parameter [ 5 : 0 ] G = 6 ’ b000110 ;
15 parameter [ 5 : 0 ] H = 6 ’ b000111 ;parameter [ 5 : 0 ] I = 6 ’ b001000 ;
17 parameter [ 5 : 0 ] J = 6 ’ b001001 ;parameter [ 5 : 0 ] K = 6 ’ b001010 ;
19 parameter [ 5 : 0 ] L = 6 ’ b001011 ;parameter [ 5 : 0 ] M = 6 ’ b001100 ;
21 parameter [ 5 : 0 ] N = 6 ’ b001101 ;parameter [ 5 : 0 ] O = 6 ’ b001110 ;
23 parameter [ 5 : 0 ] P = 6 ’ b001111 ;parameter [ 5 : 0 ] Q = 6 ’ b010000 ;
25 parameter [ 5 : 0 ] R = 6 ’ b010001 ;parameter [ 5 : 0 ] S = 6 ’ b010010 ;
27 parameter [ 5 : 0 ] T = 6 ’ b010011 ;parameter [ 5 : 0 ] U = 6 ’ b010100 ;
29 parameter [ 5 : 0 ] V = 6 ’ b010101 ;parameter [ 5 : 0 ] W = 6 ’ b010110 ;
31 parameter [ 5 : 0 ] X = 6 ’ b010111 ;
15
CSC258 - Final Project Report
parameter [ 5 : 0 ] Y = 6 ’ b011000 ;33 parameter [ 5 : 0 ] Z = 6 ’ b011001 ;
parameter [ 5 : 0 ] ONE = 6 ’ b100111 ;35 parameter [ 5 : 0 ] TWO = 6 ’ b011011 ;
parameter [ 5 : 0 ] THREE = 6 ’ b011100 ;37 parameter [ 5 : 0 ] FOUR = 6 ’ b011101 ;
parameter [ 5 : 0 ] FIVE = 6 ’ b011110 ;39 parameter [ 5 : 0 ] SIX = 6 ’ b011111 ;
parameter [ 5 : 0 ] SEVEN = 6 ’ b100000 ;41 parameter [ 5 : 0 ] EIGHT = 6 ’ b100001 ;
parameter [ 5 : 0 ] NINE = 6 ’ b100010 ;43 parameter [ 5 : 0 ] ZERO = 6 ’ b100011 ;
parameter [ 5 : 0 ] BEFORETWO = 6 ’ b100100 ;45 parameter [ 5 : 0 ] BEFOREEIGHT = 6 ’ b100101 ;
parameter [ 5 : 0 ] BEFORENINE = 6 ’ b100110 ;47
always @ ( s e l e c t )49 begin
case ( s e l e c t )51 BLANK : q = 8 ’ h20 ;
A : q = 8 ’ h41 ;53 B : q = 8 ’ h42 ;
C : q = 8 ’ h43 ;55 D : q = 8 ’ h44 ;
E : q = 8 ’ h45 ;57 F : q = 8 ’ h46 ;
G : q = 8 ’ h47 ;59 H : q = 8 ’ h48 ;
I : q = 8 ’ h49 ;61 J : q = 8 ’h4A ;
K : q = 8 ’h4B ;63 L : q = 8 ’h4C ;
M : q = 8 ’h4D ;65 N : q = 8 ’h4E ;
O : q = 8 ’h4F ;67 P : q = 8 ’ h50 ;
Q : q = 8 ’ h51 ;69 R : q = 8 ’ h52 ;
S : q = 8 ’ h53 ;71 T : q = 8 ’ h54 ;
U : q = 8 ’ h55 ;73 V : q = 8 ’ h56 ;
W : q = 8 ’ h57 ;75 X : q = 8 ’ h58 ;
Y : q = 8 ’ h59 ;77 Z : q = 8 ’h5A ;
ONE : q = 8 ’ h31 ;79 TWO : q = 8 ’ h32 ;
THREE : q = 8 ’ h33 ;
16
CSC258 - Final Project Report
81 FOUR : q = 8 ’ h34 ;FIVE : q = 8 ’ h35 ;
83 SIX : q = 8 ’ h36 ;SEVEN : q = 8 ’ h37 ;
85 EIGHT : q = 8 ’ h38 ;NINE : q = 8 ’ h39 ;
87 ZERO : q = 8 ’ h30 ;d e f au l t : q = 8 ’ h20 ;
89 endcaseend
91 endmodule
mux9
17