Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-05-2007, 12:04 AM
kenneth_888 kenneth_888 is offline
Newbie
 
Join Date: Sep 2007
Posts: 4
Rep Power: 0
kenneth_888 is on a distinguished road
Default 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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-13-2007, 11:16 AM
kkelly's Avatar   
kkelly kkelly is offline
Learning Programmer
 
Join Date: Sep 2007
Posts: 50
Rep Power: 5
kkelly is on a distinguished road
Default

What you're describing is a grammar analyzer. A grammar analyzer consists of a parser and lexical analyzer.
The Parser operates at a syntax level. The Lexical Analyzer operates at the buffer level. If you were reading a book, your brain would be the Parser and your eyes would be the Lexical Analyzer.
So you are sitting there and decide to read a book. You get up and walk to your bookshelf and select a book called SerialDevice. You sit back down, open the book (the stream), turn to the first page, and prepare to read (instantiate your SerialContoller class, and pass it the stream).
Now the logic gets a little more intricate. To make it simpler, lets pretend the book is just a sentence long. So we want to read the sentence. More specifically, we want read each word in the sentence. So our brain says, "Eyes, get the first word", and our eyes move through the sentence until they reach a space (or $), and returns, "This array of characters is the word you requested." Then our brain interprets the word by comparing it to all the cases (like in a switch statement) of words it knows. So if the word is UP, it calls the appropriate function. If it is PU, it might reply, "That doesn't make sense, scan it again eyes", or it might say, "Whatever. Get me the next word"
So, thats the gist of it. Just remember only the Parser calls Lexical Analzer and only the Lexical Analyzer handles the buffer.
The next step I may or may not be able to help with. So, with the grammar analyzer we can get valid commands. The question is, "Does this need to happen on a separate thread?" I'm not quite up to multithreading yet, but if it does need to be on another thread you would need to have the Parser call a public function of the command buffer object that will put the command in the buffer. Also, unless the command buffer processor is polling the command buffer, an event would have to notify the processor a command has been put in the queue. An event system is easy enough to create. But I'll wait for a response before I elaborate.
If not, then you would still have the Parser call a public function of the command buffer, but you wouldn't raise an event. Practically, there is no need for a command buffer if the flow of execution is synchronous. However, if this is just "proof of concept", then the Parser could read in several commands, and execution could then be handed to the command buffer processor.

Last edited by kkelly; 09-13-2007 at 01:31 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
New Algorithm Matches Any Tumor Cells To Best Possible Anticancer Treatments Kernel Programming News 0 07-29-2007 08:52 PM
Serial Port Close Problem in Pocket PC HosseinSadeghi C# Programming 0 07-14-2007 02:40 AM
Usb to serial adapter driver jatinder_44 Visual Basic Programming 0 06-11-2007 09:46 AM
efficient algorithm sovixi Python 3 04-19-2007 02:47 PM
can sum1 help me in making a CPU scheduling algorithm program in c? bryan General Programming 2 11-28-2006 12:55 PM


All times are GMT -5. The time now is 07:13 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads