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

Migrating PIC16F876A to the PIC16F1938!

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



Joined: 01 Aug 2011
Posts: 26
Location: BRAZIL

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

Migrating PIC16F876A to the PIC16F1938!
PostPosted: Mon May 28, 2012 6:02 am     Reply with quote

Good morning everyone.

I'm upgrading PIC16F876A to the PIC16F1938 to use the internal oscillator.
I have many problems with crystals due to mechanical vibration.

I am having trouble migrating the internal eeprom routines.
In PIC16F876A I use #ROM 2100, 2110, and so on.
In PIC18F452 I use #ROM F00000, F00010, and so on.
And the PIC16F1938, how should I proceed in CCS?

I do not know how to initialize the Internal EEPROM in PIC16F1938.

Someone might be giving any hints or help!

Thank you.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Mon May 28, 2012 7:15 am     Reply with quote

According to the CCS manual getenv("EEPROM_ADDRESS") should return the start address of data eeprom on all PICs. Zero if the PIC doesn't have data eeprom.

getenv() is a not a "normal" function as it returns its (constant) result at compile time, not run time, so it can be used to in #define, #rom and so on. All the values it can give you are documented in the manual.

RF Developer
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon May 28, 2012 7:21 am     Reply with quote

..
_________________
Google and Forum Search are some of your best tools!!!!


Last edited by dyeatman on Mon May 28, 2012 2:58 pm; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Mon May 28, 2012 7:48 am     Reply with quote

dyeatman wrote:
The PIC datasheet specifically says the EEPROM is NOT mapped to a
register file. I don't have the chip but I would first try write_eeprom()
and read_eeprom().

If those didn't work I would write my own functions. Sections 11.2.1 and
11.2.2 are pretty straight forward and provide the info required.

Below is an outline of the steps for your own functions.

Globally define the following:
1. EEADRL, EEDATL and EECON2 registers
2. CFGS, EEPGD, WR, WREN, EEIF and RD bits

To read:
1. write the desired address to EEADRL
2. Clear EEPGD and CFGS
3. set RD then read and return EEDATL for the data


To write:
1. put the desired address in EEADRL
2. put the data to wqrite in EEDATL
3. clear CFGS, EEPGD
4. set the WREN bit
5. disable interrupts
6. write 0x55 to EECON2
7. write 0xAA to EECON2
8. set the WR bit to start the write
9. enable interrupts
10. loop and wait for WR to be cleared.


Whoa.

The EEPROM is not mapped to a 'register file' in any PIC. However the chips are setup, so that when being _programmed_, the EEPROM contents appear as an extension to the ROM memory usually above even the fuses. This is in the _programming specification_ sheet for the chip.
The answer from RF_Developer is right, with the CCS getenv function 'telling' the compiler where this is, so you can put data into the EEPROM at programming time.

The description you give of how to write and read the EEPROM, is all done for you by the CCS runtime functions. Re-inventing the wheel is rather pointless.

If you go to the devices 'full page' (harder to find since MicroChip redesigned their site):

<http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en538157>

Then pull the 'programming specification', section 7.3, gives the answer as:

"The physical address range of the 256 data memory is
0000h-00FFh. However, these addresses are logically
mapped to address 1E000h-1E1FFh in the hex file."

so, either use the getenv form (which should find the address for you), or use:

#ROM 0x1E000 etc..

Best Wishes
hugo_br



Joined: 01 Aug 2011
Posts: 26
Location: BRAZIL

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

PostPosted: Mon May 28, 2012 8:12 am     Reply with quote

Good morning.

I've found an easier method of finding the data processor.

I was on "VIEW" -> "Special Registers = Device Table Editor" -> "MCU Parts" -> "Memory" -> "Data EE Start" -> "F000"

With this I can see all information from all available processors by CCS.

I tried using "# 0x1E000 ROM" but failed. Writes random numbers.

With the "ROM # 0xF000" so far is working properly.

I appreciate everyone's attention!!

Thank you!
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Mon May 28, 2012 8:26 am     Reply with quote

The getenv version should supply the F000 address. Remember the difference between words and bytes (what is 1E000/2?)....
Realistically the getenv route is the best, since you can just move between processors _without_ having to worry where the stuff is stored.

Best Wishes
hugo_br



Joined: 01 Aug 2011
Posts: 26
Location: BRAZIL

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

PostPosted: Mon May 28, 2012 8:33 am     Reply with quote

Ttelmah wrote:
The getenv version should supply the F000 address. Remember the difference between words and bytes (what is 1E000/2?)....
Realistically the getenv route is the best, since you can just move between processors _without_ having to worry where the stuff is stored.

Best Wishes


Ttelmah cool this tip, I'll start to use in future projects. This is a function which never used .... What about the address had forgotten to divide by 2!!

Thanks for the tips.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Mon May 28, 2012 8:59 am     Reply with quote

It is one of those little 'oddities'. The addresses used in the hex file, are twice the actual program 'word' address (since it stores the values as bytes). The 'byte' address for the EEPROM is 1E000, but I forgot to convert this to a 'word' address when posting it. ;)

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