[MOVED]How can I save some RAM space(pic16f72) fro LCD character?

Status
Not open for further replies.

Mithun_K_Das

Advanced Member level 3
Joined
Apr 24, 2010
Messages
899
Helped
24
Reputation
48
Reaction score
26
Trophy points
1,318
Location
Dhaka, Bangladesh, Bangladesh
Activity points
8,254
I was using pic 16f72 for lcd display. showing some words on lcd display. Showing only a few words but RAM goes full. how can I save some RAM space for other purpose?
 

Re: How can I save some RAM space(pic16f72) fro LCD character?

Why do you need to store your text RAM? If you have predetermined messages, those can just reide in ROM, right?
 

Re: How can I save some RAM space(pic16f72) fro LCD character?

What language/compiler are you programming it with?
 

Re: How can I save some RAM space(pic16f72) fro LCD character?

PHP:
I'm using microCpro for pic. 

here is my program:

unsigned int adc_rd0,adc_rd1,adc_rd2;
unsigned char ch,ch1;                    //

// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections

//char * text;
char txt2[3];
char txt3[3];
char txt4[4];
char text0[] ="Inverter";
char text1[] ="ON";
char text2[] ="OFF";
char text3[] ="B-Low!!!";
char text4[] ="Ch";
char text5[] ="Full";
char text6[] ="AC";
//char text7[] ="Low!";
char text8[] ="Overload!";
                      //
long tlong, tlong1;
long clear;
int cnt_inverter,cnt_over, cnt_charge,cnt_charge_clear,cnt_main;
void main()
{
 TRISC = 0xFF; // PORTC all input
 TRISA = 0xFF;
 TRISB = 0b00000001;
 ADCON1 = 0x00;
 Lcd_Init();                        // Initialize LCD
 Lcd_Cmd(_LCD_CLEAR);               // Clear display
 Lcd_Cmd(_LCD_CURSOR_OFF);
 Delay_ms(1000);
 while(1)
 {
  
    // clear LCD
    clear++;
    while(clear<=2)
    {
     Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
     break;
    }
    // main logic sequence...........
    if(RC2_bit==1)// inverter signal available.
    {
     if(RC0_bit==1 || RC1_bit ==1)
     {
      cnt_inverter = 0;
      cnt_over++;
       if(cnt_over<=2)
       {
        clear = 0;
       }
       else
       {
      while(RC0_bit==1)// low bat signal available
      {
       Lcd_Out(2,2,text3); // battery   low
       break;
      }
      while(RC1_bit==1)// overload signal available
      {
       Lcd_Out(2,2,text8); // Overload
       break;
      }
      }
     }
     else // Inverter on
     {
       cnt_over=0;
       cnt_inverter++;
       while(cnt_inverter<=2)
       {
        clear = 0;
        break;
       }

        Lcd_Out(1,1,text0); // inverter
        Lcd_Out(1,10,text1); // on
        
        // Read Battery  voltage  0 to 30V
        ADCON0 = 0b00000001;
        adc_rd2 = ADC_Read(0);        // A/D conversion. Pin RA2 is an input.
        //Lcd_Out(2,8,text);           // Write result in the second line
        tlong1 = (long)adc_rd2 *117.6470588235294; // Convert the result in millivolts
        tlong1 = tlong1;
        ch1 = tlong1/1000;           // Extract volts (thousands of millivolts)
        ch1 = (tlong1 / 10000) % 10;
        Lcd_Out(2,2,"B:");
        Lcd_Chr(2,4,48+ch1);          // Write result in ASCII format
        ch1 = (tlong1 / 1000) % 10;
        Lcd_Chr(2,5,48+ch1);          // Write result in ASCII format
        Lcd_Chr_CP('.');
        ch1 = (tlong1 / 100) % 10;     // Extract hundreds of millivolts
        Lcd_Chr_CP(48+ch1);           // Write result in ASCII format
        ch1 = (tlong1 / 10) % 10;      // Extract tens of millivolts
        Lcd_Chr_CP(48+ch1);           // Write result in ASCII format
        Lcd_Chr_CP('V');
       cnt_main = 0;

     }
    }
    else // inverter signal not available
    {
     cnt_inverter = 0;
     cnt_main++;
        while(cnt_main<=1)
        {
         clear = 0;
         break;
        }
     
     while(RC4_bit==1)// mains on
     {

       
       while(RC3_bit==1 || RC5_bit==1)// either charging or charge full
       {

        
        while(RC3_bit==1) // charging
        {
         Lcd_Out(2,2,text4); // charge
         Lcd_Out(2,5,text1); // on
         //Lcd_Out(2,12,"  "); // on
        cnt_charge++ ;;
        while(cnt_charge<=1)
        {
         clear = 0;
         break;
        }
         break;
        }
        while(RC5_bit==1) // charge full
        {
         cnt_charge=0;
         Lcd_Out(2,2,text4); // charge
         Lcd_Out(2,5,text5); // Full
         break;
        }

        break;
       }


       // show mains here
       Lcd_Out(1,1,text6); // AC
       Lcd_Out(1,4,text1); // on
       
       // read Mains voltage voltage
        ADCON0 = 0b00100001;
        adc_rd0 = ADC_Read(4);        // A/D conversion. Pin RA2 is an input.
        //Lcd_Out(1,1,text);           // Write result in the second line
        tlong = (long)adc_rd0 *19.6078431372549; // Convert the result in millivolts
        tlong = tlong*44/1000;
        ch = tlong;           // Extract volts (thousands of millivolts)
        txt2[0]=(ch/100) +48;
        txt2[1]=((ch/10)%10) +48;
        txt2[2]=((ch/1)%10) +48;
        //txt2[3]=(ch%10) +48;
        txt2[3]=0;
        Lcd_Out(1,8,"AC:");
        Lcd_Out(1,11, txt2);
        Lcd_Chr_CP('V');

     break;
     }
    
    }


  
 } // while

} // void main
 

