El lenguaje Ensamblador para programar micro-controladores tiene grandes ventajas, debido a que permite controlar a nivel mas básico el programa, especialmente es útil en aplicaciones donde el tiempo deba ser preciso.
PROGRAMA USO DEL TECLADO PIC 16F887
En el siguiente programa se muestra el despliegue de los números de un teclado mediante 6 displays. El teclado esta conectado al puerto B. Ademas el programa esta elaborado en MPLAB y ademas contiene su simulación adjunta en Proteus
TECLADO Y DISPLAYS KS
Código en Ensamblador del PIC16F887
LIST P=16F887
INCLUDE
tecla EQU 0x20
num_tecla EQU 0x21
barrido_display EQU 0x22
ayuda EQU 0x24
cont1_pausa EQU 0x25
cont2_pausa EQU 0X26
cont3_pausa EQU 0X27
contador_barrido_display EQU 0x28
display1 EQU 0x29
display2 EQU 0x2A
display3 EQU 0x2B
display4 EQU 0x2C
display5 EQU 0x2D
display6 EQU 0x2F
ORG 0X00
goto INICIO
ORG 0x10
INICIO:
clrf contador_barrido_display
clrf barrido_display
clrf num_tecla
clrf ayuda
clrf cont1_pausa
clrf cont2_pausa
movlw 0x01
movwf cont3_pausa
bsf STATUS,RP0
bsf STATUS,RP1
clrf ANSELH
bcf OPTION_REG,NOT_RBPU
bcf STATUS,RP1
bsf STATUS,RP0
movlw 0xF0
movwf TRISB
clrf TRISC
clrf TRISD
bcf STATUS,RP0
bcf STATUS,RP1
movlw 0xF0
movwf PORTB
clrf PORTC
movlw 0xFF
movwf PORTC
movwf display1
movwf display2
movwf display3
movwf display4
movwf display5
movwf display6
clrf PORTD
BARRIDO_DISPLAY:
clrf num_tecla
call TABLA_POSICIONES
movwf barrido_display
movwf PORTD
movlw 0x00
xorwf contador_barrido_display,W
btfss STATUS,Z
goto DISPLAY2
movfw display1
movwf PORTC
goto SIGUIENTE_DISPLAY
DISPLAY2:
movlw 0x01
xorwf contador_barrido_display,W
btfss STATUS,Z
goto DISPLAY3
movfw display2
movwf PORTC
goto SIGUIENTE_DISPLAY
DISPLAY3:
movlw 0x02
xorwf contador_barrido_display,W
btfss STATUS,Z
goto DISPLAY4
movfw display3
movwf PORTC
goto SIGUIENTE_DISPLAY
DISPLAY4:
movlw 0x03
xorwf contador_barrido_display,W
btfss STATUS,Z
goto DISPLAY5
movfw display4
movwf PORTC
goto SIGUIENTE_DISPLAY
DISPLAY5
movlw 0x04
xorwf contador_barrido_display,W
btfss STATUS,Z
goto DISPLAY6
movfw display5
movwf PORTC
goto SIGUIENTE_DISPLAY
DISPLAY6
movfw display6
movwf PORTC
SIGUIENTE_DISPLAY:
incf contador_barrido_display,F
0xF0
movlw 0xF0
xorwf PORTB,W
btfss STATUS,Z
goto PASO2
goto RETARDO
PASO2:
movwf tecla
bcf STATUS,RP1
bsf STATUS,RP0
movlw 0x0F
movwf TRISB
bcf STATUS,RP0
bcf STATUS,RP1
movlw 0x0F
movwf PORTB
movlw 0x0F
xorwf PORTB,W
iorwf tecla,F
movlw 0xFF
movwf PORTC
movlw 0x03
movwf cont3_pausa
PAUSA
decfsz cont1_pausa
goto PAUSA
decfsz cont2_pausa
goto PAUSA
decfsz cont3_pausa
goto PAUSA
clrf cont1_pausa
clrf cont2_pausa
16
movlw 0x88
xorwf tecla,W
btfsc STATUS,Z
goto FIN_PREGUNTA
12
incf num_tecla,F
movlw 0x84
xorwf tecla,W
btfsc STATUS,Z
goto FIN_PREGUNTA
8
incf num_tecla,F
movlw 0x82
xorwf tecla,W
btfsc STATUS,Z
goto FIN_PREGUNTA
4
incf num_tecla,F
movlw 0x81
xorwf tecla,W
btfsc STATUS,Z
goto FIN_PREGUNTA
15
incf num_tecla,F
movlw 0x48
xorwf tecla,W
btfsc STATUS,Z
goto FIN_PREGUNTA
11
incf num_tecla,F
movlw 0x44
xorwf tecla,W
btfsc STATUS,Z
goto FIN_PREGUNTA
7
incf num_tecla,F
movlw 0x42
xorwf tecla,W
btfsc STATUS,Z
goto FIN_PREGUNTA
incf num_tecla,F
movlw 0x41
xorwf tecla,W
btfsc STATUS,Z
goto FIN_PREGUNTA
incf num_tecla,F
movlw 0x28
xorwf tecla,W
btfsc STATUS,Z
goto FIN_PREGUNTA
incf num_tecla,F
movlw 0x24
xorwf tecla,W
btfsc STATUS,Z
goto FIN_PREGUNTA
incf num_tecla,F
movlw 0x22
xorwf tecla,W
btfsc STATUS,Z
goto FIN_PREGUNTA
incf num_tecla,F
movlw 0x21
xorwf tecla,W
btfsc STATUS,Z
goto FIN_PREGUNTA
incf num_tecla,F
movlw 0x18
xorwf tecla,W
btfsc STATUS,Z
goto FIN_PREGUNTA
incf num_tecla,F
movlw 0x14
xorwf tecla,W
btfsc STATUS,Z
goto FIN_PREGUNTA
incf num_tecla,F
movlw 0x12
xorwf tecla,W
btfsc STATUS,Z
goto FIN_PREGUNTA
incf num_tecla,F
goto FIN_PREGUNTA
FIN_PREGUNTA:
movfw display5
movwf display6
movfw display4
movwf display5
movfw display3
movwf display4
movfw display2
movwf display3
movfw display1
movwf display2
call TABLA_DIGITOS
movwf ayuda
comf ayuda,W
movwf display1
goto RETARDO
TABLA_POSICIONES
movf contador_barrido_display,W
addwf PCL,f
retlw 0x20
retlw 0x10
retlw 0x08
retlw 0x04
retlw 0x02
retlw 0x01
clrf contador_barrido_display
retlw 0x20
TABLA_DIGITOS
movf num_tecla,W
addwf PCL,f
retlw 0xE
retlw 0x01
retlw 0x37
retlw 0x49
retlw 0x05
retlw 0x4F
retlw 0x7D
retlw 0x6F
retlw 0x3F
retlw 0x5B
retlw 0x6D
retlw 0x7F
retlw 0x64
retlw 0x06
retlw 0x66
retlw 0x07
RETARDO
decfsz cont1_pausa
goto RETARDO
clrf cont1_pausa
movlw 0x08
movwf cont2_pausa
movlw 0xFF
movwf PORTC
clrf cont1_pausa
clrf cont2_pausa
bcf STATUS,RP1
bsf STATUS,RP0
movlw 0xF0
movwf TRISB
bcf STATUS,RP0
bcf STATUS,RP1
movlw 0xF0
movwf PORTB
goto BARRIDO_DISPLAY
END