Created
December 7, 2014 01:42
-
-
Save giobyte8/4c96aafb0d0c30edf203 to your computer and use it in GitHub Desktop.
Lee un número binario de 4 bits del PORTA, escribe ese número a la memoria EEPROM interna del microcontrolador, hace una pequeña pausa, lee el número de la memoria EEPROM y escribe el número leido al PORTB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; | |
; Archivo helloEEPROM.asm | |
; FUNCIONA CON UN PIC16F84A | |
; | |
; @author: DiganmeGiovanni | |
; | |
; Lee un número binario de 4 bits del PORTA, escribe ese número a la | |
; memoria EEPROM interna del microcontrolador, hace una pequeña pausa, | |
; lee el número de la memoria EEPROM y escribe el número leido al | |
; PORTB | |
; | |
;** Algunas instrucciones de configuración | |
processor 16f84 | |
include<p16f84.inc> | |
__config _RC_OSC & _WDT_OFF & _PWRTE_ON | |
;** DIRECCIONES UTILES PARA LOS DELAYS | |
J EQU H'1F' | |
K EQU H'1E' | |
;** Inicia en la dirección 0 | |
org 0 | |
;** Configura el PORTB como salidas | |
BSF STATUS, RP0 ; Ir a banco 1 | |
MOVLW B'00000000' | |
MOVWF TRISB | |
BCF STATUS, RP0 ; Ir a banco 0 | |
;** Si RA0=1 enviara a leer la EEPROM | |
TEAM9: | |
CALL EEPW | |
GOTO EEPR | |
;** Leer de la EEPROM | |
EEPR: | |
BCF STATUS, RP0 ; Ir a banco 0 | |
MOVLW H'02' ; Dirección de lectura | |
MOVWF EEADR | |
BSF STATUS, RP0 ; Ir a banco 1 | |
BSF EECON1, RD ; Iniciar lectura de EEPROM | |
BCF STATUS, RP0 ; Ir a banco 0 | |
MOVF EEDATA, W ; Mostrar datos leeidos en PORTB | |
MOVWF PORTB | |
CALL DELAY | |
GOTO TEAM9 | |
;** Escribir en la EEPROM | |
EEPW: | |
MOVLW B'00010000' ; Notifica por led de la escritura en curso | |
MOVWF PORTB | |
MOVF PORTA, W ; Dato a escribir tomado del PORTA | |
MOVWF EEDATA | |
MOVLW H'02' ; Dirección de escritura | |
MOVWF EEADR | |
BSF STATUS, RP0 ; Cambiar a banco 1 | |
BCF INTCON, GIE ; Dehabilitar interrupciones | |
BSF EECON1, WREN ; Activar bit de 'enable-write' | |
MOVLW 55h ; Secuencia requerida | |
MOVWF EECON2 | |
MOVLW 0AAh | |
MOVWF EECON2 | |
BSF EECON1, WR ; Iniciar secuencia de escritura | |
BTFSS EECON1, EEIF ; Esperar a que la secuencia de escritura termine | |
GOTO $-1 | |
BSF INTCON, GIE ; Habilitar interrupciones | |
BCF EECON1, WREN ; Desactivar bit de 'enable-write' | |
BCF EECON1, EEIF | |
BCF STATUS, RP0 ; Regresar al banco 0 | |
CALL DELAY ; Una ligera pausa para apreciar el led indicador de escritura | |
RETURN | |
;** Delay | |
DELAY: | |
CALL DODEL | |
CALL DODEL | |
CALL DODEL | |
CALL DODEL | |
CALL DODEL | |
CALL DODEL | |
RETURN | |
DODEL: | |
MOVLW D'255' | |
MOVWF J | |
JLOOP: | |
MOVWF K | |
KLOOP: | |
DECFSZ K, F ; K = K-1 ... SALTA SIG INSTRUCCION SI = 0 | |
GOTO KLOOP | |
DECFSZ J, F ; K = K-1 ... SALTA SIG INSTRUCCION SI = 0 | |
GOTO JLOOP | |
RETURN | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the program (compiled with MPLAB in my case) with a circuit like this:
The 4 leds on right side displays the number readed from EEPROM, the blue led turn on when EEPROM is writing.