I have a C project that contains a function that prints out string literals to an LCD. The problem is that every time print function is called the ram utilization (according to the console) increases by the number of bytes in the string. It seems that when literals are passed to the function they are stored in RAM. When passing the function a pointer to a const char[ ] the same thing happens. As it currently stands the program is burning through RAM. Is there a way to stop the compiler from wasting RAM when passing strings?
const char t1[]="Random Text";
int main(void) {
char i;
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
LCD_Init();
LCD_Print("Text 1"); //RAM use 88 7 chars
LCD_Print("Text 2"); //RAM use 96 14 chars
LCD_Print("Text 3"); //RAM use 104 21 chars
i=t1[0]; //RAM use 104
LCD_Print(t1); //RAM use 116 33 chars
while(1);
return 0;
}
From the map file t1 is stored in flash at 0000c1fc. However, passing it to the print function consumes 12 bytes of RAM, according to the console. I am under the impression that passing an array in C is the same as passing a pointer to the first element of the array; so I do not see where the 12 bytes of RAM are being used.
The Program is posted below
----------------------------------------------Main File-------------------------------------------------------
#include <msp430.h>
#include "EZ_LCD.h"
void Clock_Config();
const char t1[]="Random Text";
int main(void) {
char i;
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
void Clock_Config();
LCD_Init();
LCD_Print("Text 1"); //RAM use 88 7 chars
LCD_Print("Text 2"); //RAM use 96 14 chars
LCD_Print("Text 3"); //RAM use 104 21 chars
i=t1[0]; //RAM use 104
LCD_Print(t1); //RAM use 116 33 chars
while(1);
return 0;
}
void Clock_Config(){
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ; // DCO clock is set at 1 MHz
BCSCTL2 =0x06; // MCLK=DCO/0 SMLCK=DCO/8
BCSCTL3 = XCAP_3; //set crystal capacitance to 12.5pF
}
---------------------------------------------------EZ_LCD------------------------------------------------
#include <msp430.h>
void LCD_W(int Nibble); //private translates hex command into bit commands
void LCD_WB(int Byte); //private writes byte to data register
void LCD_Print(char Text[]);
void LCD_Print(char Text[])
{
int F_TMP=0;
while (Text[F_TMP] != 0x00) //0x00 is the null charecter used to signal end of string
{
LCD_WB(Text[F_TMP]);
F_TMP++;
}
}
void LCD_W(int Nibble)
{
if ((Nibble & 0x8)==0) {P2OUT &= ~ EZLCD_DB3;}//isolate DB3
else {P2OUT |= EZLCD_DB3;}
if ((Nibble & 0x4)==0) {P2OUT &= ~ EZLCD_DB2;}//isolate DB3
else {P2OUT |= EZLCD_DB2;}
if ((Nibble & 0x2)==0) {P2OUT &= ~ EZLCD_DB1;}//isolate DB3
else {P2OUT |= EZLCD_DB1;}
if ((Nibble & 0x1)==0) {P1OUT &= ~ EZLCD_DB0;}//isolate DB3
else {P1OUT|= EZLCD_DB0;}
P1OUT &= ~ EZLCD_EN;
P1OUT |= EZLCD_EN;
P1OUT &= ~ EZLCD_EN;
}
void LCD_WB(int Byte)
{
_delay_cycles(LCD_Delay_M);
P1OUT |= EZLCD_RS;
LCD_W((Byte & 0xF0) >> 4); //masks bytes upper nibble
_delay_cycles(LCD_Delay_M);
LCD_W(Byte & 0x0F); //masks bytes lower nibble
}
CCS 6.1
Windows 7 x64
MSP430G2533