Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] problem with page write in eeprom 24c02

Status
Not open for further replies.

pratzz

Member level 5
Joined
Jun 15, 2012
Messages
83
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,288
Activity points
1,781
Code:
list p=PIC16F877a
#include <p16F877a.inc>
errorlevel -302
__config _HS_OSC & _WDT_OFF & _LVP_OFF
;-------------------------------------------
; SPECIAL FUNCTION REGISTERS
;-------------------------------------------
;*******************Macro definitions*****************************
WRITE_ADDR  equ     b'10100000' ; Control byte for write operations
READ_ADDR   equ     b'10100001' ; Control byte for read operations
rs  equ 0
rw equ 1
en equ 2
;*******************Include file**********************************

;-------------------------------------------
; GENERAL PURPOSE REGISTERS
;-------------------------------------------
		CBLOCK 20h
count 
count1
count3
count4
dat  
disp 
number
bytecount
temp
		ENDC


		ORG 0
		clrf STATUS
		movlw 00
		movwf PCLATH
		goto start
;-------------------------------------------
		org 04
		retfie
;----------------------------------------------
table
movlw HIGH $
movwf PCLATH
movf count1,w
addwf PCL,f
dt ' ',' ',' ',' ',' ','E','X','C','E','L',' ',' ',' ',' ',' ',' '
dt ' ',' ','T','E','C','H','N','O','L','O','G','I','E','S',' ',' '
;-----------------------------------------------------------------
table1
movlw HIGH $
movwf PCLATH
movf temp,w
addwf PCL,f
dt "     EEPROM     "
movlw 0c0h
call lcd_cmd
dt "  WRITE DONE   ",0
lcd_cmd
        movwf PORTD
        bcf PORTB,rs
        bcf PORTB,rw
        bsf PORTB,en
        call delay
        bcf PORTB,en
        retlw 00h
;------------------------------------------------------------------
lcd_data
        movwf PORTD
        bsf PORTB,rs
        bcf PORTB,rw
        bsf PORTB,en
        call delay
        bcf PORTB,en
        retlw 00h
;------------------------------------------------------------------
lcd_init
        movlw 38h
        call lcd_cmd
        call delay
        movlw 0eh
        call lcd_cmd
        call delay
        movlw 01h
        call lcd_cmd
        call delay
        movlw 06h
        call lcd_cmd
        call delay
        movlw 80h
        call lcd_cmd
        call delay
        call delay
         retlw 00h
;-------------------------------------------------------------------
delay
        movlw 02h
        movwf count3
here2   movlw 0ffh
        movwf count4
here    decfsz count4,1
        goto here
        decfsz count3,1
        goto here2
        retlw 00h
;-----------------------------------------------------------------


initialise
        clrf temp
        clrf count
        clrf count1
    	bcf STATUS,RP1
		bsf STATUS,RP0
        clrf TRISB
		clrf TRISD
		movlw b'00000111'
		movwf ADCON1
        movlw b'11111111'
        movwf   TRISC               ; Set PORTC to all inputs
        clrf    SSPSTAT             ; Disable SMBus inputs
        bsf     SSPSTAT,SMP         ; Disable slew rate control
        movlw   09h                ; Load 0x18 into WREG
        movwf   SSPADD              ; Setup 100 kHz I2C clock
        clrf    SSPCON2
		bcf     STATUS,RP0
        movlw   b'00101000'
        movwf   SSPCON              ; Enable SSP, select I2C Master mode
        bcf     PIR1,SSPIF          ; Clear SSP interrupt flag
        bcf     PIR2,BCLIF
		retlw 00
;--------------------------------------------------------------
genstart
   
    bcf     STATUS,RP1
    bcf     STATUS,RP0          ; Select Bank 00
    bcf     PIR1,SSPIF          ; Clear SSP interrupt flag
    bsf     STATUS,RP0          ; Select Bank 01
    bsf     SSPCON2,SEN         ; Generate Start condition
    bcf     STATUS,RP0          ; Select Bank 00
    start_wait
    btfss   PIR1,SSPIF          ; Check if operation completed
    goto    start_wait          ; If not, keep checking
    retlw   0
