PDA

View Full Version : 12f629 Eeprom



BGreen
- 8th May 2007, 18:09
I have never used EEPROM before and am confusing the **** out of myself reading the data sheet. All I'm trying to do is save and read a couple of variables. One will range from 0-6 while th other would be a 0 or 1. If anyone has a simple code example I would really appriciate the help.

mister_e
- 8th May 2007, 18:26
There's many ways, but assuming the PBP statements and you want to do it at run-time without having default value in the EEPROM, you need to use WRITE and READ.

BGreen
- 8th May 2007, 18:40
Steve that was what I was trying with Write address, value. Maybe I'm confusing myself with the address. On page 49 of the data sheet it also gave a list of requirements and I was getting syntax errors. What I'm trying to do is increment a value using a button and write it to EEPROM and be able to read it.

mister_e
- 8th May 2007, 19:05
O.K. the 12F629 have 128 bytes of EEPROM, so the address range is between 0 and 127. PBP WRITE handle the PIC address for you.

try this

<font color="#000000"> <font color="#008000">'
' Pic Configuration
' =================
</font>@ __CONFIG _INTRC_OSC_NOCLKOUT &amp; _WDT_ON &amp; _PWRTE_ON &amp; _MCLRE_OFF &amp; _BODEN_ON

<font color="#008000">'
' Hardware configuration
' ======================
'
' I/Os
' ----
</font>TRISIO = %11111110 <font color="#008000">' GP0 As output, others TO input

'
' Comparator
' ----------
</font>CMCON = 7 <font color="#008000">' Disable comparator

'
' Hardware assignment
' ===================
'
' User control
' ------------
</font>PB1 <font color="#000080">VAR </font>GPIO.1
LED <font color="#000080">VAR </font>GPIO.0

<font color="#008000">'
' Software variables
' ==================
</font>AddressCounter <font color="#000080">VAR BYTE

</font><font color="#008000">'
' Software/Hardware initialisation
' ================================
</font>AddressCounter = 0
LED = 0
<font color="#000080">PAUSE </font>100 <font color="#008000">' osc settle time


'------------------------------&lt; Main program &gt;-----------------------------------
'
</font>Start:
<font color="#000080">WHILE </font>AddressCounter!=128
<font color="#000080">IF </font>PB1 = 1 <font color="#000080">THEN
WRITE </font>AddressCounter,AddressCounter
LED = 1
<font color="#000080">WHILE </font>PB1 : <font color="#000080">WEND
PAUSE </font>100
LED = 0
AddressCounter = AddressCounter + 1
<font color="#000080">ENDIF
WEND
</font>LED = 1

SpinHere:
<font color="#000080">GOTO </font>SpinHere
<font color="#008000">'
'---------------------------------------------------------------------------------
</font>

Each time you'll press on the push-button attach to gpio.1, it will write to the EEPROM. Once the EEPROM is full, the LED will stay ON.

Once done, if i read the pic, the EEPROM show...
<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1609&stc=1&d=1178647515">

Sucessfull!

BGreen
- 8th May 2007, 19:12
Thank you Steve. Let me see where I can go from here.

BGreen
- 9th May 2007, 19:47
Thanks again Steve. It was the address that had me confused and your example cleared it up for me.

Butch