Thread: Seven Segment Display???

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    119

    Seven Segment Display???

    I'm a college student working out of programming pearls as a means of studying. I'm kind of stumped at the following question.

    Column 3 problems:

    Write a program that displays a 16-bit positivwe integer in five seven-segment digits. The output is an array of 5 bytes; bit i of byte j is on if and only if the ith segment of digit j should be on.

    Even after doing some reading I'm a bit confused, anyone worked with the book before and know a good place to start? Or can shed some light on the problem? Thanks in advance

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So each segment on a 7 segment display is represented by one bit in a byte. I have no idea what order those seven segments are - you can find some info here:
    http://en.wikipedia.org/wiki/Seven-segment_display

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    119
    ya that's where I did some of my reading. I'm completely confused. I think i'm just gonna dive in and code and see what type of results I get.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Diving in and coding is probably not the BEST idea - but perhaps you can try to do just a simple write-up on what you think you need. If you are uncertain about whether you got it right, post here, and I'm sure someone will help out.

    When you write up what you need to do, you should split it up in really simple forms, and if anything seems complicated, split it into smaller steps.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Would the following shed any light?
    Code:
    /*
     * Change the following definitions to suit the hardware.
     */
    #define SEG_A 0x01
    #define SEG_B 0x02
    #define SEG_C 0x04
    #define SEG_D 0x08
    #define SEG_E 0x10
    #define SEG_F 0x20
    #define SEG_G 0x40
    /*
     * See http://en.wikipedia.org/wiki/Image:7_segment_display_labeled.svg
     */
    #define DISP_ZERO  (SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F        )
    #define DISP_ONE   (        SEG_B | SEG_C                                )
    #define DISP_TWO   (SEG_A | SEG_B |         SEG_D | SEG_E |         SEG_G)
    #define DISP_THREE (SEG_A | SEG_B | SEG_C | SEG_D |                 SEG_G)
    #define DISP_FOUR  (        SEG_B | SEG_C |                 SEG_F | SEG_G)
    #define DISP_FIVE  (SEG_A |         SEG_C | SEG_D |         SEG_F | SEG_G)
    #define DISP_SIX   (SEG_A |         SEG_C | SEG_D | SEG_E | SEG_F | SEG_G)
    #define DISP_SEVEN (SEG_A | SEG_B | SEG_C                                )
    #define DISP_EIGHT (SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G)
    #define DISP_NINE  (SEG_A | SEG_B | SEG_C | SEG_D |         SEG_F | SEG_G)
    Perhaps even this too?
    Code:
    const unsigned char Digit[10] =
    {
       DISP_ZERO, DISP_ONE, DISP_TWO,   DISP_THREE, DISP_FOUR,  
       DISP_FIVE, DISP_SIX, DISP_SEVEN, DISP_EIGHT, DISP_NINE,
    };
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Here is one way.. Coding it is up to you:

    Code:
    char array[9][10][20] = 
         {
              {" ### ","    "," ### "," ### ","     "," ### "," ### "," ### "," ### "," ### "},
              {"#   #","   #","    #","    #","#   #","#    ","#    ","    #","#   #","#   #"},
              {"#   #","   #","    #","    #","#   #","#    ","#    ","    #","#   #","#   #"},
              {"#   #","   #","    #","    #","#   #","#    ","#    ","    #","#   #","#   #"},
              {"     ","    "," ### "," ### "," ### "," ### "," ### ","     "," ### "," ### "},
              {"#   #","   #","#    ","    #","    #","    #","#   #","    #","#   #","    #"},
              {"#   #","   #","#    ","    #","    #","    #","#   #","    #","#   #","    #"},
              {"#   #","   #","#    ","    #","    #","    #","#   #","    #","#   #","    #"},
              {" ### ","    "," ### "," ### ","     "," ### "," ### ","     "," ### "," ### "},    
         };
    The algorithm is insanely simple, and the array can be modified to suit your assignment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. display character size...(quite urgent..)
    By karthi in forum C Programming
    Replies: 10
    Last Post: 07-11-2007, 09:42 PM
  2. new problem with class
    By jrb47 in forum C++ Programming
    Replies: 0
    Last Post: 12-01-2006, 08:39 AM
  3. Declare an array in the BSS segment
    By ^xor in forum C Programming
    Replies: 1
    Last Post: 05-27-2005, 05:12 PM
  4. LISP (DrScheme) any one?
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-31-2004, 12:52 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM