Advertisement
StudentSeng

SC1005 Lab 5

Oct 25th, 2022 (edited)
1,746
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VeriLog 1.49 KB | Source Code | 0 0
  1. module convert (input [3:0] in,
  2.                 output reg [3:0] out);
  3.     // Converts 0-15 into the 0th - 15th character of "AAC0FFEEA15A900D" respectively
  4.     always @ * begin
  5.         case (in)   // AAC0FFEEA15A900D, we are using 'A' as space
  6.             4'd0: out = 4'hA;
  7.             4'd1: out = 4'hA;
  8.             4'd2: out = 4'hC;
  9.             4'd3: out = 4'h0;
  10.             4'd4: out = 4'hF;
  11.             4'd5: out = 4'hF;
  12.             4'd6: out = 4'hE;
  13.             4'd7: out = 4'hE;
  14.             4'd8: out = 4'hA;
  15.             4'd9: out = 4'h1;
  16.             4'd10: out = 4'h4;
  17.             4'd11: out = 4'hA;
  18.             4'd12: out = 4'h9;
  19.             4'd13: out = 4'h0;
  20.             4'd14: out = 4'h0;
  21.             4'd15: out = 4'hD;
  22.             default: out = 4'hA;
  23.         endcase
  24.     end
  25. endmodule
  26.  
  27.  
  28. module scroll(input clk, rst,
  29.               output [15:0] display);
  30.              
  31.     reg [3:0] count;
  32.    
  33.     always @ (posedge clk) begin
  34.         if (rst)
  35.             count <= 4'd0;
  36.         else
  37.             count <= count + 1'b1;
  38.     end
  39.     // Count goes from 0 to 15, 1 step per clock cycle
  40.    
  41.     wire [3:0] a, b, c, d;
  42.     assign a = count;
  43.     assign b = count+1;
  44.     assign c = count+2;
  45.     assign d = count+3;
  46.     // a,b,c,d is 4 consecutive numbers starting from count (with loop-around so 16->0)
  47.    
  48.     convert c1 (a, display[15:12]);
  49.     convert c2 (b, display[11:8]);
  50.     convert c3 (c, display[7:4]);
  51.     convert c4 (d, display[3:0]);
  52.    
  53. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement