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

Const ARRAYS

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







Const ARRAYS
PostPosted: Tue Sep 07, 2004 12:38 am     Reply with quote

Hello Friends !

After discovering, that long const Arrays are not working with version 3.207 I thought that I have found a work around with splitting the Arrays.
This worked fine in the first test. See in my code, at the beginning of main I am reading all Arrays and the output is completly okay !

But in the main section where the Flag IOBounce is checked, the contents of the const Array is distroyed !!!

Can pls sombody tell me whats going on here ?

Where is my big thinking fault?

I am allready thinking on changing to an other, of course much expensier
compiler, I cant deal no longer with fiddeling around who is making errors, me or the compiler.

I hope someone of You has the clear eyes to see at my code where the trouble is located.

I appreciate very much Your kindly replay and of course I will share
all my experience with You all.

best regards

Andreas


#include "/Ferndiagnose/Ferndiagnose1.h"
#include <string.h>
#include <stdio.h>
#include "/Ferndiagnose/LCD420_8B.c"

#include "/Ferndiagnose/Dallas_Rtc.h"
#include "/Ferndiagnose/DALLAS_RTC.C"
#include "/Ferndiagnose/OutLatch.c"
#include "/Ferndiagnose/Memory.c"




BYTE const test[4] = {0x10,0x20,0x30,0x40};

byte Inport[4] = {0xff,0xff,0xff,0xff}; // Data Array for Actual Input Status

// Variable Definitions

char Pin_Def[36][35];

byte const table[5]={1,2,3,4,5};




static const char Pin_def1[10][28] = {"Eingang 0 Aktiv X","Eingang 1 Aktiv X",
"Eingang 2 Aktiv X","Eingang 3 Aktiv X","Eingang 4 Aktiv X","Eingang 5 Aktiv X",
"Eingang 6 Aktiv X","Eingang 7 Aktiv X","Eingang 8 Aktiv X","Eingang 9 Aktiv X"};






BYTE ic;
BYTE i;
Byte c;
BYTE KeyIn; // InputBuffer
int16 Tim3C; // Timer 3 Counter for Sendb Flag
int16 IORead; // Counter for Periodic Input Reads
BYTE Tout; // Output Bit Register
BYTE Status;
byte Reg;
byte Seco;
char Disp[20];

Char Level;
Byte index;


int timeold;
int KeyTime;

int32 AllIn = 00;
int32 AllOld = 0xFFFFFFFF;
int32 AllBou = 0x00;
int32 AllLev = 0x00;
int32 AllCheck = 00;
int32 AllDis = 00;
int8 DebCnt[33];
int8 DebPos[33];




// Definitions for FLAGS
int1 IODis; // Flag for Displaying Input Status
int1 IOR; // Flag to Set Next Input Read Sequenz
int1 IOBou; // I/O Bounce Flag
int1 DisIO; // Flag Set if Input Changes Detected
int1 SendB; // 1ms Flag for Sending Time and Date to Display
int1 SetOut; // Flag for Setting Output Bits
int1 IOBounce; // Flag to Test for Bouncing


Byte Debounce = 5; // Debounce Counter = 10 ms
Byte IOScan= 20; // IOScan Counter = 50 ms - Fixed Scanrate


int1 Keypressed = false;
int1 KeyOK = false;



#int_ext // External Interrupt 0 - RTC Interrupt
void Ext0_isr()
{
Output_High(Pin_c3); // Set Test PIN_C3
Reg = RTC_Read(0x0c); // Read RTC Register to Clear Interrupt Flag !!
SetOut = true; // Flag for Display Routine
mstime = 0;
tim3c = 1000;
}


void main()
{
// Set All Output Signals to Init Values
// Flash Interface Signals

// General Setups

// enable_interrupts(global);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_16,0xFF,8);
setup_timer_3(T3_INTERNAL|T3_DIV_BY_4);
// setup_timer_4(T4_INTERNAL|T4_DIV_BY_8);
setup_ccp2(CCP_PWM);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
set_timer3(0xFA20);

output_High(PIN_C2); // Test Output Signal


RTC_SetTime(0x0d,0x28,0x00);
RTC_SetDate(0x04, 0x09, 0x01, 0x02);



Tout = 0; // Output Bit Register

IORead = 50; // Threshold for Input Reads
IODis = false; // Flag for Input Status Write to Display
IOBou = false;

lcd_init(); // Init LCD Display
set_tris_c(0x40); // Set RX1 Pin to Input
set_tris_b(0x01);
CCP_2_LOW = 0x10;

Set_Tris_H(0xff); // Set All Keyboard Lines to Input

RTC_Init(); // Init RTC Chip
delay_ms(5);
RTC_ReadSerialNumber(AddressHW); // Read Internal Serial Number
Disp_ID(); // Send Serial Number to Display
delay_ms(1);
SetOut = false;

Seco = 0;
tim3c = 1000; // Second Timer


// Setup for Interrupts
//enable_interrupts(int_timer3);

// Setup for Ext Interrupt 0
// Used for Periodic Int from RTC !!

ext_int_edge(0,H_TO_L); // Select Edge
//enable_interrupts(int_Ext); // Enable External Interrupt 0
Output_High(PIN_B0); // Set Pin to High Imp to allow Interrupt !!
Status = RTC_Read(0x0c); // Read Status Register to Clear pending Interrupt !!!


for (i=0;i<35;++i) Debcnt[i] = 0;


for (ic=0;ic<10;++ic)
{
strcpy(Disp,Pin_def1[ic]);
fprintf(com1,Disp);
fprintf(com1," %U \n\r",ic);
}

for (ic=0;ic<10;++ic)
{
strcpy(Disp,Pin_def2[ic]);
fprintf(com1,Disp);
fprintf(com1," %U \n\r",ic);
}

for (ic=0;ic<10;++ic)
{
strcpy(Disp,Pin_def3[ic]);
fprintf(com1,Disp);
fprintf(com1," %U \n\r",ic);
}
for (ic=0;ic<3;++ic)
{
strcpy(Disp,Pin_def4[ic]);
fprintf(com1,Disp);
fprintf(com1," %U \n\r",ic);
}



NoUpdate = true;

i = 2;
ic = table[i];


enable_interrupts(global);
enable_interrupts(int_Ext); // Enable External Interrupt 0
enable_interrupts(int_timer3);


while(1)
{

// Up from here the contents in the Array Pin_defF[x] is corrupted!!!





if (IOBounce) // Debounce Counter expired
{
IO_Read(); // Read All Inputs again
for (ic=0;ic <=32; ++ic)
{
if (bit_test(AllBou,ic) ==1) // Check for Bounce Bits
{
if (bit_test(AllIn,ic) == bit_test(AllLev,ic)) // If new Input is equal all Level
{
if (bit_test(AllIn,ic)) Level = '1';
else Level= '0';
bit_clear(AllBou,ic);
index = ic+1;
RTC_TimeDate();

if (ic > 29)
{
i=ic - 30;
strcpy(Disp,Pin_def4[i]);
}

if (ic > 19)
{
i=ic - 20;
strcpy(Disp,Pin_def3[i]);
}
if (ic > 9)
{
i=ic - 10;
strcpy(Disp,Pin_def2[i]);
}
if (ic < 10)
{
i=ic;
strcpy(Disp,Pin_def1[i]);
}

fprintf(com1,Disp);
fprintf(com1," %U \n\r",ic);

// fprintf(com1,Pin_T[ic]);
// fprintf(com1,Pin_T[ic]);

fprintf(com1," %C ",Level);
fprintf(com1," %U %U %U %lu %U %U %U \n\r",Hour,Min,Sec,mSec,Date,Month,Year);
lcd_gotoxy(1,1);
lcd_Put_string(Disp);
lcd_putc(level);
}
}
}
AllOld = AllIn;
IOBounce = false;
IOBou = false;
}



if (IOR) { // If Input Read Flag Set _ Read all Inputs and Compare to previous Read !
IO_Read();
// DisIO = false;
IOR = false; // Reset Input Read Flag !!!
if (AllIn != AllOld) // Inputs Changed
{
AllLev = AllIn; // Store Input Level
AllCheck = AllIn ^ AllOld; // In XOR Old to see which Input changed
for (ic=0;ic <=32; ++ic) // Check all Bits for changes
{
if (bit_test(AllCheck,ic)) // Test on Input changes
{
(bit_set(AllBou,ic)); // Mark Changed Input
Debcnt[ic] = Debounce; // Set for each changed Input the debounce Counter
IOBou = True; // Set Debounce Flag if at least one input changed
}
}
// if (!IOBou) DisIO = true; // If no Input changed make no display ?????
}
// if (DisIO) IO_Disp(); // If Display Flag set then Display change ??????
}


} //while(1)
} //main
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Tue Sep 07, 2004 11:20 pm     Reply with quote

