eeprom problem

Status
Not open for further replies.

jijita

New Member
i wrote a code that takes a byte from a dip switch and write it on an eeprom then read the byte from the eeprom and display it to leds
the problem is that when i display the first byte and then i want to display the second byte i can't unless i do a reset
what i suspected it would be wrong is the fact that i sent a NOACK from pic to eeprom after the read this is where the block happens
can somebody tell me if i shouldn't use the noack when i'm reading only one byte then doing stop
 
the code

this is the code can you tellme what's wrong with it
LIST P=pic16F877A
#INCLUDE<P16F877A.INC>


addr equ 0x20
eepal equ 0x21
eepah equ 0x22

ORG 0X00 ;the start address in memory is 0
GOTO Main ;goto Main
Main BCF STATUS,RP1 ;turns to Bank 1
BSF STATUS,RP0
MOVLW B'00000111' ;Prescaler is /256
OPTION
MOVLW B'11111111'
MOVWF TRISB
MOVLW B'00011011'
MOVWF TRISC
CLRF TRISD
BCF STATUS,RP0
CLRF eepah
CLRF eepal
CLRF PORTB
CLRF PORTC
CLRF PORTD

;Initialisation I2C

BSF STATUS,RP0 ;turns to Bank 1
CLRF SSPSTAT ;Clears SSPSTAT
MOVLW D'2' ;2 is the recharge value of the Baud Rate Generator
MOVWF SSPADD ;Set SSPADD=2
BCF STATUS,RP0 ;turns to Bank 0
MOVLW B'00101000' ;Enable MSSP module in mode I2C master
MOVWF SSPCON ;

TEST MOVLW B'10100000' ;put 10100000 in W
MOVWF addr ;Set addr=10100000

BTFSC PORTC,0
GOTO $-1
CALL DEBOUNCER
BTFSC PORTC,0
GOTO TEST
BTFSS PORTC,0
GOTO $-1
CALL writeeep
BCF STATUS,RP0
BTFSC PORTC,1
GOTO $-1
CALL DEBOUNCER
BTFSC PORTC,1
GOTO TEST
BTFSS PORTC,1
GOTO $-1
CALL readdisp
GOTO TEST

DEBOUNCER MOVLW D'222'
MOVWF TMR0
BCF INTCON,2
BTFSS INTCON,2
GOTO $-1
RETURN

writeeep BSF STATUS,RP0
bsf SSPCON2,SEN ; lancer le start-condition
BTFSC SSPCON2,SEN ; start-condition terminé ?
GOTO $-1
BCF STATUS,RP0
MOVF addr,w
MOVWF SSPBUF
BSF STATUS,RP0
BTFSC SSPSTAT,R_W ; tester si émission terminée
GOTO $-1

BCF STATUS,RP0

MOVF eepah,w
MOVWF SSPBUF
BSF STATUS,RP0
BTFSC SSPSTAT,R_W ; tester si émission terminée
GOTO $-1
BCF STATUS,RP0
MOVF eepal,w
MOVWF SSPBUF
BSF STATUS,RP0
BTFSC SSPSTAT,R_W ; tester si émission terminée
GOTO $-1
BCF STATUS,RP0
MOVF PORTB,w
MOVWF SSPBUF
BSF STATUS,RP0
BTFSC SSPSTAT,R_W ; tester si émission terminée
GOTO $-1
bsf SSPCON2,PEN ; lancer le stop-condition
btfsc SSPCON2,PEN ; stop-condition terminé ?
GOTO $-1
RETURN

readdisp BSF STATUS,RP0
bsf SSPCON2,SEN ; lancer le start-condition
BTFSC SSPCON2,SEN ; start-condition terminé ?
GOTO $-1
BCF STATUS,RP0
MOVF addr,w
MOVWF SSPBUF
BSF STATUS,RP0
BTFSC SSPSTAT,R_W ; tester si émission terminée
GOTO $-1
BCF STATUS,RP0
MOVF eepah,w
MOVWF SSPBUF
BSF STATUS,RP0
BTFSC SSPSTAT,R_W ; tester si émission terminée
GOTO $-1
BCF STATUS,RP0
MOVF eepal,w
MOVWF SSPBUF
BSF STATUS,RP0
BTFSC SSPSTAT,R_W ; tester si émission terminée
GOTO $-1
bsf SSPCON2,RSEN ; lancer le repeated start-condition
btfsc SSPCON2,RSEN ; start-condition terminé ?
GOTO $-1
BCF STATUS,RP0
INCF addr,F
MOVF addr,w
MOVWF SSPBUF
BSF STATUS,RP0
BTFSC SSPSTAT,R_W ; tester si émission terminée
GOTO $-1
bsf SSPCON2,RCEN ; lancer la réception
btfsc SSPCON2,RCEN ; réception terminée ?
GOTO $-1
BCF STATUS,RP0
MOVF SSPBUF,w
MOVWF PORTD
BSF STATUS,RP0
bsf SSPCON2,ACKDT ; le bit qui sera envoyé vaudra « 1 »
bsf SSPCON2,ACKEN ; lancer l’acknowledge (= ACKDT = 1 = NOACK)
BTFSC SSPCON2,ACKEN ; tester si NOACK terminé
GOTO $-1

bsf SSPCON2,PEN ; lancer le stop-condition
btfsc SSPCON2,PEN ; stop-condition terminé ?
GOTO $-1
RETURN

END
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…