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.

EEPROM.INC - 16F84 to 16F88 (Datasheets)

Status
Not open for further replies.

REHome

Newbie level 6
Joined
Feb 23, 2008
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,372
Libraries. INC

Happy holidays:

I pass a bookstore called EEPROM.INC the 16F84 to 16F88 and I do not get out much.

Code:
;***************************** Librería "EEPROM.INC" **********************************
;
;    ====================================================================
;      Del libro "MICROCONTROLADOR PIC16F84. DESARROLLO DE PROYECTOS".
;      E. Palacios, F. Remiro y L. López.        [url]www.pic16f84a.com[/url]
;       Editorial Ra-Ma.  [url]www.ra-ma.es[/url]
;    ====================================================================
;
; Estas subrutinas permiten realizar las tareas básicas de escritura y lectura de la
; memoria EEPROM de datos del PIC.
;
; Subrutina "EEPROM_LeeDato" ------------------------------------------------------------
;
; El microcontrolador lee el dato que hay escrito en la posición de la EEPROM del PIC apuntada
; por el contenido del registro de trabajo W. El resultado se proporciona en el mismo W.
;
; Entrada: En (W) la dirección de la memoria EEPROM a leer.
; Salida :  En (W) el byte leído.

EEPROM_LeeDato
    bcf        STATUS,RP0            ; Asegura que trabaja con el Banco 0.
    movwf    EEADR                ; Dirección a leer.
    bsf        STATUS,RP0            ; Banco 1.
    bsf        EECON1,RD            ; Orden de lectura.
EEPROM_SigueLeyendo
    btfsc    EECON1,RD            ; El PIC indica que ha terminado la lectura
    goto    EEPROM_SigueLeyendo    ; poniendo en bajo este bit.
    bcf        STATUS,RP0            ; Banco 0.
    movf    EEDATA,W            ; El byte leído al registro W.
    return

; Subrutina "EEPROM_EscribeDato" --------------------------------------------------------
;
; Escribe el dato introducido en el registro de trabajo W en la posición de memoria EEPROM del
; PIC apuntada por el registro EEADR.
;
; Como altera el valor del registro INTCON al posicionar el flag GIE, éste se debe guardar al
; principio de la subrutina y restaurarlo al final.
;
; Entradas:    En el registro EEADR la dirección de la memoria EEPROM a escribir.
;        En el registro W el byte a escribir.
;
    CBLOCK
    EEPROM_GuardaINTCON
    ENDC

EEPROM_EscribeDato
    bcf        STATUS,RP0            ; Asegura que trabaja con el Banco 0.
    movwf    EEDATA                ; El byte a escribir.
    movf    INTCON,W            ; Reserva el valor anterior de INTCON
    movwf    EEPROM_GuardaINTCON
    bsf        STATUS,RP0            ; Acceso al Banco 1.
    bcf        INTCON,GIE            ; Deshabilita todas las interrupciones.
    bsf        EECON1,WREN            ; Habilita escritura.
;
; El fabricante especifica que hay que seguir esta secuencia para escritura en EEPROM:
;
    movlw    0x55
    movwf    EECON2
    movlw    0xAA
    movwf    EECON2
    bsf        EECON1,WR            ; Inicia la escritura.
EEPROM_TerminaEscribir
    btfsc    EECON1,WR            ; Comprueba que termina de escribir en la EEPROM.
    goto    EEPROM_TerminaEscribir
    bcf        EECON1,WREN            ; Desautoriza la escritura en EEPROM.
    bcf        EECON1,EEIF            ; Limpia este flag.
    bcf        STATUS,RP0            ; Acceso al Banco 0.
    movf    EEPROM_GuardaINTCON,W ; Restaura el valor anterior de INTCON.
    movwf    INTCON
    return

;    ====================================================================
;      Del libro "MICROCONTROLADOR PIC16F84. DESARROLLO DE PROYECTOS".
;      E. Palacios, F. Remiro y L. López.        [url]www.pic16f84a.com[/url]
;       Editorial Ra-Ma.  [url]www.ra-ma.es[/url]
;    ====================================================================
Looking at the Data Sheet of the 16F88 I consider the memory banks that I always change, I've tried with and with bsc BANKSEL STATUS, RP1.

See modified code for the 16F88.

Code:
;***************************** Librería "EEPROM_16F88.INC"
;
;
; Estas subrutinas permiten realizar las tareas básicas de escritura y lectura de la
; memoria EEPROM de datos del PIC.
;
; Subrutina "EEPROM_LeeDato" ------------------------------------------------------------
;
; El microcontrolador lee el dato que hay escrito en la posición de la EEPROM del PIC apuntada
; por el contenido del registro de trabajo W. El resultado se proporciona en el mismo W.
;
; Entrada: En (W) la dirección de la memoria EEPROM a leer.
; Salida :  En (W) el byte leído.

EEPROM_LeeDato
    bsf        STATUS,RP1            ; Asegura que trabaja con el Banco 2.
    bcf        STATUS,RP0
    movwf    EEADR                ; Dirección a leer.
    bsf        STATUS,RP1            ; Banco 3.
    bsf        STATUS,RP0
    bsf        EECON1,RD            ; Orden de lectura.
EEPROM_SigueLeyendo
    btfsc    EECON1,RD            ; El PIC indica que ha terminado la lectura
    goto    EEPROM_SigueLeyendo    ; poniendo en bajo este bit.
    bsf        STATUS,RP1            ; Banco 2.
    bcf        STATUS,RP0
    movf    EEDATA,W            ; El byte leído al registro W.
    return

; Subrutina "EEPROM_EscribeDato" --------------------------------------------------------
;
; Escribe el dato introducido en el registro de trabajo W en la posición de memoria EEPROM del
; PIC apuntada por el registro EEADR.
;
; Como altera el valor del registro INTCON al posicionar el flag GIE, éste se debe guardar al
; principio de la subrutina y restaurarlo al final.
;
; Entradas:    En el registro EEADR la dirección de la memoria EEPROM a escribir.
;        En el registro W el byte a escribir.
;
;-------------------------------+
;    Bancos de memoria 16F88    |
;                               |
;        RP1:PP0            Banco   |
;         0      0              0     |
;        0   1            1     |
;        1   0            2     |
;         1   1            3     |
;                               |
;-------------------------------+

    CBLOCK
    EEPROM_GuardaINTCON
    ENDC

EEPROM_EscribeDato
    bsf        STATUS,RP1
    bcf        STATUS,RP0            ; Asegura que trabaja con el Banco 2.
    movwf    EEDATA                ; El byte a escribir.
    movf    INTCON,W            ; Reserva el valor anterior de INTCON
    movwf    EEPROM_GuardaINTCON
    bsf        STATUS,RP1            ; Acceso al Banco 3.
    bsf        STATUS,RP0
    bcf        INTCON,GIE            ; Deshabilita todas las interrupciones.
    bsf        EECON1,WREN            ; Habilita escritura.
;
; El fabricante especifica que hay que seguir esta secuencia para escritura en EEPROM:
;
    movlw    0x55
    movwf    EECON2
    movlw    0xAA
    movwf    EECON2
    bsf        EECON1,WR            ; Inicia la escritura.
EEPROM_TerminaEscribir
    btfsc    EECON1,WR            ; Comprueba que termina de escribir en la EEPROM.
    goto    EEPROM_TerminaEscribir
    bcf        EECON1,WREN            ; Desautoriza la escritura en EEPROM.
    bcf        EECON1,EEIF            ; Limpia este flag.
    bsf        STATUS,RP1            ; Acceso al Banco 2.
    bcf        STATUS,RP0
    movf    EEPROM_GuardaINTCON,W ; Restaura el valor anterior de INTCON.
    movwf    INTCON
    return




I get this result.



----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Archivos de programa\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F88 "RS232_11_16F88.asm" /l"RS232_11_16F88.lst" /e"RS232_11_16F88.err" /d__DEBUG=1
Message[302] H:\PIC16F84A\16F88\RS232_11_16F88.ASM 52 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] H:\PIC16F84A\16F88\RS232_11_16F88.ASM 215 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] H:\PIC16F84A\16F88\LCD_4BIT.INC 96 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] H:\PIC16F84A\16F88\LCD_4BIT.INC 110 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] H:\PIC16F84A\16F88\EEPROM.INC 23 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] H:\PIC16F84A\16F88\EEPROM.INC 26 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] H:\PIC16F84A\16F88\EEPROM.INC 28 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] H:\PIC16F84A\16F88\EEPROM.INC 32 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] H:\PIC16F84A\16F88\EEPROM.INC 64 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] H:\PIC16F84A\16F88\EEPROM.INC 70 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] H:\PIC16F84A\16F88\EEPROM.INC 75 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] H:\PIC16F84A\16F88\EEPROM.INC 77 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] H:\PIC16F84A\16F88\EEPROM.INC 78 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] H:\PIC16F84A\16F88\EEPROM.INC 80 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] H:\PIC16F84A\16F88\EEPROM.INC 82 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] H:\PIC16F84A\16F88\EEPROM.INC 83 : Register in operand not in bank 0. Ensure that bank bits are correct.
Executing: "C:\Archivos de programa\Microchip\MPASM Suite\mplink.exe" /p16F88 "RS232_11_16F88.o" /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"RS232_11_16F88.cof" /M"RS232_11_16F88.map" /W /x
MPLINK 4.35, Linker
Copyright (c) 2009 Microchip Technology Inc.
Errors : 0

Loaded H:\PIC16F84A\16F88\RS232_11_16F88.cof.
----------------------------------------------------------------------
Debug build of project `H:\PIC16F84A\16F88\PicRS232_16F88.mcp' succeeded.
Language tool versions: MPASMWIN.exe v5.35, mplink.exe v4.35
Preprocessor symbol `__DEBUG' is defined.
Thu Dec 31 20:21:43 2009
----------------------------------------------------------------------
BUILD SUCCEEDED


Looking at the datasheet I intet looking at the examples on page 31. 16F88.


Code:
; Leer EEPROM.
EEPROM_LeeDato
    BANKSEL EEADR ; Select Bank of EEADR
    MOVF ADDR, W ;
    MOVWF EEADR ; Data Memory Address
    ; to read
    BANKSEL EECON1 ; Select Bank of EECON1
    BCF EECON1, EEPGD; Point to Data memory
    BSF EECON1, RD ; EE Read
    BANKSEL EEDATA ; Select Bank of EEDATA
    MOVF EEDATA, W ; W = EEDATA
    return











; Escribir EEPROM.



    CBLOCK
    EEPROM_GuardaINTCON
    ENDC

EEPROM_EscribeDato
    BANKSEL EECON1 ; Select Bank of
    ; EECON1
    BTFSC EECON1, WR ; Wait for write
    GOTO $-1 ; to complete
    BANKSEL EEADR ; Select Bank of
    ; EEADR
    MOVF ADDR, W ;
    MOVWF EEADR ; Data Memory
    ; Address to write
    MOVF VALUE, W ;
    MOVWF EEDATA ; Data Memory Value
    ; to write
    BANKSEL EECON1 ; Select Bank of
    ; EECON1
    BCF EECON1, EEPGD ; Point to DATA
    ; memory
    BSF EECON1, WREN ; Enable writes
    BCF INTCON, GIE ; Disable INTs.
    MOVLW 55h ;
    MOVWF EECON2 ; Write 55h
    MOVLW AAh ;
    MOVWF EECON2 ; Write AAh
    BSF EECON1, WR ; Set WR bit to
    ; begin write
    BSF INTCON, GIE ; Enable INTs.
    BCF EECON1, WREN ; Disable writes

Goddbey.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top