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_configuration_memory() with PCM ?

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



Joined: 05 Aug 2006
Posts: 149
Location: Redditch, UK

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

How to read_configuration_memory() with PCM ?
PostPosted: Thu Jul 21, 2011 8:38 am     Reply with quote

CCS PCM C Compiler, Version 4.122
The CCS help suggests the read_configuration_memory() function will only work with pic18s and does not work on pic16s. Fair enough, indeed you get a compiler error if you try.

However the 12F1822 has the ability to read/writes its User ID's config memory (8000h->8003h) according to the data sheet.

Is there a CCS way to read/write the user id on the 12F1822 Question

I tried setting it with ID Memory feature of MPLAB and reading back on the pic with read_program_memory() but that does not seem to work.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 22, 2011 4:42 pm     Reply with quote

Look in the CCS manual at this function:
Quote:

read_configuration_memory( )

I haven't tested this.
nurquhar



Joined: 05 Aug 2006
Posts: 149
Location: Redditch, UK

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

PostPosted: Sat Jul 23, 2011 12:25 am     Reply with quote

I tried read_configuration_memory(), but compiler refused it. The manual says its only for PIC18's. I have the PIC12F1822.

I did also just try read_program_eeprom() address 0x8000 but that did not work either. Looking at the .lst file and section 11.5 of parts datasheet it seems CFGS has to be set in EECON1 (bit6). And CCS (PCM) is not doing that. Are we missing a feature from CCS ?

I guess I will have to hunt out a Flash read/write procedure and modifiy it to set the CFGS flag as required. Got any recommemndations for a nice CCS procedure with inline #ASM ?
nurquhar



Joined: 05 Aug 2006
Posts: 149
Location: Redditch, UK

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

PostPosted: Sat Jul 23, 2011 2:32 am     Reply with quote

I just whipped this up using CCS after referencing the 12F1822 datasheet section 11.5 and it seems to work. Except in my test prog my printf is putting out <0> instead the string I had coded. I will have to look at this as I am concerned that my read procedure could be corrupting something Exclamation

Code:
#ifndef _CONFIGMEM_H
#define _CONFIGMEM_H

#byte   EEADRL = getenv("SFR:EEADRL")
#byte   EEADRH = getenv("SFR:EEADRH")
#byte   EEDATL = getenv("SFR:EEDATL")
#byte   EEDATH = getenv("SFR:EEDATH")

#byte   EECON1 = getenv("SFR:EECON1")
#bit   CFGS = getenv("bit:CFGS")
#bit   RD = getenv("bit:RD")

#byte   EECON2 = getenv("SFR:EECON2")

#byte   INTCON = getenv("SFR:INTCON")
#bit   GIE = getenv("bit:GIE")


// Read config memory, address is an offeset to the 0x8000 base in the PIC
uint8 read_config_memory(uint8 address)
{
   int1 ie ;

   ie = GIE ;
   EEADRL = address ;
   EEADRH = 0 ;
   CFGS = 1 ;
   GIE = 0 ;
   RD = 1 ;
   #asm
   nop
   nop
   #endasm
   GIE = ie ;
   return(EEDATL) ;
}

#endif
nurquhar



Joined: 05 Aug 2006
Posts: 149
Location: Redditch, UK

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

PostPosted: Tue Jul 26, 2011 5:43 am     Reply with quote

CCS does seem to have any functions to read/write the config memory for the 12F1822, 16F1823, 12F1840 etc .

I have just test this set of functions on the PIC12F1822 and all seems well.

enjoy .....

Code:
#ifndef _CONFIGMEM_H
#define _CONFIGMEM_H

#byte   EEADRL = getenv("SFR:EEADRL")
#byte   EEADRH = getenv("SFR:EEADRH")
#byte   EEDATL = getenv("SFR:EEDATL")
#byte   EEDATH = getenv("SFR:EEDATH")

#byte   EECON1 = getenv("SFR:EECON1")
#bit   EEPGD = getenv("bit:EEPGD")
#bit   CFGS = getenv("bit:CFGS")
#bit   LWLO = getenv("bit:LWLO")
#bit   FREE = getenv("bit:FREE")
#bit   WRERR = getenv("bit:WRERR")
#bit   WREN = getenv("bit:WREN")
#bit   RD = getenv("bit:RD")
#bit   WR = getenv("bit:WR")

#byte   EECON2 = getenv("SFR:EECON2")

#byte   INTCON = getenv("SFR:INTCON")
#bit   GIE = getenv("bit:GIE")


// Read config memory, address is an offeset to the 0x8000 base
// .... User ID values are 12 bit values
uint16 read_config_memory(uint8 address)
{
   int1 ie ;

   EEADRL = address ;
   EEADRH = 0 ;

   ie = GIE ;

   CFGS = 1 ;
   GIE = 0 ;
   RD = 1 ;
   #asm
   nop
   nop
   #endasm
   CFGS = 0 ;
   GIE = ie ;
   return(make16(EEDATH,EEDATL)) ;
}

// Write the USER ID memory locations 8000-8003, all other locations are R/O
// ... Clear all user id's locations first with earse_config_memory()
void write_config_memory(uint8 address, uint16 val)
{
   int1 ie ;

   EEDATL = make8(val,0) ;
   EEDATH = make8(val,1) ;
   EEADRL = address ;
   EEADRH = 0 ;

   ie = GIE ;

   FREE = 0 ;
   CFGS = 1 ;
   WREN = 1 ;
   GIE = 0 ;
   EECON2 = 0x55 ;
   EECON2 = 0xAA ;
   WR = 1 ;
   while(WR == 1) ;
   WREN = 0 ;
   CFGS = 0 ;
   GIE = ie ;
}


// Erase the USER ID memory locations 8000-8003, all other locations are R/O
void erase_config_memory()
{
   int1 ie ;

   EEDATL = 0 ;
   ie = GIE ;
   EEADRL = 0 ;
   EEADRH = 0 ;
   FREE = 1 ;
   CFGS = 1 ;
   WREN = 1 ;
   GIE = 0 ;
   EECON2 = 0x55 ;
   EECON2 = 0xAA ;
   WR = 1 ;
   while(WR == 1) ;
   WREN = 0 ;
   CFGS = 0 ;
   GIE = ie ;
}


#endif
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