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

Problems with constants

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







Problems with constants
PostPosted: Thu Jul 20, 2006 3:14 pm     Reply with quote

Iīm using a PIC16F877, so I have to split the Functions. But now I canīt put my Constants and the programm in one function. I tried this code, but it doesnīt work:

Main.c file:

Hauptmenu_A();




Hauptmenu_A.c file:

int Konstanten_Hauptmenu (int x)
{

BYTE CONST Konstanten_Hauptmenu_A [64] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x10,0x20,0x60,0xC0,0xC0,0x80,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x30,0x30,0x30,0x30,0x30,0x30,
0x30,0xF0,0xE0,0x00,0xF0,0xF0,0x00,0x00,
0x00,0x00,0x00,0xF0,0xF0,0x00,0xE0,0xF0};

return(Konstanten_Hauptmenu_A[x]);
}

void Hauptmenu_A (void)
{
for (x = 0; x < 63; ++x)
{
Write_Display_Data (Konstanten_Hauptmenu_A[x]);
m = Konstanten_Hauptmenu_A[x];
}
}


.... m is always a random number... any Ideas?
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu Jul 20, 2006 3:38 pm     Reply with quote

Consider two arrays of 32 each.

Code:

const int8 A[] = { /*put first 32 values here*/};
const int8 B[] = { /*put second 32 values here*/};

int Konstanten_Hauptmenu(int x)
{
   if (x>31)
      return(B[x]);
   else
      return(A[x]);
}


Maybe not the prettiest but might work.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 20, 2006 3:43 pm     Reply with quote

I made the test program, shown below. It works.
It displays the following:
Quote:

0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 20 60 C0 C0 80 80 00 00 00 etc.

I tested this with PCM vs. 3.249.
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)

int Konstanten_Hauptmenu (int x)
{

BYTE CONST Konstanten_Hauptmenu_A [64] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x10,0x20,0x60,0xC0,0xC0,0x80,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x30,0x30,0x30,0x30,0x30,0x30,
0x30,0xF0,0xE0,0x00,0xF0,0xF0,0x00,0x00,
0x00,0x00,0x00,0xF0,0xF0,0x00,0xE0,0xF0};

return(Konstanten_Hauptmenu_A[x]);
}

void Hauptmenu_A (void)
{
int8 x;
int8 m;

for(x = 0; x < 63; ++x)
   {
    //Write_Display_Data (Konstanten_Hauptmenu_A[x]);
    m = Konstanten_Hauptmenu(x);
    printf("%X ", m);
   }
}


//=================================
main()
{

Hauptmenu_A();

while(1);
}
Richi
Guest







PostPosted: Thu Jul 20, 2006 11:32 pm     Reply with quote

Thanks a lot PCM, found the error this morning: I declared the constants not global but in a subroutine local....
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