Searching \ for 'compact sort program' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=compact+sort+program
Search entire site for: 'compact sort program'.

Truncated match.
PICList Thread
'compact sort program'
1998\12\31@122004 by Gianni

flavicon
face
Hi!
I have written a program for a PIC16F84 that emulate a motorized 2 cam
programmable daily timer.
I keep in PIC's eeprom the setpoint (20 max) in the following
24h BCD format 1)byte HH  2)byte mm  3)byte which bit I want to set/reset .
Every minute I compare the actual time with the setpoint and if time is >=
setpoint I copy the third byte in a buffer then repaet for next setpoint.
At the end of eeprom , I copy the buffer to the out port .
This works properly only if setpoint (HH:mm) are in ascending order.
Unfortunately I have only 27 bytes of code free and 25 of ram.
Does anyone have any code to do this sort in few bytes of code ; or some
suggestion to solve my problem ? (I have already sqeezed the program as
possible).
       Thanks
       Gianni

1998\12\31@144336 by Mike Keitz

picon face
On Thu, 31 Dec 1998 18:08:30 +0100 Gianni <spam_OUTgia.ma.fraTakeThisOuTspamIOL.IT> writes:
>Hi!
>I have written a program for a PIC16F84 that emulate a motorized 2 cam
>programmable daily timer.
>I keep in PIC's eeprom the setpoint (20 max) in the following
>24h BCD format 1)byte HH  2)byte mm  3)byte which bit I want to
>set/reset .
>Every minute I compare the actual time with the setpoint and if time
>is >=
>setpoint I copy the third byte in a buffer then repaet for next
>setpoint.

>At the end of eeprom , I copy the buffer to the out port .
>This works properly only if setpoint (HH:mm) are in ascending order.

It seems like it would work no matter what the order is, if you check all
the setpoints every minute.  The only conflict would be if two or more
setpoints are telling the same output to go opposite ways the same
minute.  In that case, the last one in the table would dominate.

>Unfortunately I have only 27 bytes of code free and 25 of ram.

If I were writing this (in assembler), I can't imagine the time-keeping
and setpoint-checking parts of the program needing more than 100 or so
code locations.  The rest of the space could be used by the likely much
more complicated code to provide a user interface to set the setpoints.

It may be time to review the situation and re-write your program
entirely.  Most of my projects go through at least one such total
rewrite.

___________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com/getjuno.html
or call Juno at (800) 654-JUNO [654-5866]


'compact sort program'
1999\01\01@234546 by wwl
picon face
On Thu, 31 Dec 1998 18:08:30 +0100, you wrote:

>Hi!
>I have written a program for a PIC16F84 that emulate a motorized 2 cam
>programmable daily timer.
>I keep in PIC's eeprom the setpoint (20 max) in the following
>24h BCD format 1)byte HH  2)byte mm  3)byte which bit I want to set/reset .
>Every minute I compare the actual time with the setpoint and if time is >=
>setpoint I copy the third byte in a buffer then repaet for next setpoint.
>At the end of eeprom , I copy the buffer to the out port .
>This works properly only if setpoint (HH:mm) are in ascending order.
>Unfortunately I have only 27 bytes of code free and 25 of ram.
>Does anyone have any code to do this sort in few bytes of code ; or some
>suggestion to solve my problem ? (I have already sqeezed the program as
>possible).
>        Thanks
>        Gianni
How are the setpoints generated - could you ensure ordering by either
1) if all points are loaded into the PIC from an external source,.
sort them before sending to the PIC
2) If they're added one-at-a-time, insert in the correct place in the
list as each one is created

1999\01\05@152239 by John Payson

flavicon
face
|        That's exactly what I need ! But it's annoyng overwrite manually
|a lot of setpoints every time I add /change a new value.
|Perhaps is suitable change comparison mode rather than sort the table;
|but I haven't idea how to plan this.

What about searching through the list for the largest setpoint
time which is less-than-or-equal-to the current time?  Something
like:

 best_time = 0; best_index = 0;
 For each setpoint
   If time[this_one] <= current_time and time[this_one] > best_time
     best_index = this_one
     best_time = time[this_one]
   endif
 end loop

That should work no matter what order things are in.

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...