OpenCores
URL https://opencores.org/ocsvn/openmsp430/openmsp430/trunk

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [xilinx_diligent_s3board/] [rtl/] [verilog/] [driver_7segment.v] - Blame information for rev 109

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 olivier.gi
//----------------------------------------------------------------------------
2
// Copyright (C) 2001 Authors
3
//
4
// This source file may be used and distributed without restriction provided
5
// that this copyright statement is not removed from the file and that any
6
// derivative work contains the original copyright notice and the associated
7
// disclaimer.
8
//
9
// This source file is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU Lesser General Public License as published
11
// by the Free Software Foundation; either version 2.1 of the License, or
12
// (at your option) any later version.
13
//
14
// This source is distributed in the hope that it will be useful, but WITHOUT
15
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
// License for more details.
18
//
19
// You should have received a copy of the GNU Lesser General Public License
20
// along with this source; if not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
//
23
//----------------------------------------------------------------------------
24
//
25
// *File Name: driver_7segment.v
26
// 
27
// *Module Description:
28
//                      Driver for the four-digit, seven-segment LED display.
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34 16 olivier.gi
// $Rev: 109 $
35
// $LastChangedBy: olivier.girard $
36
// $LastChangedDate: 2011-03-27 13:49:47 +0200 (Sun, 27 Mar 2011) $
37
//----------------------------------------------------------------------------
38 2 olivier.gi
 
39
module  driver_7segment (
40
 
41
// OUTPUTs
42
    per_dout,                       // Peripheral data output
43
    seg_a,                          // Segment A control
44
    seg_b,                          // Segment B control
45
    seg_c,                          // Segment C control
46
    seg_d,                          // Segment D control
47
    seg_e,                          // Segment E control
48
    seg_f,                          // Segment F control
49
    seg_g,                          // Segment G control
50
    seg_dp,                         // Segment DP control
51
    seg_an0,                        // Anode 0 control
52
    seg_an1,                        // Anode 1 control
53
    seg_an2,                        // Anode 2 control
54
    seg_an3,                        // Anode 3 control
55
 
56
// INPUTs
57
    mclk,                           // Main system clock
58
    per_addr,                       // Peripheral address
59
    per_din,                        // Peripheral data input
60
    per_en,                         // Peripheral enable (high active)
61 109 olivier.gi
    per_we,                         // Peripheral write enable (high active)
62 2 olivier.gi
    puc                             // Main system reset
63
);
64
 
65
// OUTPUTs
66
//=========
67
output      [15:0] per_dout;        // Peripheral data output
68
output             seg_a;           // Segment A control
69
output             seg_b;           // Segment B control
70
output             seg_c;           // Segment C control
71
output             seg_d;           // Segment D control
72
output             seg_e;           // Segment E control
73
output             seg_f;           // Segment F control
74
output             seg_g;           // Segment G control
75
output             seg_dp;          // Segment DP control
76
output             seg_an0;         // Anode 0 control
77
output             seg_an1;         // Anode 1 control
78
output             seg_an2;         // Anode 2 control
79
output             seg_an3;         // Anode 3 control
80
 
81
// INPUTs
82
//=========
83
input              mclk;            // Main system clock
84
input        [7:0] per_addr;        // Peripheral address
85
input       [15:0] per_din;         // Peripheral data input
86
input              per_en;          // Peripheral enable (high active)
87 109 olivier.gi
input        [1:0] per_we;          // Peripheral write enable (high active)
88 2 olivier.gi
input              puc;             // Main system reset
89
 
90
 
91
//=============================================================================
92
// 1)  PARAMETER DECLARATION
93
//=============================================================================
94
 
95
// Register addresses
96
parameter          DIGIT0    = 9'h090;
97
parameter          DIGIT1    = 9'h091;
98
parameter          DIGIT2    = 9'h092;
99
parameter          DIGIT3    = 9'h093;
100
 
101
 
