This is a multi-part message in MIME format. ------=_NextPart_000_0057_01C0B721.963603E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit This is a simple program to send a byte to an 24LC32 EEPROM. The program runs all of the way through without showing an error but when I read the EEPROM the byte has not been written. This program is originally from Josef in the JAL language (http://www.piclist.com/techref/piclist/jal/i2c-j.htm). If anyone can take a look at this I would be thankful. Glenn Mitchell. ------=_NextPart_000_0057_01C0B721.963603E0 Content-Type: application/octet-stream; name="epr.asm" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="epr.asm" ; radix hex =20 ; list p=3D16f876 ;------------------------------------------------------------------------= status equ 03 =20 porta equ 05 =20 portb equ 06 =20 portc equ 07 =20 pclath equ 0a =20 intcon equ 0b =20 sspbuf equ 13 =20 sspcon equ 14 =20 ; trisa equ 05 =20 trisb equ 06 =20 trisc equ 07 =20 sspcon2 equ 11 =20 sspadd equ 13 =20 sspstat equ 14 =20 adcon1 equ 1f =20 ;------------------------------------------------------------------------= - w equ 0 =20 f equ 1 =20 ; c equ 0 =20 rp0 equ 5 =20 ; sen equ 0 =20 rsen equ 1 =20 pen equ 2 =20 rcen equ 3 =20 acken equ 4 =20 ackdt equ 5 =20 ackstat equ 6 =20 gcen equ 7 =20 ; bf equ 0 =20 ua equ 1 =20 r_w equ 2 =20 s equ 3 =20 p equ 4 =20 d_a equ 5 =20 cke equ 6 =20 smp equ 7 =20 ;------------------------------------------------------------------------= ------ edata equ 0020 ;data to/from EEPROM =20 ehigh equ 0021 ;EEPROM high address =20 elow equ 0022 ;EEPROM low address =20 ; d1 equ 0023 ;delay routine d2 equ 0024 ; d3 equ 0025 ; ;------------------------------------------------------------------------= ------ org 0x000 ; Reset Vector clrf pclath ; PCLATH bit 3 is cleared=20 clrf intcon ; all interrupts are disabled goto init ; jump to the beginning=20 org 0x004 ; interrupt vector, do nothing isr goto isr ; do nothing=20 ;------------------------------------------------------------------------= ------ init call delay ;let everything settle clrf porta clrf portb clrf portc bsf status,rp0 ;bank 1 =20 movlw 0x06 ;0000 0110 =20 movwf adcon1 ;all pins digital movlw 0x00 ;0000 0000 =20 movwf trisa ;all pins outputs movlw 0x00 ;0000 0000 =20 movwf trisb ;all pins outputs movlw 0x18 ;0001 1000 =20 movwf trisc ;RC3,RC4 inputs=20 bcf status,rp0 ;bank 0 movlw 0x28 ;0010 1000 =20 movwf sspcon ;enable I2C master mode bsf status,rp0 ;bank 1 movlw 0x80 ;1000 0000 =20 movwf sspstat ;slew control disabled movlw 0x60 ;0110 0000 movwf sspcon2 movlw d'39' ;16 MHz xtal=3D100 kHz bus =20 movwf sspadd bcf status,rp0 ;bank 0 =20 ;------------------------------------------------------------------------= ------ main bsf porta,0 ;LED 0 ON, ok so far clrf ehigh ;high address 0 clrf elow ;low address 0 movlw d'42' ;char to send movwf edata ;move to buffer call ewrite ;call write routine bsf porta,1 ;LED 1 ON, made it to the end loop goto loop ;------------------------------------------------------------------------= ------ =20 start bsf status,rp0 ;bank 1 bsf sspcon2,sen ;initiate start btfsc sspcon2,sen ;SSP respond? goto $-1 ;no. loop. bcf status,rp0 ;bank 0 return ;------------------------------------------------------------------------= ------ restart bsf status,rp0 ;bank 1 bsf sspcon2,rsen ;initiate repeated start btfsc sspcon2,rsen ;SSP respond? goto $-1 ;no. loop. bcf status,rp0 ;bank 0 return ;------------------------------------------------------------------------= ------ stop bsf status,rp0 ;bank 1 bsf sspcon2,pen ;initiate stop btfsc sspcon2,pen ;SSP respond? goto $-1 ;no. loop. bcf status,rp0 ;bank 0 return ;------------------------------------------------------------------------= ------ xmit movwf sspbuf ;send byte bsf status,rp0 ;bank 1 btfsc sspstat,r_w ;transmit in progress? goto $-1 ;yes. loop. bcf status,c ;clear carry btfsc sspcon2,ackstat ;acknowledge? bsf status,c ;no. set carry.=20 bcf status,rp0 ;bank 0 return ;------------------------------------------------------------------------= ------ recv bsf status,rp0 ;bank 1 bcf sspcon2,ackdt ;ack sequence sends ack btfsc status,c ;use carry as a flag bsf sspcon2,ackdt ;ack sequence sends not_ack bsf sspcon2,rcen ;enable receive btfss sspstat,bf ;receive complete? goto $-1 ;no. loop. bsf sspcon2,acken ;initiate ack sequence btfsc sspcon2,acken ;SSP respond? goto $-1 ;no. loop. bcf status,rp0 ;bank 0 movf sspbuf,w ;move rcvd byte to w return ;------------------------------------------------------------------------= ------ ewrite call start ;start the bus movlw 0x0a ;control byte call xmit ;send it btfsc status,c ;ack? goto err ;no. Something wrong. movf ehigh,w ;high address byte call xmit ;send it movf elow,w ;low address byte. call xmit ;send it movf edata,w ;data to send call xmit ;send it call stop ;stop the bus return ;------------------------------------------------------------------------= ------ err bsf porta,5 ;LED 5 ON, something wrong. call stop return ;------------------------------------------------------------------------= - delay movlw 0x5c movwf d1 Delay_00 movlw 0x75 movwf d2 Delay_01 movlw 0x7a movwf d3 Delay_02 decfsz d3, f goto Delay_02 decfsz d2, f goto Delay_01 decfsz d1, f goto Delay_00 ;16937 cycles movlw 0x3a movwf d1 Delay_10 movlw 0x60 movwf d2 Delay_11 decfsz d2, f goto Delay_11 decfsz d1, f goto Delay_10 ;10 cycles goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 ;4 cycles (including call) return ;------------------------------------------------------------------------= - end =20 =1A ------=_NextPart_000_0057_01C0B721.963603E0-- -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads