it shuld take data from dip switch and write it on eeprom i2c then read it and display it on leds
it's allways displaying on the leds 11111111
all the leds are on and this is only when i test portc 0
before i even test portc1 it shows all leds on
LIST P=pic16F877A
#INCLUDE<P16F877A.INC>
addr equ 0x20
eepal equ 0x21
eepah equ 0x22
term equ 0x23
cmpt equ 0x24
ORG 0X00 ;the start address in memory is 0
GOTO Main ;goto Main
ORG 0X04 ;the start address is 0X04
GOTO INTRTN ;goto INTRTN
INTRTN BTFSC term,1
GOTO lire
INCF cmpt,f ;add 1 to cmpt
movf cmpt,w
ADDWF PCL,1 ;add W to PCL
NOP
GOTO I2C_sendadress
GOTO I2C_eepaddrhigh
GOTO I2C_eepaddrlow
GOTO I2C_sendByte
GOTO I22C_STOP ;Yes
GOTO TESTING
I2C_sendByte BCF PIR1,SSPIF ;must be cleared before returning
BCF STATUS,RP0 ;turns to Bank 0
MOVF PORTB,w
MOVWF SSPBUF ;put W in SSPBUF
RETFIE
lire INCF cmpt,1
movf cmpt,w
addwf PCL,1
NOP
GOTO I2C_sendadress
GOTO I2C_eepaddrhigh
GOTO I2C_eepaddrlow
GOTO RSTART
GOTO I2C_sendadress
GOTO read
GOTO take
GOTO stopread
I2C_sendadress BCF PIR1,SSPIF ;must be cleared before returning
BCF STATUS,RP0 ;turns to Bank 0
MOVLW addr ;put addr in W
MOVWF SSPBUF ;put addr in SSPBUF
RETFIE
RSTART BCF PIR1,SSPIF
BSF STATUS,RP0
BSF SSPCON2,RSEN
BCF STATUS,RP0
INCF addr,F
RETFIE
read BCF PIR1,SSPIF
BSF STATUS,RP0
BSF SSPCON2,RCEN ; lancer la r馗eption
BCF STATUS,RP0
RETFIE
take BCF PIR1,SSPIF
MOVF SSPBUF,W
MOVWF PORTD
BSF STATUS,RP0
BSF SSPCON2,PEN ; lancer le stop-condition
BCF STATUS,RP0
RETFIE
stopread BCF PIR1,SSPIF
BCF term,1
CLRF cmpt
BSF PORTC,5
RETFIE
I2C_eepaddrhigh BCF PIR1,SSPIF ;must be cleared before returning
BCF STATUS,RP0 ;turns to Bank 0
MOVF eepah,W ;put eepa in W
MOVWF SSPBUF ;put eepa in SSPBUF
RETFIE
I2C_eepaddrlow BCF PIR1,SSPIF ;must be cleared before returning
BCF STATUS,RP0 ;turns to Bank 0
MOVF eepal,W ;put eepa+1 in W
MOVWF SSPBUF ;put eepa+1 in SSPBUF
RETFIE
I22C_STOP BCF PIR1,SSPIF ;must be cleared before returning
BSF STATUS,RP0
BSF SSPCON2,PEN ;Initiate STOP condition on SDA and SCL pins
BCF STATUS,RP0
RETFIE
TESTING CLRF cmpt
BSF term,0
RETFIE
Main BCF STATUS,RP1 ;turns to Bank 1
BSF STATUS,RP0
MOVLW B'00000111' ;Prescaler is /256
OPTION
BSF INTCON,7 ;Enables all unmasked interrupts
BSF INTCON,6 ;Enables all unmasked peripheral interrupts
MOVLW B'00001000'
MOVWF PIE1
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
CLRF term
CLRF cmpt
;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
BSF STATUS,RP0
BSF SSPCON2,SEN ;Initiate START condition on SDA and SCL pins
BCF STATUS,RP0
BTFSS term,0
GOTO $-1
BCF term,0
BSF term,1
BCF STATUS,RP0
BTFSC PORTC,1
GOTO $-1
CALL DEBOUNCER
BTFSC PORTC,1
GOTO TEST
BTFSS PORTC,1
GOTO $-1
BSF STATUS,RP0
BSF SSPCON2,SEN
BCF STATUS,RP0
btfsc term,1
GOTO $-1
INCF eepal,F
GOTO TEST
DEBOUNCER MOVLW D'222'
MOVWF TMR0
BCF INTCON,2
BTFSS INTCON,2
GOTO $-1
RETURN
end
it's allways displaying on the leds 11111111
all the leds are on and this is only when i test portc 0
before i even test portc1 it shows all leds on
LIST P=pic16F877A
#INCLUDE<P16F877A.INC>
addr equ 0x20
eepal equ 0x21
eepah equ 0x22
term equ 0x23
cmpt equ 0x24
ORG 0X00 ;the start address in memory is 0
GOTO Main ;goto Main
ORG 0X04 ;the start address is 0X04
GOTO INTRTN ;goto INTRTN
INTRTN BTFSC term,1
GOTO lire
INCF cmpt,f ;add 1 to cmpt
movf cmpt,w
ADDWF PCL,1 ;add W to PCL
NOP
GOTO I2C_sendadress
GOTO I2C_eepaddrhigh
GOTO I2C_eepaddrlow
GOTO I2C_sendByte
GOTO I22C_STOP ;Yes
GOTO TESTING
I2C_sendByte BCF PIR1,SSPIF ;must be cleared before returning
BCF STATUS,RP0 ;turns to Bank 0
MOVF PORTB,w
MOVWF SSPBUF ;put W in SSPBUF
RETFIE
lire INCF cmpt,1
movf cmpt,w
addwf PCL,1
NOP
GOTO I2C_sendadress
GOTO I2C_eepaddrhigh
GOTO I2C_eepaddrlow
GOTO RSTART
GOTO I2C_sendadress
GOTO read
GOTO take
GOTO stopread
I2C_sendadress BCF PIR1,SSPIF ;must be cleared before returning
BCF STATUS,RP0 ;turns to Bank 0
MOVLW addr ;put addr in W
MOVWF SSPBUF ;put addr in SSPBUF
RETFIE
RSTART BCF PIR1,SSPIF
BSF STATUS,RP0
BSF SSPCON2,RSEN
BCF STATUS,RP0
INCF addr,F
RETFIE
read BCF PIR1,SSPIF
BSF STATUS,RP0
BSF SSPCON2,RCEN ; lancer la r馗eption
BCF STATUS,RP0
RETFIE
take BCF PIR1,SSPIF
MOVF SSPBUF,W
MOVWF PORTD
BSF STATUS,RP0
BSF SSPCON2,PEN ; lancer le stop-condition
BCF STATUS,RP0
RETFIE
stopread BCF PIR1,SSPIF
BCF term,1
CLRF cmpt
BSF PORTC,5
RETFIE
I2C_eepaddrhigh BCF PIR1,SSPIF ;must be cleared before returning
BCF STATUS,RP0 ;turns to Bank 0
MOVF eepah,W ;put eepa in W
MOVWF SSPBUF ;put eepa in SSPBUF
RETFIE
I2C_eepaddrlow BCF PIR1,SSPIF ;must be cleared before returning
BCF STATUS,RP0 ;turns to Bank 0
MOVF eepal,W ;put eepa+1 in W
MOVWF SSPBUF ;put eepa+1 in SSPBUF
RETFIE
I22C_STOP BCF PIR1,SSPIF ;must be cleared before returning
BSF STATUS,RP0
BSF SSPCON2,PEN ;Initiate STOP condition on SDA and SCL pins
BCF STATUS,RP0
RETFIE
TESTING CLRF cmpt
BSF term,0
RETFIE
Main BCF STATUS,RP1 ;turns to Bank 1
BSF STATUS,RP0
MOVLW B'00000111' ;Prescaler is /256
OPTION
BSF INTCON,7 ;Enables all unmasked interrupts
BSF INTCON,6 ;Enables all unmasked peripheral interrupts
MOVLW B'00001000'
MOVWF PIE1
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
CLRF term
CLRF cmpt
;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
BSF STATUS,RP0
BSF SSPCON2,SEN ;Initiate START condition on SDA and SCL pins
BCF STATUS,RP0
BTFSS term,0
GOTO $-1
BCF term,0
BSF term,1
BCF STATUS,RP0
BTFSC PORTC,1
GOTO $-1
CALL DEBOUNCER
BTFSC PORTC,1
GOTO TEST
BTFSS PORTC,1
GOTO $-1
BSF STATUS,RP0
BSF SSPCON2,SEN
BCF STATUS,RP0
btfsc term,1
GOTO $-1
INCF eepal,F
GOTO TEST
DEBOUNCER MOVLW D'222'
MOVWF TMR0
BCF INTCON,2
BTFSS INTCON,2
GOTO $-1
RETURN
end