102
// Register one-hot decoder
103
parameter          DIGIT0_D  = (256'h1 << (DIGIT0 /2));
104
parameter          DIGIT1_D  = (256'h1 << (DIGIT1 /2));
105
parameter          DIGIT2_D  = (256'h1 << (DIGIT2 /2));
106
parameter          DIGIT3_D  = (256'h1 << (DIGIT3 /2));
107
 
108
 
109
//============================================================================
110
// 2)  REGISTER DECODER
111
//============================================================================
112
 
113
// Register address decode
114
reg  [255:0]  reg_dec;
115
always @(per_addr)
116
  case (per_addr)
117
    (DIGIT0 /2):   reg_dec   = DIGIT0_D;
118
    (DIGIT1 /2):   reg_dec   = DIGIT1_D;
119
    (DIGIT2 /2):   reg_dec   = DIGIT2_D;
120
    (DIGIT3 /2):   reg_dec   = DIGIT3_D;
121
    default    :   reg_dec   = {256{1'b0}};
122
  endcase
123
 
124
// Read/Write probes
125 109 olivier.gi
wire         reg_lo_write =  per_we[0] & per_en;
126
wire         reg_hi_write =  per_we[1] & per_en;
127
wire         reg_read     = ~|per_we   & per_en;
128 2 olivier.gi
 
129
// Read/Write vectors
130
wire [255:0] reg_hi_wr    = reg_dec & {256{reg_hi_write}};
131
wire [255:0] reg_lo_wr    = reg_dec & {256{reg_lo_write}};
132
wire [255:0] reg_rd       = reg_dec & {256{reg_read}};
133
 
134
 
135
//============================================================================
136
// 3) REGISTERS
137
//============================================================================
138
 
139
// DIGIT0 Register
140
//-----------------
141
reg  [7:0] digit0;
142
 
143
wire       digit0_wr  = DIGIT0[0] ? reg_hi_wr[DIGIT0/2] : reg_lo_wr[DIGIT0/2];
144
wire [7:0] digit0_nxt = DIGIT0[0] ? per_din[15:8]       : per_din[7:0];
145
 
146
always @ (posedge mclk or posedge puc)
147
  if (puc)            digit0 <=  8'h00;
148
  else if (digit0_wr) digit0 <=  digit0_nxt;
149
 
150
 
151
// DIGIT1 Register
152
//-----------------
153
reg  [7:0] digit1;
154
 
155
wire       digit1_wr  = DIGIT1[0] ? reg_hi_wr[DIGIT1/2] : reg_lo_wr[DIGIT1/2];
156
wire [7:0] digit1_nxt = DIGIT1[0] ? per_din[15:8]       : per_din[7:0];
157
 
158
always @ (posedge mclk or posedge puc)
159
  if (puc)            digit1 <=  8'h00;
160
  else if (digit1_wr) digit1 <=  digit1_nxt;
161
 
162
 
163
// DIGIT2 Register
164
//-----------------
165
reg  [7:0] digit2;
166
 
167
wire       digit2_wr  = DIGIT2[0] ? reg_hi_wr[DIGIT2/2] : reg_lo_wr[DIGIT2/2];
168
wire [7:0] digit2_nxt = DIGIT2[0] ? per_din[15:8]       : per_din[7:0];
169
 
170
always @ (posedge mclk or posedge puc)
171
  if (puc)            digit2 <=  8'h00;
172
  else if (digit2_wr) digit2 <=  digit2_nxt;
173
 
174
 
175
// DIGIT3 Register
176
//-----------------
177
reg  [7:0] digit3;
178
 
179
wire       digit3_wr  = DIGIT3[0] ? reg_hi_wr[DIGIT3/2] : reg_lo_wr[DIGIT3/2];
180
wire [7:0] digit3_nxt = DIGIT3[0] ? per_din[15:8]       : per_din[7:0];
181
 
182
always @ (posedge mclk or posedge puc)
183
  if (puc)            digit3 <=  8'h00;
184
  else if (digit3_wr) digit3 <=  digit3_nxt;
185
 
186
 
187
//============================================================================
188
// 4) DATA OUTPUT GENERATION
189
//============================================================================
190
 
191
// Data output mux
192
wire [15:0] digit0_rd   = (digit0  & {8{reg_rd[DIGIT0/2]}})  << (8 & {4{DIGIT0[0]}});
193
wire [15:0] digit1_rd   = (digit1  & {8{reg_rd[DIGIT1/2]}})  << (8 & {4{DIGIT1[0]}});
194
wire [15:0] digit2_rd   = (digit2  & {8{reg_rd[DIGIT2/2]}})  << (8 & {4{DIGIT2[0]}});
195
wire [15:0] digit3_rd   = (digit3  & {8{reg_rd[DIGIT3/2]}})  << (8 & {4{DIGIT3[0]}});
196
 
197
wire [15:0] per_dout  =  digit0_rd  |
198
                         digit1_rd  |
199
                         digit2_rd  |
200
                         digit3_rd;
201
 
202
 
203
//============================================================================
204
// 5) FOUR-DIGIT, SEVEN-SEGMENT LED DISPLAY DRIVER
205
//============================================================================
206
 
207
// Anode selection
208
//------------------
209
 
210
// Free running counter
211
reg [23:0] anode_cnt;
212
always @ (posedge mclk or posedge puc)
213
if (puc) anode_cnt <=  24'h00_0000;
214
else     anode_cnt <=  anode_cnt+24'h00_0001;
215
 
216
// Anode selection
217
wire [3:0] seg_an  = (4'h1 << anode_cnt[17:16]);
218
wire       seg_an0 = ~seg_an[0];
219
wire       seg_an1 = ~seg_an[1];
220
wire       seg_an2 = ~seg_an[2];
221
wire       seg_an3 = ~seg_an[3];
222
 
223
 
224
// Segment selection
225
//----------------------------
226
 
227
wire [7:0] digit  = seg_an[0] ? digit0 :
228
                    seg_an[1] ? digit1 :
229
                    seg_an[2] ? digit2 :
230
                                digit3;
231
 
232
wire       seg_a  = ~digit[7];
233
wire       seg_b  = ~digit[6];
234
wire       seg_c  = ~digit[5];
235
wire       seg_d  = ~digit[4];
236
wire       seg_e  = ~digit[3];
237
wire       seg_f  = ~digit[2];
238
wire       seg_g  = ~digit[1];
239
wire       seg_dp = ~digit[0];
240
 
241
 
242
endmodule // driver_7segment
243
 
244
 
245
 
246
 
247
 
248
 
249
 
250
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.