Please use the Code buttons when you post your code again, the one you have posted is very difficult to follow.

How do you know the const array is getting destroyed? Const arrays are held in flash and destroying them is not that easy. Remember, you can NOT look at the contents of a constant array in the watch window, as you will only see garbage. This is because CCS implements function calls/returns for constant arrays.
Andreas
Guest







PostPosted: Tue Sep 07, 2004 11:41 pm     Reply with quote

Thank You Haplo,

I didnt know about the Code button, will use it next time.

How do I know, that its destroyed ?

First I thought with the automatic watch with moving the cursor to variable,

okay I didnt know that this is not working.

Second if You look into my code I have a section somewhere in the middle, where I state " // Up from here the contents in the Array Pin_defF[x] is corrupted!!!" there is a point where I want to read the array and print it to the com1. at this point only garbagge is coming out !!!!!!!

If You have a hardware with just one seriell port you can easily check it .

Maybe I understand something with reading the array completly wrong, but at the first place in my code( Just after the init section) I get the array complete ok to the ser port in the second place I get only garbage !.

I am allready completly confused what is going on. I chanced today to the newest release 3.209 but this also didnt solve this.

Maybe You might get a hold on a spec point to let me see where my thinking is going in the wrong direction.

Thank You very much for Your replay and looking forward to here more form YOu.

Not to mention, that of course I will share my experience !!!

best regards

Andreas
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Tue Sep 07, 2004 11:49 pm     Reply with quote

Yes, holding the cursor on top of the constant arrays does not show its value. However, you aer getting garbage out of the serial port, then something is wrong.
Ok, post your code again using the Code button, and I (and the others) will take a look at it.
Andreas
Guest







Const Arrays
PostPosted: Wed Sep 08, 2004 1:22 am     Reply with quote

Thank You Ali,

Okay, As I told You I didnt know that the cursor Readings are missleading
at const Arrays !
It should be stated somewhere, or do I missed it ?

So here is the code again, wow looks much better now, I understand
that You like this better !

best regards

Andreas


Code:
#include "/Ferndiagnose/Ferndiagnose1.h"
#include <string.h>
#include <stdio.h>
#include "/Ferndiagnose/LCD420_8B.c"

#include "/Ferndiagnose/Dallas_Rtc.h"
#include "/Ferndiagnose/DALLAS_RTC.C"
#include "/Ferndiagnose/OutLatch.c"
#include "/Ferndiagnose/Memory.c"




BYTE const test[4] = {0x10,0x20,0x30,0x40};

byte Inport[4] = {0xff,0xff,0xff,0xff};         // Data Array for Actual Input Status

                        // Variable Definitions

char Pin_Def[36][35];

byte const table[5]={1,2,3,4,5};




static const char Pin_def1[10][28] = {"Eingang 0 Aktiv    X","Eingang 1 Aktiv    X",
"Eingang 2 Aktiv    X","Eingang 3 Aktiv    X","Eingang 4 Aktiv    X","Eingang 5 Aktiv    X",
"Eingang 6 Aktiv    X","Eingang 7 Aktiv    X","Eingang 8 Aktiv    X","Eingang 9 Aktiv    X"};

static const char Pin_def2[10][25] = {"Eingang 10 Aktiv   X","Eingang 11 Aktiv   X","Eingang 12 Aktiv   X",
"Eingang 13 Aktiv   X","Eingang 14 Aktiv   X","Eingang 15 Aktiv   X","Eingang 16 Aktiv   X",
"Eingang 17 Aktiv   X","Eingang 18 Aktiv   X","Eingang 19 Aktiv   X"};

