Searching \ for ' C on a pic c18' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: massmind.org/techref/microchip/languages.htm?key=c
Search entire site for: 'C on a pic c18'.

No exact or substring matches. trying for part
PICList Thread
'[PICLIST] C on a pic c18'
2000\12\12@102847 by info

flavicon
face
In message <spam_OUT852569B3.004D0615.00TakeThisOuTspamtdipower.com>, Andrew Kunz
<.....akunzKILLspamspam@spam@TDIPOWER.COM> writes
>const char menu[][] = {"item 1", "item 2", "item 3", "etc"};
>


Thanks, but how would this be put into ROM and accessed?

Main menu
       main menu item1
       main menu item2
               menu item2 subitem1
               menu item2 subitem2
       main menu item3
       main menu item4
               menu item4 subitem1
               menu item4 subitem2
               menu item4 subitem3
               menu item4 subitem4


Thanks again.
Alan

>--
>http://www.piclist.com hint: To leave the PICList
>piclist-unsubscribe-requestspamKILLspammitvma.mit.edu
>
>

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam.....mitvma.mit.edu


2000\12\12@105007 by Andrew Kunz

flavicon
face
You don't want to waste space doing it the "easy" way.

Instead, you need multiple arrays, not a multidimensional single array.

const char menu[][] = {"item 1", "item 2", "item 3", "etc"};
const char submenu2[][] = {"item 2 sub 1", "item 2 sub 2"};
const char submenu4[][] = {"item 4 sub 1", "item 4 sub 2", you can finish it.

Now you just check to see if the menu index == 2, then you can use menu2.

Otherwise you end up wasting lots of space.

END OF METHOD 1

METHOD 2

Make an intelligent menu parsing system using a linked list within list:

The Index column is shown for reference only.  The Entry column consists of
three things:
    a) The string for the menu option
    b) An index to the next item AT THIS LEVEL
    c) An index to the first item at the NEXT level.

Index     Entry
0    {"item 1", 1, 0}              // Item 2 is next item this level, no
sub-levels
1    {"item 2", 4, 2}              // Item 3 (index 4) is next item at this
level, index 2 is first item at next level
2    {"item 2 sub 1", 3, 0}
3    {"item 2 sub 2",0, 0}         // No more this level, no more next level
4    {"item 3",5, 0}
5    {"item 4",0,6}
6    {"item 4 sub 1",7,0}
7    {"item 4 sub 1", 8, 1}        // Point to third level entry
8    {"item 4 sub 1 subsub1 ", 0, 0}     // This one is for a third-level entry,
also marks end of list

This will require some runtime smarts, but is rather efficient in memory usage.
I have used this latter method in a PIC16C57 system that I did 7 or 8 years ago.
It's VERY efficient.  The "up" function is easy enough to remember using a
simple stack, or you can add columns in the "entry" table to manage that for
you.  Depends on if you ahve more RAM or ROM to play with.

Andy









info <EraseMEinfospam_OUTspamTakeThisOuTBROADCAST-WAREHOUSE.COM> on 12/12/2000 06:33:39 PM

Please respond to pic microcontroller discussion list <PICLISTspamspam_OUTMITVMA.MIT.EDU>








To:      @spam@PICLISTKILLspamspamMITVMA.MIT.EDU

cc:      (bcc: Andrew Kunz/TDI_NOTES)



Subject: Re: C on a pic c18








In message <KILLspam852569B3.004D0615.00KILLspamspamtdipower.com>, Andrew Kunz
<RemoveMEakunzTakeThisOuTspamTDIPOWER.COM> writes
>const char menu[][] = {"item 1", "item 2", "item 3", "etc"};
>


Thanks, but how would this be put into ROM and accessed?

Main menu
       main menu item1
       main menu item2
               menu item2 subitem1
               menu item2 subitem2
       main menu item3
       main menu item4
               menu item4 subitem1
               menu item4 subitem2
               menu item4 subitem3
               menu item4 subitem4


Thanks again.
Alan

>--
>http://www.piclist.com hint: To leave the PICList
>spamBeGonepiclist-unsubscribe-requestspamBeGonespammitvma.mit.edu
>
>

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-requestEraseMEspamspam_OUTmitvma.mit.edu

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestspamTakeThisOuTmitvma.mit.edu


2000\12\12@171906 by Bob Ammerman

picon face
> const char menu[][] = {"item 1", "item 2", "item 3", "etc"};

I don't know if this works in C18, but it is _not_ valid ANSI C.

This _is_ valid ansi C:

char const * const menu[] = { "item 1", "item 2", "item 3", "etc" };

In this case, menu is an array of const pointers to const char.

Each pointer points to one of the strings.

This has the advantage of using less memory when the strings are of widely
varying length.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestEraseMEspam.....mitvma.mit.edu


2000\12\12@214026 by Jim Ham

flavicon
face
There are (at least) two ways of  defining an array of strings in C

If the strings are unequal in length, you can define an array of pointers
to the actual strings. This means that you have the strings in memory plus
the array of pointers:

char *p_to_string[] = { "long long string", "several", "short", "strings" } ;

Or you can make all the strings equal length so that the compiler will
actually make a two-dimensional array:

char string_array[15][] = { { "15 char string"}, {"more string"}, {"etc" } } ;

This generates an array of 15 character strings. Remember that stings are
actually one byte longer than the character count to accommodate the null
byte terminator.

The compiler will warn you if any of the strings are too long. It will fill
the short strings with nulls (0). I general, C allows only the last
dimension to be automatic. All but the last must be defined in the source.

Both methods have their place.

Regards,

Jim Ham



At 02:08 PM 12/12/2000 , you wrote:
{Quote hidden}

Jim Ham, Porcine Associates
(650)326-2669 fax(650)326-1071
"http://www.porcine.com"

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestEraseMEspamEraseMEmitvma.mit.edu


2000\12\13@060310 by info

flavicon
face
One last question. Is it possible to store a function location in a
string and then retrieve that string and jump to the function
contained/referenced in that string. Back to my menu question really, i
would like to be able to hold a function against a menu option and to
have the menu system in an array would seem logical. Each menu option
could have another deeper menu or a reference to a function. How to
implement the function call is beyond me.
ALAN



In message <RemoveME4.2.2.20001212182659.00ad86d0spam_OUTspamKILLspamshell12.ba.best.com>, Jim Ham
<RemoveMEjimhamTakeThisOuTspamspamPORCINE.COM> writes
{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2000\12\13@073214 by Bond Peter S-petbond1

flavicon
face
> One last question. Is it possible to store a function location in a
> string and then retrieve that string and jump to the function
> contained/referenced in that string. Back to my menu question
> really, i
> would like to be able to hold a function against a menu option and to
> have the menu system in an array would seem logical. Each menu option
> could have another deeper menu or a reference to a function. How to
> implement the function call is beyond me.

Rather than a string for the function location, use a pointer to the
function (K&R section 5.11)

Quick and dirty example:

/* Fwd decl of a function called func_a */
int func_a(int);

...

/* Decl of a pointer to a function returning int, taking int as a parameter
*/
int (*func_ptr)(int);

/* Point it at func_a */
func_ptr = func_a;

/* Call func_a normally */
result1 = func_a(7);

/* Call it via func_ptr */
result2 = (*func_ptr)(7);

Your menu could then hold an array of structs containing the menu item and
the associated function pointer, for example.

HTH

Peter

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2000\12\13@104705 by info

flavicon
face
{Quote hidden}

That's really helpful (:  I have tried the following and I can't get the
pointer info from an array. Any ideas on what is wrong here?

#include <p18c452.h>
void main(void);
void func_a(void);

rom extern jump[5] = {func_a,func_a};

void main()
{

void (*fp)(void);

//THIS WORKS
fp=func_a;
(*fp)();
//THIS WONT
fp=jump[1];
(*fp)();
}
void func_a(){}         // return only
///////////////////////////////////////////////////
{Quote hidden}

*******************************************************
Broadcast Warehouse ( FM Transmitters and accessories )
Website:            http://www.broadcast-warehouse.com
Email:              infoSTOPspamspamspam_OUTbroadcast-warehouse.com
Phone:
   sales:          +44 (0) 208 5409992
   tech support:   +44 (0) 208 5409993
Fax:                +44 (0) 208 5409994
*******************************************************

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2000\12\13@110755 by Bond Peter S-petbond1

flavicon
face
> That's really helpful (:  I have tried the following and I
> can't get the
> pointer info from an array. Any ideas on what is wrong here?

Yup.

Sorry to be terse ("concise") -

http://www.progsoc.uts.edu.au/lists/progsoc/1998/04/msg00016.html

Peter

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2000\12\13@121500 by Bill Westfield

face picon face
   That's really helpful (:  I have tried the following and I can't get the
   pointer info from an array. Any ideas on what is wrong here?

   void func_a(void);

   rom extern jump[5] = {func_a,func_a};

   //THIS WONT
   fp=jump[1];
   (*fp)();

You don't have "jump" defined as an array of pointers to functions.
Presumably it defaults to "int", and an int (8 bits?) on a pic is much
different than a pointer to a function (more than 8 bits!)

I'm surprised that your compiler doesn't complain bitterly about the
initialization (AND the assignment of an int to fp...)

BillW

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2000\12\15@052607 by Peter L. Peres

picon face
I have a question: Can the c18 do a computed call ? Because the 16c can't,
you know. So no matter what correct ANSI C you write to get the function
address from a table of pointers it won't be jumped into. Please correct
me if I am wrong...

Peter

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2000\12\15@112634 by Andrew E. Kalman

flavicon
face
>I have a question: Can the c18 do a computed call ? Because the 16c can't,
>you know. So no matter what correct ANSI C you write to get the function
>address from a table of pointers it won't be jumped into. Please correct
>me if I am wrong...


HI-TECH PIC C and PICC-18 both support computed calls -- I do
computed calls on the PIC16, PIC17 and PIC18 parts. The only ANSI
thing not supported is recursion ...

The PIC C compiler handles computed calls for the PIC16 and PIC17 via
jump tables created at compile time. On the PIC18, it's done somewhat
differently. You can also execute function calls via pointers, as
you'd expect in ANSI C.

Clyde @ HI-TECH can supply more info .
--

 ______________________________________
  Andrew E. Kalman, Ph.D.   spamBeGoneaekSTOPspamspamEraseMEpumpkininc.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


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