PDA

View Full Version : Writing To Eeprom



Srigopal007
- 22nd December 2004, 18:05
Hello Everyone, I have a quick question I wanted to address. I have searched for keywords in the search menu but did not get the results I wanted for my question. I also looked in the PBP manual but only got a partial answer to it.

My question is about the READ and WRITE FUNCTIONs. I am using a PIC 18F series that has ON-BOARD EEPROM. Will the WRITE and READ command work for the 18F series microcontrollers?

I have 1024 byte of EEPROM space available for the 18F device. And how do I konw what address the PIC micro is writing or reading to when I include these commands into my CODE?
How do I konw where the Addressing starts in my PIC micro?


thanks in advance for answering these questions.

srig

Srigopal007
- 22nd December 2004, 18:07
Oops I forgot .. I will be using 20Mhz quartz crystal oscillator. Not sure if I need to define the OSC on top of my CODE

OSC 20 into my code

thelightbrain
- 22nd December 2004, 19:14
You need to download the datasheet for your processor from Microchip. Then you need to read the section on EEPROM data memory.
This will explain how the 1K of memory is addressed.

The write command should work fine but probably can only access the first 256 bytes.

I use assembly subroutines to allow access to the full 1K memory. The datasheet shows exactly how to do this in assembly. I am using the PIC18F2525.

-Jim

mister_e
- 22nd December 2004, 19:30
Hi srig,

Actualy you don't need to know at wich address you write to internal EEPROM, PBP handle it.

You must define OSC 20... always


The following will write and read on internal EEPROM. And display on LCD.





' Code to Read/Write to Internal EEPROM
' =====================================
'
' File name : InternalEEPROM.bas
' Company : Mister E
' Programmer : Steve Monfette
' Date : 22-12-2004
' Device : PIC18f452-I/P
'
'
'
' Device programming mode and hardware definition
' ===============================================
'
'
'
@ __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HS_OSC_1H
' Oscillator switch OFF
' Use HS oscillator (20MHZ here)
'
@ __CONFIG _CONFIG2L, _BOR_ON_2L & _PWRT_ON_2L & _BORV_45_2L
' Brown out reset ON @ 4.5Volts
' Power-up timer ON
'
@ __CONFIG _CONFIG2H, _WDT_ON_2H
' Watch dog timer ON
'
@ __CONFIG _CONFIG4L, _STVR_ON_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
' Stack over/underflow ON
' Low Voltage programming OFF
' Background debugger OFF
'
define OSC 20 'Use of 20 MHZ crystal
' Lcd defines
' ===========
' BO-B3 : Data port (pin 33-36)
' B4 : Rs Bit (pin 37)
' B5 : E Bit (pin 38)
'
'
'
define LCD_DREG PORTB ' Set data pin of LCD to
define LCD_DBIT 0 ' PORTB.0-PORTB.3
define LCD_RSREG PORTB ' Set RS bit of LCD to
define LCD_RSBIT 4 ' PORTB.4
define LCD_EREG PORTB ' Set E bit of LCD to
define LCD_EBIT 5 ' PORTB.5
DEFINE LCD_LINES 4 ' 4 Lines LCD
define LCD_COMMANDUS 2000 ' Command delay time in uSec
DEFINE LCD_DATAUS 50 ' Data delay time in uSec
'
'
'
' Variable definition
' ===================
'
'
'
Addr var Byte
ToStore var byte
ToRead var byte
'
'
' Let's begin
' ===========
'
PAUSE 500 ' waiting for LCD Start up

' Writing to internal EEPROM
' ==========================
'
For addr=0 to 10
Tostore = 10+addr
write Addr, tostore
next
'
' Reading from internal EEPROM
' ============================
'
For addr=0 to 10
read addr,Toread
lcdout $FE,1,"Address : ",dec addr,_
$FE,$C0,"Data : ",dec ToRead
Pause 1000 ' wait 1 sec between each display
next
Here:goto here

mister_e
- 22nd December 2004, 20:18
But for full access 1024 bytes... i cannot test it for now... i don't have any of those PIC. Probably define Addr as WORD could work... let me know.

mister_e
- 25th December 2004, 01:08
It's also working for 1024 BYTES too following code is working


'Use of PIC18F2525
@ __CONFIG _CONFIG1H, _OSC_HS_1H & _FCMEN_ON_1H & _IESO_OFF_1H
' Use HS oscillator (20MHZ)
' Fail Safe Clock Monitor ON
' Internal/External switch over mode OFF
'
@ __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOREN_ON_2L & _BORV_45_2L
' Power-up timer ON
' Brown out detect ON
' brown out detect voltage 4.5 Volts
'
@ __CONFIG _CONFIG2H, _WDT_ON_2H
' Watch dog timer ON
'
@ __CONFIG _CONFIG3H, _MCLRE_ON_3H & _PBADEN_OFF_3H
' MCLR pin enable
' PORTB<4:0> digital on RESET
'



@ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _DEBUG_OFF_4L & _ENHCPU_OFF_4L
' stack overflow ON
' Low Voltage programming OFF
' Debug OFF
' extended CPU OFF
ToStore var byte
Addr var word

start:
for addr=0 to 1024
tostore=addr.lowbyte
write addr,tostore
next
here: goto here