TODOPIC

Microcontroladores PIC => Lenguaje Basic para microcontroladores PIC => Mensaje iniciado por: doppel en 04 de Marzo de 2005, 13:16:00

Título: [b]grabar datos sin usar eprom externa[/b]
Publicado por: doppel en 04 de Marzo de 2005, 13:16:00
hola amigos

hemos estado trabajando en un circuito para guardar una clave de 4 digitos
en el pic, pero las pruebas estan hechas en base a un array, por lo que los datos se borran al sacar la alimentacion, el proximo paso que queremos implementar es grabarlo de forma definitiva en el pic, estoy usando un 16f84.-
revisando encontre la forma de hacerlo pero en Asembler por lo que recurro a uds para que me den alguna idea de como hacerlo en PBplus,


Codigo:
Read_Flash bsf STATUS,RP1  
 bcf STATUS,RP0 ;Selecciona el Banco 2
 movf ADDRL,W ;Contenido d la variable a EEADR,
 movwf EEADR ;parte baja de la direccion.
 movf ADDRH,W ;Contenido d la variable a EEADRH,
 movwf EEADRH ;parte alta de la direccion.
 bsf STATUS,RP0 ;Selecciona Banco 3
 bsf EECON1,EEPGD ;habilita acceso a la flash.
 bsf EECON1,RD ;Inicio operacion de lectura.
 nop  ;se esperan dos ciclos
 nop  tal como especifica el datasheet
 bcf STATUS,RP0 ;Selecciona Banco 2
 movf EEDATA,W ;DATAL = parte baja del dato leido
 movwf DATAL  
 movf EEDATAH,W ;DATAH = parte alta del dato leido
 movwf DATAH  
 return





ahora para escribir

Codigo:
Write_Flash bsf STATUS,RP1  
 bcf STATUS,RP0 ;Selecciona el Banco 2
 movf ADDRL,W ;Contenido d la variable a EEADR,
 movwf EEADR ;parte baja de la direccion.
 movf ADDRH,W ;Contenido d la variable a EEADRH,
 movwf EEADRH ;parte alta de la direccion.
 movf DATAL,W ;Se mueve la parte baja del dato
 mowf EEDATA ;a escribir en EEDATA.
 movf DATAH,W ;Se mueve la parte alta del dato
 mowf EEDATAH ;a escribir en EEDATAH.
 bsf STATUS,RP0 ;Selecciona Banco 3
 bsf EECON1,EEPGD ;habilita acceso a la flash.
 bsf EECON1,WREN ;Habilita escritura en la FLASH
 bcf INTCON,GIE ;Deshabilita todas las interrupciones.
 movlw 0x55 ;Secuencia especial de 5 pasos
 movwf EECON2 ;para escribir en la flash
 movlw 0xAA ;
 movwf EECON2 ;
 bsf EECON1,WR ;Inicia la operacion de escritura.
 nop  ;se esperan dos ciclos
 nop  tal como especifica el datasheet
 bsf INTCON,GIE ;Habilita todas interrupciones generales
 bcf EECON1,WREN ;Deshabilita escritura en la FLASH
 return  ;retorna de la interupcción




los ejemplos que encontre estan hechos para el 16f877,  espero sus opiniones y /o sugerencias de como convertirlo a PBplus

saludos

Título: RE: [b]grabar datos sin usar eprom externa[/b]
Publicado por: josemyzm en 08 de Marzo de 2005, 02:47:00
En PB Pro se usan las instrucciones READ y WRITE para manejar la eeprom interna, en Plus supongo que habrá algo parecido. Si por otro lado lo que quieres es grabar los datos en la memoria Flash olvidalo, en el 16F84 no se puede.

Un saludo.
Título: RE: [b]grabar datos sin usar eprom externa[/b]
Publicado por: RGL en 08 de Marzo de 2005, 07:10:00
Los comandos y su explicación:

Syntax

Variable = EREAD Address
 
Overview

Read information from the on-board EEPROM available on some PICmicro types.
 
Operators
Variable - a user defined variable of type bit, byte, byte array, word, word array, dword, or float.
Address - a constant, variable, or expression, that contains the address of interest within EEPROM memory.

Example

 DEVICE 16F84  " A PICmicro with on-board eeprom
 DIM VAR1 as BYTE
 DIM WRD1 as WORD
 DIM DWRD1 as DWORD  
 
 EDATA 10 , 354 , 123456789  " Place some data into the eeprom
 VAR1 = EREAD 0              " Read the 8-bit value from address 0
 WRD1= EREAD 1               " Read the 16-bit value from address 1
 DWRD1 = EREAD 3             " Read the 32-bit value from address 3
 
Notes

If a float, or dword type variable is used as the assignment variable, then 4-bytes will be read from the eeprom. Similarly, if a word type variable is used as the assignment variable, then a 16-bit value (2-bytes)will be read from eeprom, and if a byte type variable is used, then 8-bits will be read. To read an 8-bit value while using a word sized variable, use the LOWBYTE modifier
 
 WRD1.LOWBYTE = EREAD 0 " Read an 8-bit value
 WRD1.HIGHBYTE = 0      " Clear the high byte of WRD
 
If a 16-bit size value is read from the EEPROM, the address must be incremented by two for the next read. Also, if a float or dword type variable is read, then the address must be incremented by 4.
 
Most of the Flash PICmicro types have a portion of memory set aside for storage of information. The amount of memory is specific to the individual PICmicro type, some, such as the 16F84, has 64 bytes, the 16F877 device has 256 bytes, and some of the 16-bit core devices have upwards of 512 bytes. EEPROM memory is non-volatile, and is an excellent place for storage of long-term information, or tables of values. Reading data with the ERead command is almost instantaneous, but writing data to the eeprom can take up to 10ms per byte

EWRITE Address , [ Variable {, Variable…etc } ]
 
Overview

Write information to the on-board EEPROM available on some PICmicro types.
 
Operators
Address is a constant, variable, or expression, that contains the address of interest within eeprom memory.
Variable is a user defined variable of type bit, byte, byte array, word, word array, dword, float or a constant value.

Example

 DEVICE 16F628   " A PICmicro with on-board eeprom
 DIM VAR1 as BYTE
 DIM WRD1 as WORD
 DIM Address as BYTE
 VAR1 = 200
 WRD1= 2456
 Address = 0    " Point to address 0 within the eeprom
 EWRITE Address , [ WRD , VAR1 ] " Write a 16-bit then an 8-bit value
 
Notes

If a dword type variable is used, then a 32-bit value (4-bytes) will be written to the eeprom. Similarly, if a word type variable is used, then a 16-bit value (2-bytes) will be written to eeprom, and if a byte type variable is used, then 8-bits will be written. To write an 8-bit value while using a word sized variable, use the LOWBYTE modifier: -
 
 EWRITE Address , [ WRD.LOWBYTE , VAR1 ]
 
If a 16-bit size value is written to the EEPROM, the address must be incremented by two before the next write: -
 
 FOR Address = 0 TO 64 STEP 2
  EWRITE Address , [ WRD ]
 NEXT
 
Most of the Flash PICmicro types have a portion of memory set aside for storage of information. The amount of memory is specific to the individual PICmicro type, some, such as the 16F84, has 64 bytes, while the newer 16F877, and 18FXXX devices have 256 bytes. EEPROM memory is non-volatile, and is an excellent place for storage of long-term information, or tables of values. Writing data with the EWrite command can take up to 10ms per byte, but reading data from the EEPROM is almost instantaneous

Saludos,
Ricky