genstop
    bcf     STATUS,RP1
    bcf     STATUS,RP0          ; Select Bank 00
    bcf     PIR1,SSPIF          ; Clear SSP interrupt flag
    bsf     STATUS,RP0          ; Select Bank 01
    bsf     SSPCON2,PEN         ; Generate Stop condition
    bcf     STATUS,RP0          ; Select Bank 00
stop_wait
    btfss   PIR1,SSPIF          ; Check if operation completed
    goto    stop_wait          ; If not, keep checking
    retlw   00
genrepstart
    bcf     STATUS,RP1
    bcf     STATUS,RP0          ; Select Bank 00
    bcf     PIR1,SSPIF          ; Clear SSP interrupt flag
    bsf     STATUS,RP0          ; Select Bank 01
    bsf     SSPCON2,RSEN        ; Generate Restart condition
    bcf     STATUS,RP0          ; Select Bank 00
    repstart_wait
    btfss   PIR1,SSPIF          ; Check if operation completed
    goto    repstart_wait       ; If not, keep checking

    retlw   0
;-------------------------------------------------------------
--------------------------------------------
transmit
   
    bcf     STATUS,RP1
    bcf     STATUS,RP0          ; Select Bank 00
    bcf     PIR1,SSPIF          ; Clear SSP interrupt flag
    movf    dat,W           ; Copy dat to WREG
    movwf   SSPBUF              ; Write byte out to device
  tx_wait
    btfss   PIR1,SSPIF          ; Check if operation completed
    goto    tx_wait             ; If not, keep checking
    bcf     PIR1,SSPIF
  ; bsf     STATUS,RP0          ; Select Bank 01
 ;  btfsc   SSPCON2,ACKSTAT     ; Check if ACK bit was received
 ;  goto    ackfailed           ; This executes if no ACK received
    
    retlw   00h

;-----------------------------------------------------------
  
    pagewrite
    bcf     STATUS,RP1
    bcf     STATUS,RP0          ; Select Bank 00
    movlw   08h
    movwf   bytecount           ; Initialize counter to 16 bytes

    call    genstart              ; Generate start bit
                                ; Now we send the control byte
    bcf     STATUS,RP0          ; Select Bank 00
    movlw   WRITE_ADDR
    movwf   dat               ; Copy control byte to buffer
    call    transmit                 ; Output control byte to device

                                ; Send word address high byte
    bcf     STATUS,RP0          ; Select Bank 00
    movf    count,W                ; Use 0x5A for address to send
    movwf   dat               ; Copy address to buffer
    call    transmit


    bcf     STATUS,RP0          ; Select Bank 00
txbyte                          ; This loop transfers all 16 of
    call    table                            ; the data bytes to the device
    incf    count,1     ; Use bytecount as data value
    movwf   dat                      ; Copy data to buffer
    call    transmit                  ; Output data to device

    bcf     STATUS,RP0          ; Select Bank 00
    decfsz  bytecount,F         ; Check if finished looping
    goto    txbyte              ; Continue looping

    call    genstop               ; Generate stop bit
    ;call    Poll                ; Poll for write completion
    retlw   0
;-------------------------------------------
; Main program starts
;-------------------------------------------
start		call initialise
            call lcd_init
            
            call pagewrite
            call pagewrite
            call pagewrite
            call pagewrite
 y          call table1
            iorlw 00h
            btfsc STATUS,Z
            goto x
            call lcd_data
            incf temp,1
            goto y
 x           goto x

   end
only my first and last page call are wrking and corresponding data is getting written into it.
 

I am using pic18f458 to write data to eeprom 24c02 & am correctly writing and reading data upto 256 bytes (upto page 1) , once i write data after 256 bytes its overwriting from begining .plz help how to write data to eepom after 256bytes memory location.
 
Last edited:

to my knowledge 24c02 has capacity of 256 bytes only i.e. 256*8 bits = 2k
 

to my knowledge 24c02 has capacity of 256 bytes only i.e. 256*8 bits = 2k

thank u..it has 32 pages of 8 bytes each(32*8=256bytes)...but its memory is 2K & i am sure i used only 256 bytes then how to access remaining memory.

( AT24C02, 2K SERIAL EEPROM: Internally organized with 32 pages of 8 bytes each,
the 2K requires an 8-bit data word address for random word addressing......from datasheet)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top