Advertisement
krist7599555

skilltest_hw_6031301721.v

Mar 23rd, 2020
963
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // แก้ Skill Test
  2. // 6031301721 Krist Pornpairin
  3.  
  4. `timescale 1ns / 1ps
  5.  
  6. module system(
  7.     output[6:0] seg,
  8.     output dp,
  9.     output[3:0] an,
  10.     input clk
  11. );
  12.    
  13. wire an0, an1, an2, an3;
  14. assign an = {an0, an1, an2, an3};
  15.  
  16.  
  17. wire clk_15, clk_50;
  18. clockDivGen #(18) genClk1(clk_15, clk); // clock ปกติ
  19. clockDivGen #(27) genClk2(clk_50, clk); // clock สลับเลข
  20.  
  21.  
  22. // counter {0,1,2,3,4,0,1,2,3,4,0.....}
  23. reg[3:0] num;
  24. initial begin
  25.     num = 0;
  26. end
  27. always @(posedge clk_50)
  28. begin
  29.     num = (num + 1) % 5;
  30. end
  31.  
  32. // counter ~> unary counter
  33. // แปลง num ให้เป็น 4 decimal digit โดยแต่ละหลักมีค่าเป็น 0 หรือ 1
  34. // ! warning 0 เฉยๆได้ 4'b0000 แก้บัคตรงนี้เกือบ 4 ชม :(
  35. wire [15:0] out;
  36. assign out = {
  37.  3'b000, num > 3,
  38.  3'b000, num > 2,
  39.  3'b000, num > 1,
  40.  3'b000, num > 0
  41. };
  42.  
  43. // display
  44. quadSevenSeg q7seg(
  45.     // output
  46.     seg, dp,
  47.     an0, an1, an2, an3,
  48.     // input
  49.     out[15:12], out[11:8], out[7:4], out[3:0],
  50.     clk_15
  51. );
  52.  
  53. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement