Shop OBEX P1 Docs P2 Docs Learn Events
24C01 EEPROM Programmer — Parallax Forums

24C01 EEPROM Programmer

cesamcesam Posts: 4
edited 2006-03-02 10:47 in Robotics
· I got·BOT with BS2 from parallax's Hong Kong distributer few years ago.· Currently, i am working on one home project that need to work with 24C01/24C01A eeprom as a kind of backup device.· At the program debug stage, i have some trouble if i want to take a look what kind of data are put inside eeprom.· As a result, i come out an idea make use of my BS2 to be my 24C01 programmer and eeprom display device.
· Since BS2 dont support I2C, so i need to buit my sub-program for I2C.· Eventaully the home program is finished and this eeprom programmer is work quite well for me, that is the reason why i want to send to Parallax and share with other user who also have BOE-BS2 in their hand!
· The hardware is very simple, i just make use of the 'X1' slot to connect my own PCB on top of it with the IC socket (for the eeprom) and LED (for error display purpose).· You can also make use of the bread board area for the connection too.
· This program receive commend from serial terminal or debug terminal.· eeprom data can be prestore in BS2 during upload stage.· eeprom can also be backup in BS2 or display on the screen for debug purpose.· eeprom is powered by one of the pin in BS2 during rw/wrt process and it can be turn off when the process is finished in order to take out the eeprom from the socket!
· Here is the code of my program.· The program it-self is not complex, but it save a long of time for those who has this kind of needs during project development.
· If any peope feel happy with my small stuff, i will feel happy if you can send me an email.
sam

' {$STAMP BS2}
' {$PBASIC 2.5}
' 24C01/24C01A eeprom programing
' make use of page write and sequential read
'#DEFINE _24C01A
eeprom_size CON 128· ' 128 x 8· = 1k Bits
size CON 8
' *** eeprom data is here ***
'DATA $FF (128)
' or
'DATA $0 (128)
' or
DATA $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
DATA $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
DATA $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
DATA $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
DATA $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
DATA $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
DATA $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
DATA $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
' *** end ***
baud CON 84· 'baud rate = 9600-8-N-1