static const char Pin_def3[10][25] = {"Eingang 20 Aktiv   X","Eingang 21 Aktiv   X",
"Eingang 22 Aktiv   X","Eingang 23 Aktiv   X","Eingang 24 Aktiv   X","Eingang 25 Aktiv   X",
"Eingang 26 Aktiv   X","Eingang 27 Aktiv   X","Eingang 28 Aktiv   X","Eingang 29 Aktiv   X"};

static const char Pin_def4[3][25] = {"Eingang 30 Aktiv   X","Eingang 31 Aktiv   X","Eingang 32 Aktiv   X"};


char const Pin_T[5][20] = {"Eingang 0 Aktiv ","Eingang 1 Aktiv "};



BYTE ic;
BYTE i;
Byte c;
BYTE KeyIn;             // InputBuffer
int16 Tim3C;            // Timer 3 Counter for Sendb Flag
int16 IORead;           // Counter for Periodic Input Reads
BYTE Tout;              // Output Bit Register
BYTE Status;
byte Reg;
byte Seco;
char Disp[20];

Char Level;
Byte index;


int timeold;
int KeyTime;

int32 AllIn = 00;
int32 AllOld = 0xFFFFFFFF;
int32 AllBou = 0x00;
int32 AllLev = 0x00;
int32 AllCheck = 00;
int32 AllDis = 00;
int8  DebCnt[33];
int8  DebPos[33];




                        // Definitions for FLAGS
int1 IODis;             // Flag for Displaying Input Status
int1 IOR;               // Flag to Set Next Input Read Sequenz
int1 IOBou;             // I/O Bounce Flag
int1 DisIO;             // Flag Set if Input Changes Detected
int1 SendB;             // 1ms Flag for Sending Time and Date to Display
int1 SetOut;            // Flag for Setting Output Bits
int1 IOBounce;          // Flag to Test for Bouncing


Byte Debounce = 5;      // Debounce Counter = 10 ms
Byte IOScan= 20;        // IOScan Counter = 50 ms - Fixed Scanrate


int1 Keypressed = false;
int1 KeyOK = false;



#int_ext                // External Interrupt 0 - RTC Interrupt
void Ext0_isr()
{
Output_High(Pin_c3);    // Set Test PIN_C3
Reg = RTC_Read(0x0c);   // Read RTC Register to Clear Interrupt Flag !!
SetOut = true;          // Flag for Display Routine
mstime = 0;
tim3c = 1000;
}


#int_timer3
void timer3_isr() {

set_timer3(0xfA20);     // Setupt Timer3 as ms Timer

   mstime =++mstime;       // Increment ms Timer

   if (--IORead==0) {
      IORead = IOScan;
      IOR = true;
   }
   if(--tim3c==0) {
      Sendb = true;
      tim3c = 1000;
    }
   if (IOBou)
   IORead = IOScan - Debounce;
   IOBounce = false;                              // Reset Bounce Flag
   {
   for (ic=0;ic <=32; ++ic)
       {
       if (Debcnt[ic] !=0)
         {
         Debcnt[ic] -= Debcnt[ic];                    // Decrement each Debounce ctr
         if (Debcnt[ic] == 0) IOBounce = true;        // If at least one counter reached Zero set Flag !
         }
       }
   }
}

void IO_Disp()
{
   Byte index;
   Byte check;
   char Level;
   lcd_gotoxy(1,1);

 if (AllIn != AllOld)
    {
    AllCheck = AllIn ^ AllOld;
    AllOld = AllIn;

       for (ic=0;ic<=32;++ic)
            {
            if (bit_test(AllCheck,ic))
               {
               if (bit_test(AllIn,ic)) Level= '1';
                   else Level= '0';
                   index = ic+1;
                   fprintf(com1,Pin_def[index]);
                   fprintf(com1," %C \n\r",Level);
                   lcd_gotoxy(1,1);
                   lcd_Put_string(Pin_def[index]);
                   lcd_putc(level);
               }
            }
   IOR = false;
   }
}


