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

(write / read _program_memory) in 18f2550

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



Joined: 08 Aug 2009
Posts: 3

View user's profile Send private message

(write / read _program_memory) in 18f2550
PostPosted: Sat Aug 08, 2009 11:01 am     Reply with quote

I have a problem with the function Write_program_memory and Read_program_memory, I do not know how to use this function and I need to write into the flash memory of pic18f2550.

When compiling the code in CCS, this gives no errors, the problem is to simulate in Proteus 7.2. Also present problems in hardware.

This is the code in CCS:
Code:

#include "yy.h"
#include <lcd.c>
#fuses NOWDT,HS, NOPROTECT,NOBROWNOUT, NOPUT, NOLVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB
#use delay(clock=4000000)

void main()
{
   int16 write_data, read_data;

   lcd_init();
   setup_adc_ports(NO_ANALOGS);

   write_data = 0x55;
   write_program_memory(0x4000, write_data, 2);
   delay_ms(100);

   read_program_memory(0x4000, read_data, 2);
   printf(lcd_putc,"%2X ", read_data);
}

I want you to help me in my problem.

I very much appreciate your help.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 08, 2009 11:18 am     Reply with quote

Your middle parameter is wrong in both function calls. Read the CCS
manual. It says the middle parameter must be a pointer:
Quote:

write_program_memory( )

Syntax: write_program_memory( address, dataptr, count );

Parameters:
address is 16 bits on PCM parts and 32 bits on PCH parts.
dataptr is a pointer to one or more bytes
count is a 8 bit integer



read_program_memory( )

Syntax: read_program_memory (address, dataptr, count );
Parameters:

address is 16 bits on PCM parts and 32 bits on PCH parts. The least
significant bit should always be 0 in PCM.
dataptr is a pointer to one or more bytes.
count is a 8 bit integer
Deark



Joined: 08 Aug 2009
Posts: 3

View user's profile Send private message

PostPosted: Sat Aug 08, 2009 11:59 am     Reply with quote

Can you give me an example of use of function Write / read program_memory? please.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 08, 2009 12:18 pm     Reply with quote

You need to study the C language and learn how to create a pointer
to an integer variable. It's done by pre-fixing the variable name with
an Ampersand (&) character. Example:
Quote:
write_program_memory(0x4000, &write_data, 2);

read_program_memory(0x4000, &read_data, 2);
Deark



Joined: 08 Aug 2009
Posts: 3

View user's profile Send private message

PostPosted: Sat Aug 08, 2009 3:47 pm     Reply with quote

Thank you very much! Now we have no errors in the Proteus 7.2 simulator .

We know that pointers are a variable that save memory address of other variable. Can how this help us?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 08, 2009 7:39 pm     Reply with quote

I'm not sure what you are asking. Do you need any other help ?
Ttelmah
Guest







PostPosted: Sun Aug 09, 2009 2:28 am     Reply with quote

Deark wrote:
Thank you very much! Now we have no errors in the Proteus 7.2 simulator .

We know that pointers are a variable that save memory address of other variable. Can how this help us?


Not quite.

A pointer, _is_ the address of a variable.

You can have variables that are themselves pointers, and use these to contain the addresses of variables. However in this case, you don't need the variable.

If you look at the manual entry for the read and write functions, the second entry, _needs_ to be the address in memory (pointer) to where you want to store the value.

The '&' operation, returns the pointer 'to' a variable, which is what the functions need. You could perfectly well declare a pointer variable, and put the address into this, but you don't need to. What you need to do, is pass the address to the function. Nothing more.
The functions need to know 'where' to put the data, hence they need the address.

Best Wishes
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