It is currently Thu Sep 09, 2010 12:43 am




Post new topic Reply to topic  [ 1 post ] 
Verilog - Seven Segment Display on Spartan 3 Board 
Author Message
Site Admin

Joined: Sat Jan 24, 2009 3:56 pm
Posts: 32
Post Verilog - Seven Segment Display on Spartan 3 Board
This should be quite helpful to all those new to using the spartan 3 and nexys 2 boards

Code:
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date:    16:52:54 03/11/2009
// Design Name:
// Module Name:    SevenSegmentDisplay
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------
//                        DISPLAY MODULE
//----------------------------------------------------------
module SevenSegmentDisplay(seg3,seg2,seg1,seg0,clock,annodes1, segments1);
   
   input clock;
   input [3:0] seg3;
   input [3:0] seg2;
   input [3:0] seg1;
   input [3:0] seg0;
   
   output reg [3:0] annodes1;
   output wire [6:0] segments1;
   
   reg [1:0] an;
   reg [3:0] anVal;
   
   reg rotate_AN;
   reg [7:0] timer;
   
   wire [3:0] anVals;
   
   assign anVals = anVal;
   
   //----------------------------------------------------------
   //   Initilize variables
   //----------------------------------------------------------
   initial
   begin
      anVal <= 4'd0;
      an <= 2'd0;
      timer <= 8'd0;
   end
   
   //----------------------------------------------------------
   // call the decoder for segments
   //----------------------------------------------------------
   segments7 SEG(.fourIN(anVals),.clock(clock),.sevenOUT(segments1));
   
   //----------------------------------------------------------
   // rotation delay
   //----------------------------------------------------------
   always @ (posedge clock)
      begin
         if (timer == 8'b11111111)
            begin
               rotate_AN = (~rotate_AN);
               timer = 8'd0;
            end
         else
            begin
               timer = timer + 1;
            end
   end
   
   //----------------------------------------------------------
   // rotate to all segments
   //----------------------------------------------------------
   always @ (posedge rotate_AN)
   begin
      if(an == 2'd0)
         begin
            anVal = seg0;
            annodes1 = 4'b1110;
            if((seg1 >0) || (seg2 > 0) || (seg3 > 0))
               begin   an = 2'd1; end
            else
               begin an = 2'd0; end
         end
      
      else if (an == 2'd1)
         begin
            anVal = seg1;
            annodes1 = 4'b1101;
            if((seg2 > 0) || (seg3 > 0))
               begin   an = 2'd2; end
            else
               begin an = 2'd0; end
         end
      
      else if (an == 2'd2)
         begin
            anVal = seg2;   
            annodes1 = 4'b1011;
            if(seg3 > 0)
               begin an = 2'd3; end
            else
               begin an = 2'd0; end
         end
      
      else
         begin
            anVal = seg3;
            annodes1 = 4'b0111;
            an = 2'd0;         
         end
   end
   
endmodule


Code:
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date:    16:54:21 03/11/2009
// Design Name:
// Module Name:    segments7
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------
//                  DISPLAY DECODER MODULE
//----------------------------------------------------------
module segments7(fourIN,clock,sevenOUT);
   input clock;
   input [3:0] fourIN;
   output reg [6:0] sevenOUT;
   
   always @ (posedge clock)
   begin
       case (fourIN)
         4'h0: sevenOUT <= 7'b1000000;
         4'h1: sevenOUT <= 7'b1111001;
         4'h2: sevenOUT <= 7'b0100100;
         4'h3: sevenOUT <= 7'b0110000;
         
         4'h4: sevenOUT <= 7'b0011001;
         4'h5: sevenOUT <= 7'b0010010;
         4'h6: sevenOUT <= 7'b0000010;
         4'h7: sevenOUT <= 7'b1111000;
         
         4'h8: sevenOUT <= 7'b0000000;
         4'h9: sevenOUT <= 7'b0010000;
         4'hA: sevenOUT <= 7'b0001000;
         4'hB: sevenOUT <= 7'b0000011;
         
         4'hC: sevenOUT <= 7'b1111111; // blank
         4'hD: sevenOUT <= 7'b1000000; // letter O
         4'hE: sevenOUT <= 7'b0001100; // letter P
         4'hF: sevenOUT <= 7'b0111111; // minus sign
       endcase
   end
endmodule



Thu Aug 06, 2009 6:53 am
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © phpBB Group.
Designed by Vjacheslav Trushkin for Free Forum/DivisionCore.