Guest User

Untitled

a guest
Jan 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module uart(
  2. input clk,
  3. input rst,
  4. input bcd0,
  5. input bcd1,
  6. output reg tx_out
  7. );
  8.  
  9. reg [7:0]tx_shr;
  10. reg [2:0]tx_cntr;
  11. reg parity;
  12. reg tx_enable;
  13.  
  14. always @(posedge clk)begin
  15.  
  16.     if(rst)begin
  17.         tx_cntr <=0;
  18.         tx_shr <=8'b00000000;
  19.         tx_out <= 1;
  20.     end
  21.  
  22. if (tx_enable) begin
  23.          if(tx_cntr==0)begin //startbit
  24.          tx_out <= 0;
  25.          end
  26.          tx_shr <= {tx_shr[3:0], bcd0}; //betoltom alsot
  27.          tx_shr <= {tx_shr[7:4], bcd1}; //betoltom felsot
  28.          tx_out <= tx_shr[tx_cntr] ;
  29.          tx_cntr <= tx_cntr+1;
  30.            
  31.         if(tx_cntr == 7)begin
  32.        
  33.        parity =  (tx_shr[0] ^ tx_shr[1]) ^  
  34.                (tx_shr[2] ^ tx_shr[3]) ^
  35.               (tx_shr[4] ^ tx_shr[5]) ^  
  36.              (tx_shr[6] ^ tx_shr[7]);
  37.        
  38.         end
  39.        
  40.             if (parity == 0)begin
  41.                 tx_out <= 0 ;
  42.                 end
  43.             else
  44.                 tx_out <= 1 ;
  45.  
  46.         if (tx_cntr == 7) begin
  47.         tx_out <= 1;
  48.         tx_cntr <= 0;
  49.         end
  50.  
  51.     end
  52. end
  53.  
  54. endmodule
Add Comment
Please, Sign In to add comment