Help with "Not enough RAM 'active_state'" message

mikroC, mikroBasic and mikroPascal PRO for Microchip’s 8-bit PIC MCUs.
Post Reply
Author
Message
svasilevski19@gmail.com
Posts: 2
Joined: 20 Jan 2024 16:42

Help with "Not enough RAM 'active_state'" message

#1 Post by svasilevski19@gmail.com » 20 Jan 2024 16:49

Hi all.

New member here with MikroC for PIC.And my issue here is that in my code for PIC16F84A is a message that there is not enough RAM for 'active_state'.

Down there is the code that I am working on.

Code: Select all

unsigned short shifter, portd_index;
unsigned int   digit, number;
unsigned short portd_array[4];

bit oldstate;                                    // Stara sostojba (flag)
unsigned int broi_1ms, flag_1s;                      //flag za sekunda, brojac za milisekundi
unsigned int  sekundi = 0, minuti = 0;
unsigned int sekundi_desetki=0, sekundi_edinici=0, minuti_edinici=0, minuti_desetki=0;


sbit LED1 at PORTA.B0;
sbit LED2 at PORTA.B1;
sbit LED3 at PORTA.B2;



unsigned int  sevenBCD[10] = {
  0B0000, //'0'
  0B0001, //'1'
  0B0010, //'2'
  0B0011, //'3'
  0B0100, //'4'
  0B0101, //'5'
  0B0110, //'6'
  0B0111, //'7'
  0B1000, //'8'
  0B1001, //'9'
 };

void checkButtons(){
      if (Button(&PORTB, 4, 1, 1)) {                  // Detektira logicka edinica
          oldstate = 1;                              // ja setira flagot i pocnuva da broi
      }
      if(Button(&PORTB, 5, 1, 1)){                   //tasterot STOP e pritisnat
          oldstate = 0;                              //ja vrakja na nula i ne odbrojuva
       }
}
void InitTimer0(){
  OPTION_REG         = 0x82;
  TMR0                 = 6;
  INTCON         = 0xA0;
}
void Interrupt(){
            if (TMR0IF_bit){
            
                PORTA = 0;                             // Turn off all 7seg displays
                PORTB = portd_array[portd_index];      // bring appropriate value to PORTD
                PORTA = shifter;                       // turn on appropriate 7seg. display

                // move shifter to next digit
                 shifter <<= 1;
                  if (shifter > 8u)
                      shifter = 1;

                      // increment portd_index
                 portd_index++ ;
                 if (portd_index > 3u)
                    portd_index = 0;             // turn on 1st, turn off 2nd 7seg.
                TMR0IF_bit         = 0;
                TMR0                 = 6;
                                     // if( oldstate == 1)
            if(oldstate == 1){
            broi_1ms++;
            if(broi_1ms > 1000)
            {
               broi_1ms = 0; // ja vrakjame promenlivata od nula da broi i da broi do 100 pak
               flag_1s = 1; // imame izbrojano edna sekunda
               sekundi++;
            }
            if(sekundi == 60)
            {
                 //imame edna minuta(60 sekundi)
                 //minuti se zgolemuvaat
                 sekundi = 0;
                 minuti++;
            }
            if(minuti == 99)
            {
                 //ako imame 99 minuti vrati gi na 00
                 minuti = 0;
            }
        }
    }
}

void main() {
       InitTimer0();
       TRISA = 0x00;
       TRISB = 0xF0;
       portd_index = 0;
       shifter = 1;
       


       do{
       
          sekundi_edinici = sekundi % 10;
           portd_array[0] = sevenBCD[sekundi_edinici];
           sekundi_desetki = sekundi / 10;
           portd_array[1] = sevenBCD[sekundi_desetki];
           minuti_edinici = minuti % 10;
           portd_array[2] = sevenBCD[minuti_edinici];
           minuti_desetki = minuti / 10;
           portd_array[3] = sevenBCD[minuti_desetki];
           checkButtons(); //gi proveruvame kopcinjata
          // updateDisplay();


       }
       while(1);


}
Regards to all.
And happy holidays.

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: Help with "Not enough RAM 'active_state'" message

#2 Post by IvanJeremic » 23 Jan 2024 13:12

Hi,

Instead of using a string like below:

unsigned int sevenBCD[10] = {
0B0000, //'0'
0B0001, //'1'
0B0010, //'2'
0B0011, //'3'
0B0100, //'4'
0B0101, //'5'
0B0110, //'6'
0B0111, //'7'
0B1000, //'8'
0B1001, //'9'
};

Try using a math function to achieve a similar goal, this will save up a lot of RAM.

Note that the PIC16F84A MCU does not have a lot of RAM to begin with.

Regards,

Ivan.

svasilevski19@gmail.com
Posts: 2
Joined: 20 Jan 2024 16:42

Re: Help with "Not enough RAM 'active_state'" message

#3 Post by svasilevski19@gmail.com » 26 Jan 2024 20:59

IvanJeremic wrote:
23 Jan 2024 13:12
Hi,

Instead of using a string like below:

unsigned int sevenBCD[10] = {
0B0000, //'0'
0B0001, //'1'
0B0010, //'2'
0B0011, //'3'
0B0100, //'4'
0B0101, //'5'
0B0110, //'6'
0B0111, //'7'
0B1000, //'8'
0B1001, //'9'
};

Try using a math function to achieve a similar goal, this will save up a lot of RAM.

Note that the PIC16F84A MCU does not have a lot of RAM to begin with.

Regards,

Ivan.
Thank you very much for the answer.

I used the built in function Dec2Bcd() from MikroC.

Kind regards,
Stefan,

Post Reply

Return to “PIC PRO Compilers”