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 CCS Technical Support

[RESOLVED] Not enough RAM for all variables ?

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



Joined: 21 Jul 2017
Posts: 16

View user's profile Send private message

[RESOLVED] Not enough RAM for all variables ?
PostPosted: Wed Aug 02, 2017 3:30 am     Reply with quote

Hi,

When i compile i have this error message.

PIC18F4550 with 16Mhz crystal
CCS version 5.0.15

This message appears when i include file font.h
Code:

#include "font.h"


This file is for driving ili9341 font, the array is biggest, but my question is:

Why does this same program work with mplab-x, does mplab-x optimize arrays?

When i use #device *=16, I have a same error.

main.h
Code:

#include <18F4550.h>
#device *=16
#device ADC=16


#FUSES NOWDT                    //No Watch Dog Timer
//#FUSES HSPLL
//#FUSES CPUDIV1
//#FUSES PLL4   
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV21                   //Brownout reset at 2.1V
#FUSES VREGEN                   //USB voltage regulator enabled
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTC                   //Configuration registers not write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads

#use delay(crystal=16Mhz,clock=16Mhz)


Any idea ?


Last edited by andromeda92 on Wed Aug 02, 2017 11:21 am; edited 2 times in total
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Wed Aug 02, 2017 4:18 am     Reply with quote

How is the font defined?

I define my fonts as

Code:
const unsigned int8 font7x5[99][5] =
{
// char 32 == ' '
0x00, 0x00, 0x00, 0x00, 0x00,


etc...


const puts it in ROM instead of (ROM which is copied to RAM)
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Wed Aug 02, 2017 4:26 am     Reply with quote

#=16, makes no difference at all on a PIC18 or above chip.

Declare the font as const. Then it'll be stored in ROM.

You keep talking about MPLAB as if it is a language. It isn't. MPLAB is an IDE, inside which you can be running quite a few different languages and variants (including CCS...). I'd suspect that the declaration you have (not shown) in 'font.h', results in the compiler being used (XC8 possibly), in storing the table in ROM.
andromeda92



Joined: 21 Jul 2017
Posts: 16

View user's profile Send private message

PostPosted: Wed Aug 02, 2017 7:56 am     Reply with quote

Yes you have right the array was defined as a const but i deleted keywork
const because i have this error:

attempt to create a pointer to a constant.

font.h
Code:

unsigned char Courier_New_Bold_20[] = {
/****************************************
 * Font header
 ****************************************/
    0x00,           // Information
    0x00,           // ID
    0x20, 0x00,     // First Character
    0x7E, 0x00,     // Last Character
    0x17,           // Height
    0x00,           // Reserved


But if i add const
Code:

const unsigned char Courier_New_Bold_20[] = {
/****************************************
 * Font header
 ****************************************/
    0x00,           // Information
    0x00,           // ID
    0x20, 0x00,     // First Character
    0x7E, 0x00,     // Last Character
    0x17,           // Height
    0x00,           // Reserved


the code below display the error message

TFT_SetFont(Courier_New_Bold_20, 1); <= error attempt to create a pointer to a constant


Code:

void TFT_SetFont(char *font_, char letterspacing)
{
   font2 = font_;
   letter_spacing = letterspacing;
   height = TFT_CharHeight();
}


Original code for mplab-x is
Code:

typedef const unsigned char      CUchar;
typedef unsigned char            Uchar;


const unsigned char Courier_New_Bold_20[] = {
/****************************************
 * Font header
 ****************************************/
    0x00,           // Information
    0x00,           // ID
    0x20, 0x00,     // First Character
    0x7E, 0x00,     // Last Character
    0x17,           // Height
    0x00,           // Reserved
........

void TFT_SetFont(CUchar *font_, Uchar letterspacing){
font2 = font_;
letter_spacing = letterspacing;
height = TFT_CharHeight();
}


But in CCS char is unsigned char.

If i changed code for CCS:
Code:

void TFT_SetFont(const unsigned int8 *font_, char letterspacing);

void TFT_SetFont(const unsigned int8*font_, char letterspacing){
font2 = font_;
letter_spacing = letterspacing;
height = TFT_CharHeight();
}

TFT_SetFont(Courier_New_Bold_20, 1); <= i have now plenty error   message

The keyword const don't work in CCS, if i declare a function with keyword const, i have plenty error.
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Wed Aug 02, 2017 8:04 am     Reply with quote

Put back const.
Otherwise you are trying to put the whole font pointlessly into RAM....

Then add at the top of your code (after the processor include, but before anything else):

#DEVICE PASS_STRINGS=IN_RAM

This is a standard setting that is needed if you want to use any const with pointers.

Start with some basic code and learn the language, instead of expecting us to translate everything for you.
andromeda92



Joined: 21 Jul 2017
Posts: 16

View user's profile Send private message

PostPosted: Wed Aug 02, 2017 10:33 am     Reply with quote

I translated correctly the program for ccs, so for the constant works I was forced to put #device CONST = ROM.

I also put the clock at 48Mhz because I have timmings problems, for example the screen that turned white or time was erroneous, for example delay_ms (200) was 1 second.

Thanks for your help.
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Thu Aug 03, 2017 1:44 am     Reply with quote

Since CONST=ROM, is the default CCS behaviour, implies you were turning this off at some point....
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