Re: How can I save some RAM space(pic16f72) fro LCD character?

Declare your string messages as constants - if I recall correctly that will make MikroC put them in ROM:

Code:
const code char *text1="Inverter";

etc...

With only 128 bytes of RAM to play with though, things will always be tight using a high-level compiler instead of assembly.


Edit:
Ahh... there's a catch to that of course - you can't use ROM in functions than need a pointer to RAM, like lcd_out(). So...


You have to copy each text into a RAM location as you need it, something like this:
Code:
const code char text1[] = "Inverter";
const code char text2[] = "ON";
//etc etc

char* ROMtext_to_RAMtext(const char* romtext)
{
  static char text[20]; // set to maximum length of your strings
  char i=0;

  for(i =0; text[i] = romtext[i]; i++);  // or: while(text=romtext[i++]);

  return text;
}


void main()
{

 Lcd_Out(2,2,ROMtext_to_RAMtext(text1);

}

I think... of course this will take extra program memory and uses a little RAM itself, in addition to that needed for temporary storage of the copied text string.
 
Last edited:
Re: How can I save some RAM space(pic16f72) fro LCD character?

But lcd need to be cleared as different words need to be shown in same position. in this case if I use Lcd_Cmd(_LCD_CLEAR); // Clear LCD display command then lcd is cleared but display flickers after a few mins.
 

Re: How can I save some RAM space(pic16f72) fro LCD character?

That's a different issue.

What do you mean by "display flickers after a few mins"? Do you mean it flickers during writing and clearing it?

An easy way to avoid things like that is, if you have the spare memory space, pad all your stored text messages to the same length with spaces. Alternatively, use a string function to display a truncated string of spaces, calculated from the length of the actual text string. That's probably less efficient though, for just a few strings.
 
Re: How can I save some RAM space(pic16f72) fro LCD character?

Thank you foxrrick. display flickers between writing and clearing. if i use same word length then memory doesn't support so much, I can't use so much.

---------- Post added at 07:53 ---------- Previous post was at 07:15 ----------

Its working well....................!!!!!!!!!!!
 

Can you tell me how can I use flash memory to save some data or some sub program to save some RAM space and to add some extra features for LCD? I found some Chinese circuits that is using same MCU but showing a lots of things in LCD which is impossible the way I'm walking. I can't believe how can they add so many features whether I cry to save some RAM/ROM space? Can you tell me what is the best way to utilize a MCU?
 
Last edited:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…