Advertisement
Guest User

Untitled

a guest
May 24th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `define IDLE    4'b0001
  2. `define E_0     4'b0010
  3. `define E_1     4'b0011
  4. `define E_2     4'b0100
  5. `define E_3     4'b0101
  6. `define E_4     4'b0110
  7. `define E_5     4'b0111
  8. `define E_6     4'b1000
  9.  
  10. module recog_seq(input clk, input rx, input [7:0] char, output reg [7:0] answer);
  11.  
  12.     reg [3:0] state;
  13.     reg [3:0] nxt_state;
  14.    
  15.     wire [1:0] stt;
  16.    
  17.    
  18.     buart asdf(.rst(1'b0), .clk(clk), .ld_tx_data(ld_tx_data), .tx_data(char_tx),
  19.                   .tx_enable(1'b1), .tx(tx), .tx_empty(tx_empty), .uld_rx_data(uld),
  20.                   .rx_data(char_rx), .rx_enable(1'b1), .rx(rx), .rx_empty(rx_empty),
  21.                   .rx_err(err));
  22.    
  23.     assign stt = {(prev_state==`E_6),(state==`IDLE)};
  24.    
  25.     always @(posedge clk or posedge rst)
  26.         if (rst) prev_state <= IDLE;
  27.         else prev_state <= state;
  28.        
  29.     always @(*)
  30.        
  31.         case(prev_state)
  32.        
  33.             `IDLE:  state = ((char_rx == 8'h2F)&(char_tx == 8'h2F))?`E_1:prev_state;
  34.             `E_0:       state = ((char_rx == 8'h2F)&(char_tx == 8'h2F))?prev_state:
  35.                                   ((char_rx == 8'h5C)&(char_tx == 8'h5C))?prev_state:
  36.                                   (char_rx == char_tx)?`E_1: `E_0;
  37.             `E_1:       state = ((char_rx == 8'h2F)&(char_tx == 8'h2F))?`E_0:
  38.                                   ((char_rx == 8'h5C)&(char_tx == 8'h5C))?prev_state:
  39.                                   (char_rx == char_tx)?`E_2: `E_0;
  40.             `E_2:       state = ((char_rx == 8'h2F)&(char_tx == 8'h2F))?`E_0:
  41.                                   ((char_rx == 8'h5C)&(char_tx == 8'h5C))?prev_state:
  42.                                   (char_rx == char_tx)?`E_3: `E_0;
  43.             `E_3:       state = ((char_rx == 8'h2F)&(char_tx == 8'h2F))?`E_0:
  44.                                   ((char_rx == 8'h5C)&(char_tx == 8'h5C))?prev_state:
  45.                                   (char_rx == char_tx)?`E_3: `E_0;
  46.             `E_4:       state = ((char_rx == 8'h2F)&(char_tx == 8'h2F))?`E_0:
  47.                                   ((char_rx == 8'h5C)&(char_tx == 8'h5C))?prev_state:
  48.                                   (char_rx == char_tx)?`E_3: `E_0;
  49.             `E_5:       state = ((char_rx == 8'h2F)&(char_tx == 8'h2F))?`E_0:
  50.                                   ((char_rx == 8'h5C)&(char_tx == 8'h5C))?prev_state:
  51.                                   (char_rx == char_tx)?`E_6: `E_0;
  52.             `E_6:       state = ((char_rx == 8'h2F)&(char_tx == 8'h2F))?`E_0:
  53.                                   ((char_rx == 8'h5C)&(char_tx == 8'h5C))?`IDLE:
  54.                                   (char_rx == char_tx)?`prev_state: `E_0;
  55.             default  state = prev_state;
  56.        
  57.         endcase
  58.  
  59.     always @(*)
  60.    
  61.         if (stt==2'b11) answer = 16'h4F_4B;
  62.         else answer = 16'h0;
  63.  
  64.  
  65. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement