??? 10/06/11 17:51 Modified: 10/06/11 20:07 Read: times Msg Score: +1 +1 Good Answer/Helpful |
#184115 - This Problem Shouts "Use a Table" Responding to: ???'s previous message |
The algorithms shown here are screaming out "table" "table" "table".
Management of irregular type sequences such as shown here are most often best handled through the use of a table. Each entry in the table can consist of something like // action // parameter // port/bit //. A simple code routine can simply initilaize an index to the table to the first entry and then scan down through the table one step at a time. The action member of each element can include functions such as: SET port pit CLR port bit LOAD loop counter LOOP decrement counter and change index if not zero STOP sequence The parameter member of each element can be used in various ways based upon the action value. For example if the action is SET or CLR this could be a delay time to wait till proceeding to the next index in the table. For the LOAD action this could be the count to put into the looping management counter. Finally if the action was the LOOP type the parameter could be the index number to branch to if the loop counter is non-zero after the decrement. (And if programming in Assembler the index value inserted can be computed at assembly time using some simple label arithmetic instantiated via a macro. Harder to do in C.) This scheme makes it very easy to make arbitrarily complex sequences of the LEDs without having to write new code each time. Some will say that this may be too complicated of an approach for students and beginning programmers but I would say otherwise. It is a very good way to force programmers to think of appropriate ways to write programs instead of the HORRIBLE code we see in the first posting here. If a beginner learns things like this from the onset of their programming venture they will forever think of good ways to do things instead of bad ways. Michael Karas |
Topic | Author | Date |
Speed control of running light | 01/01/70 00:00 | |
Please insert the legible source code | 01/01/70 00:00 | |
comments | 01/01/70 00:00 | |
please suggest some idea | 01/01/70 00:00 | |
Bad | 01/01/70 00:00 | |
Better to use timer | 01/01/70 00:00 | |
May be better - but not essential | 01/01/70 00:00 | |
Ok that 's fine | 01/01/70 00:00 | |
hw-timers for delays | 01/01/70 00:00 | |
there doesn't seem to be any other tasks | 01/01/70 00:00 | |
Not uncommon to have | 01/01/70 00:00 | |
no, you don't | 01/01/70 00:00 | |
do you have pullups on P0? | 01/01/70 00:00 | |
***__HORRIBLE CODE__*** | 01/01/70 00:00 | |
This Problem Shouts "Use a Table" | 01/01/70 00:00 | |
new tutorial needed | 01/01/70 00:00 |