void IO_Read()                // Read All Input Ports
{
   Byte cnt;

      Output_High(E_Input);   //Enable Input Buffers
      delay_cycles(3);
      Output_Low(OE_1);       //Select Input Buffer 1
      delay_cycles(3);
      Inport[0] = input_D();
      output_High(OE_1);
      Output_Low(OE_2);       //Select Input Buffer 2
      delay_cycles(3);
      Inport[1] = input_D();
      output_High(OE_2);
      Output_Low(OE_3);       //Select Input Buffer 3
      delay_cycles(3);
      Inport[2] = input_D();
      output_High(OE_3);
      Output_Low(OE_4);       //Select Input Buffer 4
      delay_cycles(3);
      Inport[3] = input_D();
      output_High(OE_4);
      Output_Low(E_Input);    //Disable All Input Buffers

      AllIn = 0;              // Convert 4 Input Values to one 32Bit Value !
   for (cnt=4; cnt > 0; --cnt)
      {
      AllIn <<=8;
      AllIn |= Inport[cnt-1];
      }
}

void main()
{
      // Set All Output Signals to Init Values
      // Flash Interface Signals

Output_High(RReset);          // RAM Reset
Output_High(ROut_E);          // RAM Output Enable
Output_High(RDir);            // RAM Data Direction Set to Write to Flash
Output_High(E_Out_Buffer);    // Disable Output Driver
Output_High(CLK);             // RAM Clock Input
Output_Low(WP);               // Page Write Protect

Output_High(RB_1);             // Ready /-Busy RAM
Output_High(RB_2);
Output_High(RB_3);
Output_High(RB_4);

Output_High(CS_1);             // -Chip Select for RAM
Output_High(CS_2);
Output_High(CS_3);
Output_High(CS_4);

      // Output Driver Interface
Output_Low(E_OUT);            // Disable Output Latch
OutLatch = 0x00;              // Clear Output Latch Variable

      // LED Backlight Control
Output_High(BackLight);

      // General Setups

// enable_interrupts(global);
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_16,0xFF,8);
   setup_timer_3(T3_INTERNAL|T3_DIV_BY_4);
 //  setup_timer_4(T4_INTERNAL|T4_DIV_BY_8);
   setup_ccp2(CCP_PWM);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   set_timer3(0xFA20);

   output_High(PIN_C2);       // Test Output Signal


     RTC_SetTime(0x0d,0x28,0x00);
     RTC_SetDate(0x04, 0x09, 0x01, 0x02);



Tout = 0;                           //  Output Bit Register

IORead = 50;                        // Threshold for Input Reads
IODis = false;                      // Flag for Input Status Write to Display
IOBou = false;

lcd_init();                         // Init LCD Display
set_tris_c(0x40);                   // Set RX1 Pin to Input
set_tris_b(0x01);
CCP_2_LOW = 0x10;

Set_Tris_H(0xff);                   // Set All Keyboard Lines to Input

RTC_Init();                         // Init RTC Chip
delay_ms(5);
RTC_ReadSerialNumber(AddressHW);    // Read Internal Serial Number
Disp_ID();                          // Send Serial Number to Display
delay_ms(1);
SetOut = false;

Seco = 0;
tim3c = 1000;                       // Second Timer


         // Setup for Interrupts
//enable_interrupts(int_timer3);

         // Setup for Ext Interrupt 0
         // Used for Periodic Int from RTC !!

ext_int_edge(0,H_TO_L);             // Select Edge
//enable_interrupts(int_Ext);         // Enable External Interrupt 0
Output_High(PIN_B0);                // Set Pin to High Imp to allow Interrupt !!
Status = RTC_Read(0x0c);            // Read Status Register to Clear pending Interrupt !!!


   for (i=0;i<35;++i) Debcnt[i] = 0;


   for (ic=0;ic<10;++ic)
   {
   strcpy(Disp,Pin_def1[ic]);
   fprintf(com1,Disp);
   fprintf(com1,"   %U \n\r",ic);
   }

  for (ic=0;ic<10;++ic)
   {
   strcpy(Disp,Pin_def2[ic]);
   fprintf(com1,Disp);
   fprintf(com1,"   %U \n\r",ic);
   }

  for (ic=0;ic<10;++ic)
   {
   strcpy(Disp,Pin_def3[ic]);
   fprintf(com1,Disp);
   fprintf(com1,"   %U \n\r",ic);
   }
  for (ic=0;ic<3;++ic)
   {
   strcpy(Disp,Pin_def4[ic]);
   fprintf(com1,Disp);
   fprintf(com1,"   %U \n\r",ic);
   }



NoUpdate = true;

i = 2;
ic = table[i];


enable_interrupts(global);
enable_interrupts(int_Ext);         // Enable External Interrupt 0
enable_interrupts(int_timer3);


while(1)
{

if (!Keypressed)
   {
   KeyIn = Input_H();                  // Read Keyboard Inputs
      if (KeyIn != 0xff)
         if (!input(PIN_H0))
         lcd_putc("1");
         if (!input(PIN_H1))
         lcd_putc("2");
         if (!input(PIN_H2))
         lcd_putc("3");
         if (!input(PIN_H3))
         lcd_putc("4");
         if (!input(PIN_H4))
         lcd_putc("5");
         if (!input(PIN_H5))
         lcd_putc("6");
         if (!input(PIN_H6))
         lcd_putc("7");
         if (!input(PIN_H7))
         lcd_putc("8");
   }


if (sendb) {                        // If Second Timer Elapsed then Display Time and Date
      lcd_putc("\n");
      RTC_Time_Display();
      RTC_Date_Display();
      if (seco != sec)
      {
         lcd_gotoxy(37,1);
         Disp_Dec(mstime);
//         mstime = 0;
         Seco = sec;
      }
      sendb = false;
}

if (SetOut) {
      if (Tout < 8) {               // Set Periodic Output Bits !! Only for Testing Purpose !!
            Out_Bit(Tout,1);
            lcd_gotoxy(32,2);
            Disp_Bin(OutLatch);
            Tout =++Tout;
      }
      if (Tout > 8) {
            Out_Bit(Tout-9,0);
            lcd_gotoxy(32,2);
            Disp_Bin(OutLatch);
            Tout =++ Tout;
            if (Tout == 17) Tout = 0;
      }
      if (Tout ==8) Tout =++Tout;

SetOut = false;
}



      // Up from here the contents in the Array Pin_defF[x] is corrupted!!!]
     
     



if (IOBounce)                                                  // Debounce Counter expired
   {
   IO_Read();                                                  // Read All Inputs again
   for (ic=0;ic <=32; ++ic)
           {
            if (bit_test(AllBou,ic) ==1)                       // Check for Bounce Bits
               {
               if (bit_test(AllIn,ic) == bit_test(AllLev,ic))   // If new Input is equal all Level
                  {
                     if (bit_test(AllIn,ic))  Level = '1';
                        else Level= '0';
                        bit_clear(AllBou,ic);
                        index = ic+1;
                        RTC_TimeDate();

                        if (ic > 29)
                           {
                           i=ic - 30;
                           strcpy(Disp,Pin_def4[i]);
                           }

                         if (ic > 19)
                           {
                           i=ic - 20;
                           strcpy(Disp,Pin_def3[i]);
                           }
                         if (ic > 9)
                           {
                           i=ic - 10;
                           strcpy(Disp,Pin_def2[i]);
                           }
                         if (ic < 10)
                           {
                           i=ic;
                           strcpy(Disp,Pin_def1[i]);
                           }

                           fprintf(com1,Disp);
                           fprintf(com1,"   %U \n\r",ic);

   //                             fprintf(com1,Pin_T[ic]);
   //                             fprintf(com1,Pin_T[ic]);

                        fprintf(com1," %C ",Level);
                        fprintf(com1," %U  %U %U  %lu   %U  %U %U   \n\r",Hour,Min,Sec,mSec,Date,Month,Year);
                        lcd_gotoxy(1,1);
                        lcd_Put_string(Disp);
                        lcd_putc(level);
                  }
               }
           }
      AllOld = AllIn;
      IOBounce = false;
      IOBou = false;
      }



if (IOR) {                                  // If Input Read Flag Set _ Read all Inputs and Compare to previous Read !
   IO_Read();
//   DisIO = false;
   IOR = false;                             // Reset Input Read Flag !!!
   if (AllIn != AllOld)                     // Inputs Changed
      {
      AllLev = AllIn;                       // Store Input Level
      AllCheck = AllIn ^ AllOld;            // In XOR Old to see which Input changed
           for (ic=0;ic <=32; ++ic)         // Check all Bits for changes
               {
               if (bit_test(AllCheck,ic))    // Test on Input changes
                  {
                   (bit_set(AllBou,ic));     // Mark Changed Input
                   Debcnt[ic] = Debounce;    // Set for each changed Input the debounce Counter
                   IOBou = True;             // Set Debounce Flag if at least one input changed
                  }
               }
//         if (!IOBou) DisIO = true;         // If no Input changed make no display ?????
      }
//   if (DisIO) IO_Disp();                   // If Display Flag set then Display change ??????
}


} //while(1)
} //main
Andreas
Guest







PostPosted: Wed Sep 08, 2004 3:06 pm     Reply with quote

Hello Ali !

Thank You very much for willing to help me !

In the meantime I found the major Problem in my Code.

It was that easy that I was always thinking everything is okay.
If You look at my code I am using the variable "ic" for determining
which array entry to show, but unfortunatly I am using the same public variable in the interruot section of my code, so this variable was alsways destroyed by the interrupt !!!

That Easy !!!

But according to some posts in this forum It was mentioned that CCS has a problem with large Const Arrays - it looks that this problem is still not fixed with new release !!!!


But I have to thank also CCS that they allowed me to download the last revision after my expired 30days !


MAybe You find a solution to make out of my 4 arrays one large ????

Thanks so far and good morning

Andreas
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Wed Sep 08, 2004 6:01 pm     Reply with quote

Andreas,

The CCS manual clearly states that the ROM arrays may not occupy more
than 256 locations. So I'm afraid there is no straight-forward way of putting all your strings in one big array. I'll get back to this later.
Look at Pin_def1, it is 280 bytes, bigger than the maximum allowable size. It still works probably because the location of the first character of your last string is smaller than 256, you got lucky there. Looking at your strings in Pin_def1, they all have constant length of 20. So allocating 21 bytes (20+one byte for te null character) should be enough. I recommend you to change the definition of Pin_def1 to [10][28]. This way you will also save ROM space. The same goes for the rest of your arrays.

