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

How to read Constant datas From Program Memory????

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



Joined: 24 Jul 2009
Posts: 4

View user's profile Send private message

How to read Constant datas From Program Memory????
PostPosted: Tue Aug 18, 2009 2:01 am     Reply with quote

Dear All

I am using PIC16f887 controller for displaying some constant datas on a LCD display.
Those datas are stored in the program memory.

Am using the following code (which I found in some forum topic).
Also am not sure with pointers wheather am using it correct or not.

When I read am getting only 00 and some junk datas.
I can't find the solution for this.
Can anyone help me on this.

Thanks in advance.
Thanks
Vinoth

Code:

#rom 0X0500={"Initializing"}
byte LCD_DATA

//I want to read the Above Characters From Flash and display it through
//the lcd_write() Function.

void lcd_puts2()
   {
      int buffer[10];
      read_program_memory(0x0500,buffer,4); 
      LCD_DATA=buffer[0];
      lcd_write(LCD_DATA);
      delay_ms(10);
      LCD_DATA=buffer[1];
      lcd_write(LCD_DATA);
      delay_ms(10);     
   }
Ttelmah
Guest







PostPosted: Tue Aug 18, 2009 2:58 am     Reply with quote

Why bother?
Just use 'const'.
Code:

const char init_message[] = {"Initializing"};

void lcd_puts2()
   {
      LCD_DATA=init_message[0];
      lcd_write(LCD_DATA);
      delay_ms(10);
      LCD_DATA=init_message[1];
      lcd_write(LCD_DATA);
      delay_ms(10);     
   }

Using #ROM, has the advantage of not including the 'header' to access the data each time, but will involve you in significant work. The ROM memory on the PIC16, is 14 bits wide, rather than 16 bits wide. Text data, can be packed as two characters per 14bit word, but then needs to be 'dismantled' back to two bytes. If you only store one byte per word, you will waste significant space.
The code you found, was almost certainly being used on a PIC18, where this problem doesn't appear.

Your LCD_DATA declaration, needs a ';'.

Best Wishes
vino_18_2k6



Joined: 24 Jul 2009
Posts: 4

View user's profile Send private message

PostPosted: Wed Aug 19, 2009 12:57 am     Reply with quote

Hi Ttelmah,

thanks For Your Reply.
I Understand Wat U Mean . But I need to Store more than 100 Characters.
it Occupying All My RAm Space. Thats Why I AM Going For Flash memory.

Its Ok I found a different Way of Accesing It thru Directly accessing the Registers and its Working Good.

Code:
#locate EEADR=0X10D
#locate EEADRH=0X10F
#locate EEDATA=0X10C
#locate EEDATAH=0X10E
#locate EECON1=0X18C


void lcd_puts(byte msb,byte lsb)
   {     
      int i;
      EEADR=lsb;
      EEADRH=msb; 
      for(i=0;i<16;i++)
         {
            EEADR=lsb;
            EEADRH=msb;
            EECON1=EECON1|0X01;
            EECON1=EECON1|0X81;
            delay_us(10);
            lcd_write(EEDATA);
            lsb++;
            delay_ms(10);
         }     
   }


Like This...

Thanks For Ur Reply Ttelmah..
vino_18_2k6



Joined: 24 Jul 2009
Posts: 4

View user's profile Send private message

PostPosted: Wed Aug 19, 2009 1:05 am     Reply with quote

Hi Ttelmah

One more yhing... is anything wrong with this code? I am writing some
datas (42 in this case) on EEprom, using the below code to address 0x00.

But after executing there is no data in that place. It is showing only
default (FF) value.

Anything wrong or anything I need to do before this??

Thanks for your reply again.
Code:

void write_eeprm(void)
   {
     write_eeprom(0X00,42);
    delay_ms(10);
    }


Code:
#include <16F887.h>
#device ICD=TRUE
#device adc=10

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC                    //Internal RC Osc
#FUSES NOPUT                    //No Power Up Timer
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPD                    //No EE protection
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOWRT                    //Program memory not write protected
#FUSES BORV40                   //Brownout reset at 4.0V

#use delay(clock=8000000)
Ttelmah
Guest







PostPosted: Wed Aug 19, 2009 2:17 am     Reply with quote

'Const', does not use RAM space. it puts the data in ROM, where you want it, _unless you have selected one of the compiler options to put this data into RAM_. "#device PASS_STRINGS = IN_RAM", will make the constant use RAM, as will ''#device CONST=READ_ONLY". Both of these store copies of the constant into RAM. The default behaviour, is for constants to be put directly into ROM, which is what you want.

How are you testing the EEPROM write?. There are limitations on the ICD, and on most emulator programs about this. I see you have the ICD selected....
If I remember correctly, on some ICD's, the EEPROM window, will not show the updated value, till you do a read from the EEPROM in the code.
A search here will find threads about this.

As a separate comment, I notice your code, does not have the line:

#device *=16

Without this, you only have access to 96 bytes of the chip's RAM, rather than the 368 bytes the chip actually has....

Best Wishes
mbradley



Joined: 11 Jul 2009
Posts: 118
Location: California, USA

View user's profile Send private message Visit poster's website

PostPosted: Sat Aug 29, 2009 1:11 am     Reply with quote

I sometimes do this:


#define MSG_INITIALIZE "Initializing..."

puts(MSG_INITIALIZE);
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