1 | module display (clock, AN0, AN1, AN2, AN3, CA, CB, CC, CD, CE, CF, CG, CDP);
|
2 |
|
3 |
|
4 | //USED FOR SEVEN SEG
|
5 | input clock;
|
6 |
|
7 | output AN0, AN1, AN2, AN3, CA, CB, CC, CD, CE, CF, CG, CDP;
|
8 |
|
9 | reg [7:0] cathodedata; //cathode data
|
10 | reg [3:0] anodedata; //anode data
|
11 | reg [2:0] digit = 1;
|
12 | reg [6:0] data;
|
13 | reg setdp;
|
14 | reg [19:0] counter = 0;
|
15 |
|
16 | assign CA = cathodedata [7];
|
17 | assign CB = cathodedata [6];
|
18 | assign CC = cathodedata [5];
|
19 | assign CD = cathodedata [4];
|
20 | assign CE = cathodedata [3];
|
21 | assign CF = cathodedata [2];
|
22 | assign CG = cathodedata [1];
|
23 | assign CDP = cathodedata [0];
|
24 | assign AN3 = anodedata [3];
|
25 | assign AN2 = anodedata [2];
|
26 | assign AN1 = anodedata [1];
|
27 | assign AN0 = anodedata [0];
|
28 | //USED FOR SEVEN SEG
|
29 |
|
30 | //Multiplexing
|
31 | //Board Clock: 50MHz
|
32 | //p = t*f
|
33 | //t = 16ms
|
34 | //p = 16ms * 50*10^6 = 800,000 cycles
|
35 | //200,000 cycles for each digit
|
36 | //Refreshed every 16ms (~60Hz)
|
37 |
|
38 | always@(negedge clock)
|
39 | begin
|
40 | if (digit == 1)
|
41 | begin
|
42 | if (counter == 200000)
|
43 | begin
|
44 | digit = 2;
|
45 | end
|
46 | else
|
47 | begin
|
48 | counter = counter + 1;
|
49 | data = 4;
|
50 | end
|
51 | end
|
52 | else if (digit == 2)
|
53 | begin
|
54 | if (counter == 400000)
|
55 | begin
|
56 | digit = 3;
|
57 | end
|
58 | else
|
59 | begin
|
60 | counter = counter + 1;
|
61 | data = 3;
|
62 | end
|
63 | end
|
64 | else if (digit == 3)
|
65 | begin
|
66 | if (counter == 600000)
|
67 | begin
|
68 | digit = 4;
|
69 | end
|
70 | else
|
71 | begin
|
72 | counter = counter + 1;
|
73 | data = 2;
|
74 | end
|
75 | end
|
76 | else if (digit == 4)
|
77 | begin
|
78 | if (counter == 800000)
|
79 | begin
|
80 | digit = 1;
|
81 | counter = 0;
|
82 | end
|
83 | else
|
84 | begin
|
85 | counter = counter + 1;
|
86 | data = 1;
|
87 | end
|
88 | end
|
89 | end
|
90 |
|
91 |
|
92 | always @ (*)
|
93 | begin
|
94 |
|
95 | case (data)
|
96 | 6'd0: cathodedata = 8'b00000011; //0
|
97 | 6'd1: cathodedata = 8'b10011111; //1
|
98 | 6'd2: cathodedata = 8'b00100101; //2
|
99 | 6'd3: cathodedata = 8'b00001101; //3
|
100 | 6'd4: cathodedata = 8'b10011001; //4
|
101 | 6'd5: cathodedata = 8'b01001001; //5
|
102 | 6'd6: cathodedata = 8'b01000001; //6
|
103 | 6'd7: cathodedata = 8'b00011111; //7
|
104 | 6'd8: cathodedata = 8'b00000001; //8
|
105 | 6'd9: cathodedata = 8'b00001001; //9
|
106 | 6'd10: cathodedata = 8'b00010001; //A
|
107 | 6'd11: cathodedata = 8'b11000001; //B
|
108 | 6'd12: cathodedata = 8'b01100011; //C
|
109 | 6'd13: cathodedata = 8'b10000101; //D
|
110 | 6'd14: cathodedata = 8'b00100001; //E
|
111 | 6'd15: cathodedata = 8'b01110001; //F
|
112 | default: cathodedata = 8'b11111111; //default all off
|
113 | endcase
|
114 |
|
115 | if (setdp == 1) //decimal point
|
116 | cathodedata = cathodedata & 8'hFE;
|
117 |
|
118 | case(digit)
|
119 | 0: anodedata = 4'b1111; //all OFF
|
120 | 4: anodedata = 4'b1110; //AN0
|
121 | 3: anodedata = 4'b1101; //AN1
|
122 | 2: anodedata = 4'b1011; //AN2
|
123 | 1: anodedata = 4'b0111; //AN3
|
124 | default:
|
125 | anodedata = 4'b1111; //all OFF
|
126 | endcase
|
127 |
|
128 | end
|
129 | endmodule
|