Now how to have very large arrays. You can do this by placing all the characters in your strings one by one in the Flash (using #ROM), and later reading them and sending them to the LCD.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Wed Sep 08, 2004 6:58 pm     Reply with quote

Not sure exactly what you are trying to do, but the majority of the strings are the same. It appears that only a number changes. Sounds like a waste of ROM to repeat all that. Why not just do this?????
Code:

   for (ic=0;ic<33;++ic)
     fprintf(com1, "Eingang %U Aktiv    X",ic);
Andreas
Guest







PostPosted: Wed Sep 08, 2004 11:47 pm     Reply with quote

Hi Ali

Thank You for the help, I have to read the manual again, but I can remember of this limiitation and was also wondering why the size 10,28 was working.


Hi Mark the reason for this array is that the contents at startup is only used for a non initialized system, later the customer will be able to sent his own pin definitions thru the serial port to the system and then I will store it in the same array .

The suggestion of Haplo to make it with the #ROM statement was also in my consideration, but I thought in this way it would be easier.

Thanks to ALl who revised my code, just only taking about leads sometimes to the solution.


BTW, because of accepting my request for download will turn me to sign in for a year assitance at CCS, so I will stick with the compiler

best regards

ANdreas
Trampas



Joined: 04 Sep 2004
Posts: 89
Location: NC

View user's profile Send private message MSN Messenger

PostPosted: Thu Sep 09, 2004 6:41 am     Reply with quote

Andres,

I will give you a bit of free advice, and it may be worth what you paid!

I do not use the internal flash for storing things the user can change. I personally use a SPI Flash chip. The reason is that unless I am making 1000s of these devices were the cost of the BOM is issue, it may be cheaper. The reason is that you can use the same SPI Flash chip and code on multiple projects and microcontrollers. Thus you write your code to load user parameters and then use the same code and interface on next project.

I personally have been using the AT45DB041 series of chips. They have various sizes available with same footprint, thus if more configuration needed I can add a larger chip with out change the PCB design!

Another thing I do is when doing field firmware updates, I download the firmware to the external flash. Then when firmware is all download I do the update. I percieve it being a bit safer for end user, may not be but...

Of course if BOM price is an issue, then continue an use every ounce of capabilities out of all the chips on your board.

Trampas
Andreas
Guest







PostPosted: Thu Sep 09, 2004 9:39 am     Reply with quote

Hello Trampas,

Thanks for Your advices, BTW I was also thinking in this way before and
as a matter of fact I have on my board up to 4 64Mb Data Flash Chips from Atmel, its of course the same family that You mentioned.

My Reason for going into Onchip Flash was, that in this case the external memory can be used at all for Recorded Data.

Me Project is a Datalogger for 32 Inputs and 8 Outputs with the capability to make a remote check of the system status. In the future , means in about 3 month I have to add also a wireless networking thru a GPRS System.

So in my case the Processor is the part wich will change from customer to customer and the external memorx has allways the same function.

But be shure I will start considering Your aproach for remote update, I like this way, just have to find out a way to determine if enough memory is aval and some others.

Do You use the ATmel Chip in parallel mode or only on the SPI Side ?

Thanks so far and keep in touch

ANdreas
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Thu Sep 09, 2004 5:27 pm     Reply with quote

Andreas wrote:
Hi Mark the reason for this array is that the contents at startup is only used for a non initialized system, later the customer will be able to sent his own pin definitions thru the serial port to the system and then I will store it in the same array .


If these strings are going to be changed frequently and you prefer to use the on-chip resources, I recommend using the EEPROM instead of FLASH.
Andreas
Guest







PostPosted: Fri Sep 10, 2004 1:10 am     Reply with quote

Hi Ali,

Yes I was also thinking of using the EEPROM. Why do You think its the better
idea ?

BTW, can You tell me an easy way to get the start adress of the Array?

whether its in Flash or in EEPROM I have to rewrite it with new data.

Yes, my porgramm is now working as it should be and also the large array is working. I am using now "static const Pin_def[33][34] and looks its working now. I didnt try to compile with the old compiler !

Looks like they eliminated also the const array limitation of 256 Bytes !

Best regards

Andreas
Ttelmah
Guest







PostPosted: Fri Sep 10, 2004 2:13 am     Reply with quote

Andreas wrote:
Hi Ali,

Yes I was also thinking of using the EEPROM. Why do You think its the better
idea ?

BTW, can You tell me an easy way to get the start adress of the Array?

whether its in Flash or in EEPROM I have to rewrite it with new data.

Yes, my porgramm is now working as it should be and also the large array is working. I am using now "static const Pin_def[33][34] and looks its working now. I didnt try to compile with the old compiler !

Looks like they eliminated also the const array limitation of 256 Bytes !

Best regards

Andreas

The key difference between the EEPROM, and the flash memory, is it's 'life'. Typically, the EEPROM is rated for 100* as many write cycles (or more), than the flash memory. It is suprisingly easy to use up the entire chip life, if data that changes at all frequently is written to flash.
Consider just writing your own 'wrapper' for the eeprom read/write functions. For instance, if your array has a 'line' that is 10 bytes long, then something like:
#define read_eeprom_array(x,y) read_eeprom(x*10L+y)

would allow you to access an address in the eeprom, with an row/column address. Obviously on the chips internal eeprom, this would only allow 25 rows, on the chips with 256 addresses, but on the chips with 1024 addresses, or using an external eeprom, it gives the translation required. This is the same arithmetic, that the compiler itself is doing, when dealing with an array. The addvantage of this, is that te array is simply consecutive addresses, and you can put it anywhere you want. The problem normally, is that when dealing with (say) a flash based array, CCS, adds a copy of the read_program_eeprom code, in front of the data itself (on chips that support this ability), hence the data is not simply organised in the ROM at the start of the array 'location'. Using your own external call to the function, allows you to just have the array placed with a #ROM statement, at the location you want, and makes access for updates much easier...

Best Wishes
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