PDA

View Full Version : PIC12F683 and EEPROM



ross246
- 19th November 2010, 16:39
Hi everyone,

I have a PIC12F683 which communicates via serin/serout and I want it to be able to store an 8 digit number into eeprom. I have searched and searched and I can't find any basic examples on how I can read write something like for example "47364837" sent over serial port to eeprom. Can anyone point me in the right direction please. Just thought it would be a fun project to help me learn :)

Thanks,
Ross

Edit: I probably should have put this under Picbasc Pro forum - doh. My brain is fried from googling this issue. Sorry

ross246
- 19th November 2010, 17:30
Ok figured out the EEPROM thing kind of - works fine when working with a single digit :) Just need to know how I can store a string of numbers and then return it on demand. Code so far:


Include "modedefs.bas"

OSCCON = %01100000 'set for 4mhz internal
CMCON0 = 7 'TURN COMPARITORS OFF
ANSEL = %00000000 'Set A/D OFF
ADCON0 = %00000000 'Analog converter OFF
TRISIO = %00000000 'Set GSIO 4 and 2 to INPUT, others to OUTPUT

tcx var GPIO.0 'output pin
rcx var GPIO.1 'input pin
led VAR GPIO.5
cmd VAR byte
x VAR BYTE

Main:
serin rcx,n2400,cmd
If cmd = "0" THEN GOTO SetNum
If cmd = "1" THEN GOTO RetNum
GOTO Main

setNum:
serin rcx,n2400,x
WRITE 2, x
GOTO Main

RetNum:
READ 2, x
SEROUT tcx,n2400,[x]
goto main

LinkMTech
- 19th November 2010, 19:17
I know there are more elegent ways of doing this but as a starting point to learn I would suggest this:
Each byte received needs to have somewhere to go like the first character you did so make some more variables for the rest.


X0 VAR BYTE
....
X7 VAR BYTE

setnum:
SERIN rcx,n2400,X0,X1,X2,X3,X4,X5,X6,X7
WRITE 2, X0 ' Remember this takes some time, about 10ms ea
WRITE 3, X1
...
WRITE 9, X7
GOTO main

RetNum:
READ 2, X0
READ 3, X1
...
READ 9, X7
SEROUT tcx,n2400,[x0,X1,X2,X3,X4,X5,X6,X7]
goto main.


I haven't tested this but I hope you get the idea.