Thread: Serial controller algorithm

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    21

    Serial controller algorithm

    hi all,
    i would like to implement a serial controller controlling 7 segment display to c++.
    Can anyone just give me an algorithm so i can apply it to c++ coding??i dont need the code just plain simple pseudo code will do.

    The controller decodes incoming hexadecimal encoded in ASCII text stream.Assume input stream is stored in an input buffer from where the command handler reads each character. Valid commands are stored in the command buffer and a command handler reads them and executes them thereby updating the current display. the command is: [$] [UP/DOWN?STOP]. the $ is the start character for each command, UP increments the output value, DOWN decrements the output value while STOP sets the output value to 0 if the output is below 5. the output range is from 0 to 9.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > The controller decodes incoming hexadecimal encoded in ASCII text stream.
    What kind of double-speak is this?

    Does the controller receive say
    $ UP

    If so, then what is all that "hexadecimal encoded" mumbo jumbo?

    The algorithm is very simple, you read a command, decode it, then take the appropriate action.

    Try writing it as a console program first (input is keyboard, output is screen).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    21
    i know the basic stuff like input and output
    i just need the body part of the algoirthm.
    The controller controls 7 segment display. It either increment or decrements the digit displayed on the 7 segment display.

    Code:
    input control stream: -------> decoder------->7 segment-----> output
    {$UP....$DOWN....ect}

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    That's all there is - what's the problem?

    Maintain a variable which changes in response to UP/DOWN/STOP commands, then refresh your 7-segment display with the new value.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    May 2007
    Posts
    21
    the problem is i need an algorithm so i can write a c++

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You already have something resembling an algorithm in your text describing the problem - is there any part of the description of the problem that you find hard to understand or you want clarified, then please ask more precisely.

    --
    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.

  7. #7
    Registered User
    Join Date
    May 2007
    Posts
    21
    i would like a pseudo code for these:

    input stream (algorithm for this)
    Call (decoder) ( algorithm for this)
    Call (7 Segment) ( algorithm for this)
    Output outcome (algorithm for this)

    This is the test data i will be using:
    $up
    $ = i, u = j, p = k;
    For i from 1 to 127
    For j from 1 to 127
    For k from 1 to 127

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    "algorithm" for what appears to be a few lines of code is stretching the term somewhat.

    Can you do this as a console program?

    Code:
    void displayOnSegmentDisplay ( int n ) {
      cout << "Display " << n << endl;
    }
    Like I said, get the logic working as a console program. If you write the input and output as two separate functions, then that is ALL you would need to rewrite when move to your controller. The rest of the program logic would be
    a) untouched
    b) known to work.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    May 2007
    Posts
    21
    pseudo code is the process of telling you the step of what does the programme do with english terms and a bit of code in it
    like this:

    area of triangle:

    input num1 and num2
    compute area of triangle
    area = 1 / 2 * num1 * num2
    output area

    just like that. so i want a code like that so i know how to implement to c++. makes life easier if there was a guideline. thank you

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    I'd say you've already written that much out.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Registered User
    Join Date
    May 2007
    Posts
    21
    what?if u dont wana help its okay

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by kenneth_888 View Post
    what?if u dont wana help its okay
    It is one thing helping out with understanding things, or with the details of a problem. But if you are asking someone else to essentially write the code for you, then you're looking at the wrong place. Try some consulting service, perhaps. That is, if you are willing to pay for it.

    --
    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.

  13. #13
    Registered User
    Join Date
    May 2007
    Posts
    21
    im not askin for the code, just a guide line of how to write a serial controller code.
    and i did say if u dont want to help its okay

  14. #14
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    No one is saying that we don't want to help you - but there's difference between giving help to solve a small part of a bigger problem, and sitting down to describe exactly what you need to do to solve the whole problem - especially as it seems like there's a pretty well-defined problem in your original text, so I ask again: Which part of the original problem description is it that you have a hard time dealing with?

    --
    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.

  15. #15
    Registered User
    Join Date
    May 2007
    Posts
    21
    i dont know where to start off writing the algorithm with the serial controller.
    do i decode the hex into binary then binary corresponds to the segment table to display the digit out??

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM