CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

messages in an array

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sadlpx



Joined: 19 Feb 2004
Posts: 23

View user's profile Send private message

messages in an array
PostPosted: Wed Jun 01, 2005 11:22 am     Reply with quote

I'm not a very good C programmer but here is what i'm trying to accomplish.

I have a 4 line LCD, I want the top 3 lines to be a vertically scrolling menu. My choice will always be the middle line. IF i hit enter i will know what he message is based on the current menu.

What i want

" CMD 0"
"> CMD1"
" CMD2"
" up dwn esc enter"

If i hard code each line with a series of case statment (one of each menu it works fine)

Here is what i would like to do, much easier, much shorter

STRUCT CMDS {
char C_string[19];
} ;

Const Struct CMDS C_item[10] =
{
{"cmd0 \n\0"},
{"cmd1 \n\0"},
{"cmd2 \n\0"},
{"cmd3 \n\0"},
{"cmd4 \n\0"},
{"cmd5 \n\0"},
{"cmd6 \n\0"},
{"cmd7 \n\0"},
{"cmd8 \n\0"},
{"cmd9 \n\0"},
};



// ----------------------------------------------------------------------------


void Display_Menu(int new) {

LCD_goto(2);
printf(C_item[new]);
LCD_goto(22);
printf(C_item[new +1]);
LCD_goto(42);
printf(C_item[New + 2]);
}

Problem is everytimeit restarts each line with "cmd0" and gets longer.

Feeling stupid
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 01, 2005 12:08 pm     Reply with quote

Post your LCD_goto() function.
sadlpx



Joined: 19 Feb 2004
Posts: 23

View user's profile Send private message

PostPosted: Wed Jun 01, 2005 12:44 pm     Reply with quote

Here is the function but i don't think that thast the problem


void LCD_goto( int posn ) {

putc(16); // Cursor Position command
posn = posn + 64;
putc(posn); // New LIne Position
}


If i hard code the origina routine ina casr atatement it works fine, only the chage to the array causes me problems. here was my original code usign 2 cases. the only difference was commenting out the fixed message and trying the array.

16f876 @10M



void Display_Menu(int new) {

switch(new) {
case 0:
LCD_goto(2);
printf("*** MAIN MENU ****");
// printf(C_item[0]);
LCD_goto(22);
printf("Run Battery Test ");
// printf(C_item[1]);
LCD_goto(42);
printf("Download Data ");
// printf(C_item[2]);
break;
case 1:
LCD_goto(2);
printf("Run Battery Test ");
LCD_goto(22);
printf("Download Data ");
LCD_goto(42);
printf("Setup ");
break;
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 01, 2005 1:18 pm     Reply with quote

If you think there's a problem with the ROM structure, you don't
need an LCD to test it. You can test it with a terminal program.

I made the following test program. I couldn't get your code to
compile with PCM vs. 3.225. The compiler gave me this error
message on all your printf lines:
"Attempt to create a pointer to a constant"

I fixed that by adding "%s" to all your printf statements.
I also commented out your LCD_goto() statements because they
don't apply to my terminal program.
I ran the program and I got this output on my terminal window:
Code:

Hello World
cmd0
     cmd1
          cmd2   


Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#ignore_warnings 202, 203

//============================

STRUCT CMDS {
char C_string[19];
} ;

Const Struct CMDS C_item[10] =
{
{"cmd0 \n\0"},
{"cmd1 \n\0"},
{"cmd2 \n\0"},
{"cmd3 \n\0"},
{"cmd4 \n\0"},
{"cmd5 \n\0"},
{"cmd6 \n\0"},
{"cmd7 \n\0"},
{"cmd8 \n\0"},
{"cmd9 \n\0"},
};

//-----------------------

void Display_Menu(int new)
{
//LCD_goto(2);
printf("%s", C_item[new]);
//LCD_goto(22);
printf("%s", C_item[new +1]);
//LCD_goto(42);
printf("%s", C_item[New + 2]);
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group