This is a multi-part message in MIME format. ------=_NextPart_000_00D2_01C14B86.51565DC0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit >Hi, > >Can anyone please give a rough indication for a (very) basic I2C driver to >interface a 12C508/similar to a 24LC00 E2? No multi master or other such >"cleverness" is required. Just a simple read and write routine allowing >for internal page boundaries will suffice (sorry - not Inet/data >sheets.....from memory, the 24LC00 is 256 bytes with a 16 byte page writing >buffer(?)) 24LC00 is 16 bytes only with no page write buffer. I have a simple I2C routine which does byte and page read/write. It's about 70 words and works reliably for years in a product with 24LC01. This version is cut out from a large file - it's not tested. Regards, Djula ------=_NextPart_000_00D2_01C14B86.51565DC0 Content-Type: application/octet-stream; name="i2c_508.asm" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="i2c_508.asm" ; Device: 12c508a ; Oscillator: Internal RC @ 4.00MHz (I2C @ 166kHz) ; Watchdog Timer: On ; Code Protect: Off ; Master Clear : Internal list p=12c508a,f=inhx8m,r=dec include p12c508a.inc __config _IntRC_OSC & _WDT_ON & _CP_OFF & _MCLRE_OFF Buffer0 equ 0x10 Buffer1 equ 0x11 Buffer2 equ 0x12 Buffer3 equ 0x13 EE_Addr equ 0x14 EE_Data equ 0x15 Tmp1 equ 0x16 Tmp2 equ 0x17 ;***************************************************************** ;* R E S E T E N T R Y P O I N T * ;***************************************************************** org 0x0000 ;Reset vector movwf OSCCAL ;Take care of the calibration goto Start ;Start the program ;***************************************************************** ;* S U B R O U T I N E S * ;***************************************************************** Wait_ms movwf Tmp1 Wait1 movlw 249 ;Waits W movwf Tmp2 ;miliseconds Wait2 clrwdt decfsz Tmp2,f ;Uses Tmp1 goto Wait2 ;and Tmp2 decfsz Tmp1,f goto Wait1 StartB movlw B'00000000' tris GPIO ;SDA=output bsf GPIO,1 ;SDA=1 goto $+1 bsf GPIO,0 ;SCL=1 goto $+1 bcf GPIO,1 ;SDA=0 goto $+1 SCL_0 bcf GPIO,0 ;SCL=0 retlw 0 StopB movlw B'00000000' tris GPIO ;SDA=output bcf GPIO,1 ;SDA=0 goto $+1 bsf GPIO,0 ;SCL=1 goto $+1 bsf GPIO,1 ;SDA=1 retlw 0 PutAck movlw B'00000000' ;SDA=output goto Ack GetAck movlw B'00000010' ;SDA=input Ack tris GPIO bcf GPIO,1 ;SDA=0 goto $+1 bsf GPIO,0 ;SCL=1 goto $+1 clrc btfsc GPIO,1 ;SDA=1? setc ;Yes goto SCL_0 ;SCL=0 PrepWr bsf Tmp1,7 ;Prepares EEPROM for write goto PrepEE ;Input=EE_Addr PrepRd clrf Tmp1 ;Prepares EEPROM for read PrepEE call StartB ;Start bit movlw 0xa0 call Write8 ;Write EEPROM id (4) + address (3) + Wr (1) call GetAck ;Get acknowledge movfw EE_Addr call Write8 ;Write address (8) call GetAck ;Get acknowledge btfsc Tmp1,7 retlw 0 call StartB ;Start Bit movlw 0xa1 call Write8 goto GetAck ;Get acknowledge Write8 movwf Tmp2 ;W is written to EEPROM movlw B'00000000' ;Uses Tmp1 and Tmp2 goto TrisRW8 ;SDA=output Read8 movlw B'00000010' ;SDA=input TrisRW8 tris GPIO RW8 movlw 0x80 ;Bit counter=0 andwf Tmp1,f RWNext rlf Tmp2,w skpc bcf GPIO,1 ;SDA=0 skpnc bsf GPIO,1 ;SDA=1 goto $+1 bsf GPIO,0 ;SCL=1 goto $+1 clrc btfsc GPIO,1 ;SDA=1? setc ;Yes rlf Tmp2,f bcf GPIO,0 ;SCL=0 incf Tmp1,f ;All bits sent/read? btfss Tmp1,3 ;Yes, skip goto RWNext ;No, again retlw 0 ;***************************************************************** ;* M A I N P R O G R A M * ;***************************************************************** Start clrf FSR movlw B'00000011' ;Init IO movwf GPIO ;GPIO0=SCL (no pull-up) movlw B'00000000' ;GPIO1=SDA tris GPIO movlw B'11000100' option ;ONE BYTE WRITE movlw 0x00 ;Example: movwf EE_Addr ;Write one byte to EEPROM movlw 0x12 movwf EE_Data call PrepWr ;Load address movfw EE_Data ;Get the data call Write8 ;and do the write call GetAck call StopB ;Finish the sequence movlw 10 ;Wait 10 ms call Wait_ms ;ONE BYTE READ movlw 0x00 ;Example: movwf EE_Addr ;Read one byte from EEPROM call PrepRd ;Load address call Read8 ;and do the read movfw Tmp2 ;Get the result movwf EE_Data ;and save it call StopB ;Finish the sequence ;FOUR BYTE PAGE WRITE movlw 0x12 ;Example: movwf Buffer0 ;Write four bytes to EEPROM movlw 0x34 movwf Buffer1 movlw 0x56 movwf Buffer2 movlw 0x78 movwf Buffer3 movlw Buffer0 movwf FSR movlw 0x00 movwf EE_Addr call PrepWr ;Load address WrNext movfw INDF ;Get the data from RAM call Write8 ;and do the write call GetAck incf FSR,f ;Increment RAM pointer incf EE_Addr,f ;Increment EEPROM pointer btfss EE_Addr,2 ;EEPROM address=4? goto WrNext ;No, write another byte call StopB ;Yes, finish the sequence movlw 10 ;Wait 10 ms call Wait_ms ;FOUR BYTE SEQUENTIAL READ movlw Buffer0 ;Example: movwf FSR ;Read four bytes from EEPROM movlw 0x00 movwf EE_Addr call PrepRd ;Load address RdNext call Read8 ;Do the read movfw Tmp2 ;Get the result movwf INDF ;and save it to RAM incf FSR,f ;Increment RAM pointer incf EE_Addr,f ;Increment EEPROM pointer btfsc EE_Addr,2 ;EEPROM address=4? goto EndSqRd ;Yes, finish the sequence call PutAck ;No, acknowledge and goto RdNext ;read another byte EndSqRd call StopB Done clrwdt ;Endless loop goto Done END ------=_NextPart_000_00D2_01C14B86.51565DC0-- -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body