A·· VAR Byte
r0· VAR Nib
r1· VAR Byte
r2· VAR Byte
vcc PIN 7· ' eeprom is power on/off by BS2
scl PIN 3· ' SCL pin pull up with 10k to +5V
sda PIN 1· ' ditto for SDA pin
LED PIN 6· ' LED, active low
'sw· PIN 2
OUTPUT scl
OUTPUT sda
'INPUT sw
start:
· LOW vcc
· HIGH led
· DO
· #IF _24C01A #THEN
··· SEROUT 16,baud,[noparse][[/noparse]LF,CR,
··················· "24C01A",LF,CR]
··· #ELSE
··· SEROUT 16,baud,[noparse][[/noparse]LF,CR,
··················· "24C01",LF,CR]
··· #ENDIF
··· SEROUT 16,baud,[noparse][[/noparse]"1- Copy, BS2 > eeprom",LF,CR,
··················· "2- Backup, eeprom > BS2",LF,CR,
··················· "3- Display eeprom",LF,CR,
··················· "4- Display BS2",LF,CR]
··· SERIN 16,baud,[noparse][[/noparse]r2]
'main:
'··· IF sw=1 THEN main
'release:
'··· IF sw=0 THEN release
··· SELECT r2
····· CASE "1"·· ' copy BS2 > eeprom
········ HIGH vcc
········ GOSUB I2C_start
········ #IF _24C01A #THEN
··········· A=%10100000
··········· GOSUB I2C_out
··········· GOSUB I2C_ack
········ #ENDIF
········ A=0
········ GOSUB I2C_out
········ GOSUB I2c_ack
········ FOR r2=0 TO eeprom_size-1
··········· #IF _24C01A #THEN
·············· A=r2//8
·············· IF A=0 THEN
················· GOSUB I2C_stop
················· GOSUB I2C_start
················· A=%10100000
················· GOSUB I2C_out
················· GOSUB I2C_ack
················· A=r2
················· GOSUB I2C_out
················· GOSUB I2C_ack
·············· ENDIF
··········· #ELSE
·············· A=r2//4
·············· IF A=0 THEN
················· GOSUB I2C_stop
················· GOSUB I2C_start
················· A=r2<<1
················· A.BIT0=0
················· GOSUB I2C_out
················· GOSUB I2c_ack
·············· ENDIF
··········· #ENDIF
··········· READ r2,A
··········· GOSUB I2C_out
··········· GOSUB I2C_ack
········ NEXT
········ GOSUB I2C_stop
········ LOW vcc
········ HIGH led
····· CASE "2"·· ' copy eeprom > BS2
········ HIGH Vcc
········ GOSUB I2C_start
········ #IF _24C01A #THEN
··········· ' start of DUMMY WRITE
··········· A=%10100000
··········· GOSUB I2C_out
··········· GOSUB I2C_ack
··········· A=0
··········· GOSUB I2C_out
··········· GOSUB I2C_ack
··········· ' end of DUMMY WRITE
··········· GOSUB I2C_start
··········· A=%10100001
········ #ELSE
··········· A=1· ' read
········ #ENDIF
········ GOSUB I2C_out
········ GOSUB I2C_ack
········ FOR r2=0 TO eeprom_size-1
··········· GOSUB I2C_in
··········· LOW sda·· ' sda pull low, eeprom inc data word addr
··········· HIGH scl
··········· LOW scl
··········· TOGGLE LED
··········· WRITE r2,a
········ NEXT
········ GOSUB I2C_no_ack
········ GOSUB I2C_stop
········ LOW vcc
········ HIGH led
····· CASE "3" TO "4"
······· IF r2="3" THEN··· ' display eeprom
·········· HIGH Vcc
·········· GOSUB I2C_start
·········· #IF _24C01A #THEN
··········· A=%10100000
··········· GOSUB I2C_out
··········· GOSUB I2C_ack
··········· A=0
··········· GOSUB I2C_out
··········· GOSUB I2C_ack
··········· GOSUB I2C_start
··········· A=%10100001
·········· #ELSE
············· A=1· ' read
·········· #ENDIF
·········· GOSUB I2C_out
·········· GOSUB I2C_ack
······· ENDIF
······· SEROUT 16,baud,[noparse][[/noparse]LF,CR,"DATA "]
······· FOR r1= 0 TO eeprom_size-1
········· IF r2="4" THEN
············ READ r1,A····· ' read from BS2
········· ELSE
············ GOSUB I2C_in·· 'read from eemprom
············ LOW sda·· ' sda pull low, eeprom inc data word addr
············ HIGH scl
············ LOW scl
············ TOGGLE LED
········· ENDIF
········· SEROUT 16,baud,[noparse][[/noparse]"$",HEX2 A]
········· A=(r1+1)//16
········· IF A=0 THEN
············ SEROUT 16,baud,[noparse][[/noparse]LF,CR,"DATA "]
········· ELSE
············ SEROUT 16,baud,[noparse][[/noparse]","]
········· ENDIF
······· NEXT
······· IF r2="3" THEN
·········· GOSUB I2C_no_ack
·········· GOSUB I2C_stop
·········· LOW Vcc
·········· HIGH LED
······· ENDIF
··· ENDSELECT
· LOOP
END
I2C_start:
· HIGH sda
· HIGH scl
· LOW sda
· LOW scl
RETURN
I2C_stop:
· LOW sda
· HIGH scl
· HIGH sda
· LOW scl
RETURN
I2C_ack:
· HIGH scl
· INPUT sda
· IF sda=0 THEN
··· TOGGLE LED
· ELSE
··· LOW scl
··· SEROUT 16,baud,[noparse][[/noparse]"Err",CR]
··· STOP
· ENDIF
· LOW scl
· OUTPUT sda
RETURN
I2C_no_ack:
· PULSOUT scl,5
RETURN
I2C_out:
· ' Byte to be send put into valuable A
· LOW scl····· ' low the scl to put the data in sda
· FOR r0=1 TO size
··· IF A.BIT7=1 THEN· ' MSB send out first
····· HIGH sda
··· ELSE
····· LOW sda
··· ENDIF
··· A=A << 1
··· PULSOUT scl,5
· NEXT
RETURN
I2C_in:
· LOW scl
· A=0
· FOR r0=1 TO size
··· A=A << 1
··· INPUT sda
··· IF sda=1 THEN
····· A.BIT0=1
··· ELSE
····· A.BIT0=0
··· ENDIF
··· PULSOUT scl,5
· NEXT
· OUTPUT sda·· 'sda pin in output mode
RETURN

Post Edited By Moderator (Chris Savage (Parallax)) : 2/16/2006 3:07:16 PM GMT
1600 x 1200 - 812K

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-03-02 10:47
    It is interesting that you started out with a robot and moved on to an EEPROM programer for another project. It seems that a BasicStamp can easily adapt to so many things. This is quite useful for me too as I am programing the SX-28, but sometimes I need to program an EEPROM for it.

    It will save time because I don't have to figure out a way to do it all in Assemby language.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
Sign In or Register to comment.