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 79

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: 23 $
35
// $LastChangedBy: olivier.girard $
36
// $LastChangedDate: 2009-08-30 18:39:26 +0200 (Sun, 30 Aug 2009) $
37
//----------------------------------------------------------------------------
38 23 olivier.gi
`include "timescale.v"
39 2 olivier.gi
 
40
module  driver_7segment (
41
 
42
// OUTPUTs
43
    per_dout,                       // Peripheral data output
44
    seg_a,                          // Segment A control
45
    seg_b,                          // Segment B control
46
    seg_c,                          // Segment C control
47
    seg_d,                          // Segment D control
48
    seg_e,                          // Segment E control
49
    seg_f,                          // Segment F control
50
    seg_g,                          // Segment G control
51
    seg_dp,                         // Segment DP control
52
    seg_an0,                        // Anode 0 control
53
    seg_an1,                        // Anode 1 control
54
    seg_an2,                        // Anode 2 control
55
    seg_an3,                        // Anode 3 control
56
 
57
// INPUTs
58
    mclk,                           // Main system clock
59
    per_addr,                       // Peripheral address
60
    per_din,                        // Peripheral data input
61
    per_en,                         // Peripheral enable (high active)
62
    per_wen,                        // Peripheral write enable (high active)
63
    puc                             // Main system reset
64
);
65
 
66
// OUTPUTs
67
//=========
68
output      [15:0] per_dout;        // Peripheral data output
69
output             seg_a;           // Segment A control
70
output             seg_b;           // Segment B control
71
output             seg_c;           // Segment C control
72
output             seg_d;           // Segment D control
73
output             seg_e;           // Segment E control
74
output             seg_f;           // Segment F control
75
output             seg_g;           // Segment G control
76
output             seg_dp;          // Segment DP control
77
output             seg_an0;         // Anode 0 control
78
output             seg_an1;         // Anode 1 control
79
output             seg_an2;         // Anode 2 control
80
output             seg_an3;         // Anode 3 control
81
 
82
// INPUTs
83
//=========
84
input              mclk;            // Main system clock
85
input        [7:0] per_addr;        // Peripheral address
86
input       [15:0] per_din;         // Peripheral data input
87
input              per_en;          // Peripheral enable (high active)
88
input        [1:0] per_wen;         // Peripheral write enable (high active)
89
input              puc;             // Main system reset
90
 
91
 
92
//=============================================================================
93
// 1)  PARAMETER DECLARATION
94
//=============================================================================
95
 
96
// Register addresses
97
parameter          DIGIT0    = 9'h090;
98
parameter          DIGIT1    = 9'h091;
99
parameter          DIGIT2    = 9'h092;
100
parameter          DIGIT3    = 9'h093;
101
 
102
 
103
// Register one-hot decoder
104
parameter          DIGIT0_D  = (256'h1 << (DIGIT0 /2));
105
parameter          DIGIT1_D  = (256'h1 << (DIGIT1 /2));
106
parameter          DIGIT2_D  = (256'h1 << (DIGIT2 /2));
107
parameter          DIGIT3_D  = (256'h1 << (DIGIT3 /2));
108
 
109
 
110
//============================================================================
111
// 2)  REGISTER DECODER
112
//============================================================================
113
 
114
// Register address decode
115
reg  [255:0]  reg_dec;
116
always @(per_addr)
117
  case (per_addr)
118
    (DIGIT0 /2):   reg_dec   = DIGIT0_D;
119
    (DIGIT1 /2):   reg_dec   = DIGIT1_D;
120
    (DIGIT2 /2):   reg_dec   = DIGIT2_D;
121
    (DIGIT3 /2):   reg_dec   = DIGIT3_D;
122
    default    :   reg_dec   = {256{1'b0}};
123
  endcase
124
 
125
// Read/Write probes
126
wire         reg_lo_write =  per_wen[0] & per_en;
127
wire         reg_hi_write =  per_wen[1] & per_en;
128
wire         reg_read     = ~|per_wen   & per_en;
129
 
130
// Read/Write vectors
131
wire [255:0] reg_hi_wr    = reg_dec & {256{reg_hi_write}};
132
wire [255:0] reg_lo_wr    = reg_dec & {256{reg_lo_write}};
133
wire [255:0] reg_rd       = reg_dec & {256{reg_read}};
134
 
135
 
136
//============================================================================
137
// 3) REGISTERS
138
//============================================================================
139
 
140
// DIGIT0 Register
141
//-----------------
142
reg  [7:0] digit0;
143
 
144
wire       digit0_wr  = DIGIT0[0] ? reg_hi_wr[DIGIT0/2] : reg_lo_wr[DIGIT0/2];
145
wire [7:0] digit0_nxt = DIGIT0[0] ? per_din[15:8]       : per_din[7:0];
146
 
147
always @ (posedge mclk or posedge puc)
148
  if (puc)            digit0 <=  8'h00;
149
  else if (digit0_wr) digit0 <=  digit0_nxt;
150
 
151
 
152
// DIGIT1 Register
153
//-----------------
154
reg  [7:0] digit1;
155
 
156
wire       digit1_wr  = DIGIT1[0] ? reg_hi_wr[DIGIT1/2] : reg_lo_wr[DIGIT1/2];
157
wire [7:0] digit1_nxt = DIGIT1[0] ? per_din[15:8]       : per_din[7:0];
158
 
159
always @ (posedge mclk or posedge puc)
160
  if (puc)            digit1 <=  8'h00;
161
  else if (digit1_wr) digit1 <=  digit1_nxt;
162
 
163
 
164
// DIGIT2 Register
165
//-----------------
166
reg  [7:0] digit2;
167
 
168
wire       digit2_wr  = DIGIT2[0] ? reg_hi_wr[DIGIT2/2] : reg_lo_wr[DIGIT2/2];
169
wire [7:0] digit2_nxt = DIGIT2[0] ? per_din[15:8]       : per_din[7:0];
170
 
171
always @ (posedge mclk or posedge puc)
172
  if (puc)            digit2 <=  8'h00;
173
  else if (digit2_wr) digit2 <=  digit2_nxt;
174
 
175
 
176
// DIGIT3 Register
177
//-----------------
178
reg  [7:0] digit3;
179
 
180
wire       digit3_wr  = DIGIT3[0] ? reg_hi_wr[DIGIT3/2] : reg_lo_wr[DIGIT3/2];
181
wire [7:0] digit3_nxt = DIGIT3[0] ? per_din[15:8]       : per_din[7:0];
182
 
183
always @ (posedge mclk or posedge puc)
184
  if (puc)            digit3 <=  8'h00;
185
  else if (digit3_wr) digit3 <=  digit3_nxt;
186
 
187
 
188
//============================================================================
189
// 4) DATA OUTPUT GENERATION
190
//============================================================================
191
 
192
// Data output mux
193
wire [15:0] digit0_rd   = (digit0  & {8{reg_rd[DIGIT0/2]}})  << (8 & {4{DIGIT0[0]}});
194
wire [15:0] digit1_rd   = (digit1  & {8{reg_rd[DIGIT1/2]}})  << (8 & {4{DIGIT1[0]}});
195
wire [15:0] digit2_rd   = (digit2  & {8{reg_rd[DIGIT2/2]}})  << (8 & {4{DIGIT2[0]}});
196
wire [15:0] digit3_rd   = (digit3  & {8{reg_rd[DIGIT3/2]}})  << (8 & {4{DIGIT3[0]}});
197
 
198
wire [15:0] per_dout  =  digit0_rd  |
199
                         digit1_rd  |
200
                         digit2_rd  |
201
                         digit3_rd;
202
 
203
 
204
//============================================================================
205
// 5) FOUR-DIGIT, SEVEN-SEGMENT LED DISPLAY DRIVER
206
//============================================================================
207
 
208
// Anode selection
209
//------------------
210
 
211
// Free running counter
212
reg [23:0] anode_cnt;
213
always @ (posedge mclk or posedge puc)
214
if (puc) anode_cnt <=  24'h00_0000;
215
else     anode_cnt <=  anode_cnt+24'h00_0001;
216
 
217
// Anode selection
218
wire [3:0] seg_an  = (4'h1 << anode_cnt[17:16]);
219
wire       seg_an0 = ~seg_an[0];
220
wire       seg_an1 = ~seg_an[1];
221
wire       seg_an2 = ~seg_an[2];
222
wire       seg_an3 = ~seg_an[3];
223
 
224
 
225
// Segment selection
226
//----------------------------
227
 
228
wire [7:0] digit  = seg_an[0] ? digit0 :
229
                    seg_an[1] ? digit1 :
230
                    seg_an[2] ? digit2 :
231
                                digit3;
232
 
233
wire       seg_a  = ~digit[7];
234
wire       seg_b  = ~digit[6];
235
wire       seg_c  = ~digit[5];
236
wire       seg_d  = ~digit[4];
237
wire       seg_e  = ~digit[3];
238
wire       seg_f  = ~digit[2];
239
wire       seg_g  = ~digit[1];
240
wire       seg_dp = ~digit[0];
241
 
242
 
243
endmodule // driver_7segment
244
 
245
 
246
 
247
 
248
 
249
 
250
 
251
 

powered by: WebSVN 2.1.0

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