0% found this document useful (0 votes)
26 views9 pages

Teclado

Uploaded by

Ricardo Alvarado
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views9 pages

Teclado

Uploaded by

Ricardo Alvarado
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

C:\Users\Ricardo AG\Desktop\TECLADOM\TECLADOM.

asm

;
; INSTITUTO POLITECNICO NACIONAL
; CENTRO DE ESTUDIOS CIENTIFICOS Y TECNOLOGICOS NO. 9
; JUAN DE DIOS BATIZ
;
; PRACTICA 2
;
; TIMER 0 (Manejo de LCD para mostrar tiempo)
;
; OBJETIVO:
;
;------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------
;
#include "C:\Program Files (x86)\Microchip\MPASM Suite\P16F877A.INC";
__Config _XT_OSC & _WDT_OFF & _PWRTE_ON & _BODEN_OFF & _LVP_OFF & _CP_OFF;
;
;------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------
; fosc = 4Mhz.
;Ciclo de trabajo del PIC = (1/fosc)*4 = 1us.
;t int =(256-tmr0)*(P)*((1/40000000)*4) = 1 ms;// Tiempo de interrupcion.
;tmr0=131, P=8.
;frec int = 1/t int=874 Hz.
;------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------
;
;VARIABLES.
;
temporal equ 0x20
cont_mili equ 0x21
presc_1 equ 0x22
presc_2 equ 0x23
Seg equ 0x24
M equ 0x25
H equ 0x26
buffer0 equ 0x27
buffer1 equ 0x28
buffer2 equ 0x29
buffer3 equ 0x2A
buffer4 equ 0x2B
buffer5 equ 0x2C
Banderas equ 0x2D
resp_pclath equ 0x2E
resp_w equ 0x2F
resp_status equ 0x30
resp_fsr equ 0x31
;--------------------------------------
;
; Constantes de barrido
;
seg1 equ .0
Ren1 equ 0x70
Ren2 equ 0xB0
Ren3 equ 0xD0
Ren4 equ 0xE0
Col1 equ 0x07
Col2 equ 0x0B
Col3 equ 0x0D
Col4 equ 0x0E
;----------------------------------
;
; Programación de puertos
;
;--- Puerto A
proga equ b'111111'; //PROGRAMACION INICIAL DEL PUERTO A.
;
;--- Puerto B
progb equ b'00001111'; //PROGRAMACION INICIAL DEL PUERTO B
;
;--- Puerto C
1
C:\Users\Ricardo AG\Desktop\TECLADOM\TECLADOM.asm

RS equ .0
E equ .1
K equ .2
progc equ b'11111000'; //PROGRAMACION INICIAL DEL PUERTO C
;
;--- Puerto D
progd equ b'00000000'; //PROGRAMACION INICIAL DEL PUERTO D
;
;--- Puerto E
proge equ b'111'; //PROGRAMACION INICIAL DEL PUERTO E
;
;==========================================================================
;
; Vector Reset
;
org 0x0000;
vec_reset clrf pclath;
goto prog_prin;
;==========================================================================
;
; Vector Interrupción
;
org 0x0004;
vec_int movwf resp_w;
movfw pclath;
movwf resp_pclath;
movfw status;
movwf resp_status;
movfw fsr;
movwf resp_fsr;

btfss intcon,tmr0if
goto salte_int

incf cont_mili,f;
incf presc_1,f;
bcf intcon, tmr0if

movlw Ren4
movwf portb
movfw portb
movwf temporal
movlw 0x0F
andwf temporal,f
movlw Col3
subwf temporal,w
btfsc status,z
bsf banderas,.1
clrf portb

movlw .47;
subwf presc_1,w;
btfss status,z;
goto salte_int
clrf presc_1
incf presc_2,f
movlw .20;
subwf presc_2,w;
btfss status,z;
goto salte_int
bsf banderas,seg1
clrf presc_1
clrf presc_2
goto salte_int

salte_int movlw .131


movwf tmr0
movfw resp_status
movwf status
movfw resp_pclath
movwf pclath
2
C:\Users\Ricardo AG\Desktop\TECLADOM\TECLADOM.asm

movfw resp_fsr
movwf fsr
movfw resp_w

retfie;

;==========================================================================
;
; Programa inicialización
;
prog_ini bsf status, rp0;
movlw 0x02;
movwf option_reg ^0x80;
movlw proga;
movwf trisa ^0x80;
movlw progb;
movwf trisb ^0x80;
movlw progc;
movwf trisc ^0x80;
movlw progd;
movwf trisd ^0x80;
movlw proge;
movwf trise ^0x80;
movlw 0x06;
movwf adcon1 ^0x80;
bcf status, rp0;
movlw 0xa0
movwf intcon
;-----------------------------------
;
; Programa principal
;
prog_prin call prog_ini
call ini_LCD
call ini_RAM
regresa call convierte
call manda_datos
call incrementa_tiempo
call espera
goto regresa

ini_LCD bsf portc,e


nop
bcf portc,rs
movlw 0x38; Selecciona bus de 8 bits, display de 2 lineas y matriz de 5*8 puntos
movwf portd
call pulso_enable
movlw 0x0C; Prende el display y apaga el cursos y su parpadeo
movwf portd
call pulso_enable
movlw 0x01; Limpia el display
movwf portd
call pulso_enable
movlw 0x06; Ajusta la roacion a la derecha del cursor y deja los valores anteriores de la
DDRAM estaticos
movwf portd
call pulso_enable
movlw 0x80; Se ajusta a la direccion 00h de la DDRAM
movwf portd
call pulso_enable
bsf portc,k
nop
bsf portc,rs
return

ini_RAM clrf Seg


clrf M
clrf H
clrf presc_1
clrf presc_2
movlw .131
3
C:\Users\Ricardo AG\Desktop\TECLADOM\TECLADOM.asm

movwf tmr0
clrf portd
bcf portc,rs
movlw 0x02
movwf portd
call pulso_enable
movlw 0x84
movwf portd
call pulso_enable
bsf portc,rs
Movlw 'E';
movwf portd;
call pulso_enable;
movlw 'Q';
movwf portd;
call pulso_enable;
movlw 'U';
movwf portd;
call pulso_enable;
movlw 'I';
movwf portd;
call pulso_enable;
movlw 'P';
movwf portd;
call pulso_enable;
movlw 'O';
movwf portd;
call pulso_enable;
movlw '-';
movwf portd;
call pulso_enable;
movlw '4';
movwf portd;
call pulso_enable

return

convierte movfw seg


movwf temporal
call conversion_ascii
movwf buffer0
swapf seg,w
movwf temporal
call conversion_ascii
movwf buffer1
movfw m
movwf temporal
call conversion_ascii
movwf buffer2
swapf m,w
movwf temporal
call conversion_ascii
movwf buffer3
movfw h
movwf temporal
call conversion_ascii
movwf buffer4
swapf h,w
movwf temporal
call conversion_ascii
movwf buffer5
return

manda_datos bcf portc,rs


movlw 0xc4
movwf portd
call pulso_enable
bsf portc,rs
movfw buffer5
movwf portd
4
C:\Users\Ricardo AG\Desktop\TECLADOM\TECLADOM.asm

call pulso_enable
movfw buffer4
movwf portd
call pulso_enable
movlw ':'
movwf portd
call pulso_enable
movfw buffer3
movwf portd
call pulso_enable
movfw buffer2
movwf portd
call pulso_enable
movlw ':'
movwf portd
call pulso_enable
movfw buffer1
movwf portd
call pulso_enable
movfw buffer0
movwf portd
call pulso_enable
movlw ' '
movwf portd
call pulso_enable
movlw ' '
movwf portd
call pulso_enable
movlw ' '
movwf portd
call pulso_enable
movlw ' '
movwf portd
call pulso_enable

return

conversion_ascii nop
movlw 0x0f
andwf temporal,w
addlw 0x30

return

incrementa_tiempo nop
incf seg,f
movlw 0x0f
andwf seg,w
movwf temporal
movlw 0x0A
xorwf temporal,w
btfss status,z
goto salte_incrementa
movlw .6
addwf seg,f
movlw 0xf0
andwf seg,w
movwf temporal
movlw 0x60
xorwf temporal,w
btfss status,z
goto salte_incrementa
clrf seg
incf m,f
movlw 0x0f
andwf m,w
movwf temporal
movlw 0x0A
xorwf temporal,w
btfss status,z
goto salte_incrementa
5
C:\Users\Ricardo AG\Desktop\TECLADOM\TECLADOM.asm

movlw .6
addwf m,f
movlw 0xf0
andwf m,w
movwf temporal
movlw 0x60
xorwf temporal,w
btfss status,z
goto salte_incrementa
clrf M
movlw 0xf0
andwf h,w
movwf temporal
movlw 0x20
xorwf temporal,w
btfss status,z
goto caso0
incf h,f
movlw 0x0f
andwf h,w
movwf temporal
movlw .4
xorwf temporal,w
btfss status,z
goto salte_incrementa
clrf h
goto salte_incrementa
caso0 incf h,f
movlw 0x0f
andwf h,w
movwf temporal
movlw .10
xorwf temporal,w
btfss status,z
goto salte_incrementa
movlw .6
addwf h,f

salte_incrementa return

espera btfsc banderas,.1


goto cambio_general
btfss banderas,seg1
goto espera
bcf banderas,seg1

return;

pulso_enable nop
bcf portc,e
clrf cont_mili
revisa movlw .7
xorwf cont_mili,w
btfss status,z
goto revisa
bsf portc,e
clrf cont_mili
revisa1 movlw .7
xorwf cont_mili,w
btfss status,z
goto revisa1

return

cambio_general bcf banderas,.1


clrf Seg
clrf M
clrf H
movlw ' '
movwf buffer0
movwf buffer1
6
C:\Users\Ricardo AG\Desktop\TECLADOM\TECLADOM.asm

movwf buffer2
movwf buffer3
movwf buffer4
movwf buffer5
call manda_datos
se_pasa call cambio_hora
movwf temporal
movlw .3
subwf temporal,w
btfsc status,c
goto se_pasa
movlw 0x30
addwf temporal,w
movwf buffer5
swapf temporal,w
movwf H
call manda_datos
call esperams
regresa_bro call cambio_hora
movwf temporal
movlw 0x20
subwf H,w
btfss status,z
goto siguele_bro
movlw .4
subwf temporal,w
btfsc status,c
goto regresa_bro
siguele_bro movfw temporal
addwf H,f
addlw 0x30
movwf buffer4
call manda_datos
call esperams
se_pasa1 call cambio_hora
movwf temporal
movlw .6
subwf temporal,w
btfsc status,c
goto se_pasa1
movlw 0x30
addwf Temporal,w
movwf buffer3
swapf temporal,w
movwf M
call manda_datos
call esperams
call cambio_hora
addwf M,f
addlw 0x30
movwf buffer2
call manda_datos
call esperams
se_pasa2 call cambio_hora
movwf temporal
movlw .6
subwf temporal,w
btfsc status,c
goto se_pasa2
movlw 0x30
addwf temporal,w
movwf buffer1
swapf temporal,w
movwf Seg
call manda_datos
call esperams
call cambio_hora
addwf Seg,f
addlw 0x30
movwf buffer0
call manda_datos
7
C:\Users\Ricardo AG\Desktop\TECLADOM\TECLADOM.asm

call esperams
checaast movlw Ren4
movwf portb
movfw portb
andlw 0x0F
movwf temporal
movlw Col1
subwf temporal,w
btfss status,z
goto checaast
clrf presc_1
clrf presc_2
clrf banderas
goto incrementa_tiempo

cambio_hora movlw Ren1


movwf portb
movfw portb
movwf temporal
movlw 0x0F
andwf temporal,f
movlw Col1
subwf temporal,w
btfsc status,z
goto fue_1
movlw Col2
subwf temporal,w
btfsc status,z
goto fue_2
movlw Col3
subwf temporal,w
btfsc status,z
goto fue_3
movlw Col4
subwf temporal,w
btfsc status,z
goto cambio_hora
movlw Ren2
movwf portb
movfw portb
movwf temporal
movlw 0x0F
andwf temporal,f
movlw Col1
subwf temporal,w
btfsc status,z
goto fue_4
movlw Col2
subwf temporal,w
btfsc status,z
goto fue_5
movlw Col3
subwf temporal,w
btfsc status,z
goto fue_6
movlw Col4
subwf temporal,w
btfsc status,z
goto cambio_hora
movlw Ren3
movwf portb
movfw portb
movwf temporal
movlw 0x0F
andwf temporal,f
movlw Col1
subwf temporal,w
btfsc status,z
goto fue_7
movlw Col2
subwf temporal,w
8
C:\Users\Ricardo AG\Desktop\TECLADOM\TECLADOM.asm

btfsc status,z
goto fue_8
movlw Col3
subwf temporal,w
btfsc status,z
goto fue_9
movlw Col4
subwf temporal,w
btfsc status,z
goto cambio_hora
movlw Ren4
movwf portb
movfw portb
movwf temporal
movlw 0x0F
andwf temporal,f
movlw Col1
subwf temporal,w
btfsc status,z
goto cambio_hora
movlw Col2
subwf temporal,w
btfsc status,z
goto fue_0
movlw Col3
subwf temporal,w
btfsc status,z
goto cambio_hora
movlw Col4
subwf temporal,w
btfsc status,z
goto cambio_hora
goto cambio_hora
fue_0 movlw .0
goto salte_cambio
fue_1 movlw .1
goto salte_cambio
fue_2 movlw .2
goto salte_cambio
fue_3 movlw .3
goto salte_cambio
fue_4 movlw .4
goto salte_cambio
fue_5 movlw .5
goto salte_cambio
fue_6 movlw .6
goto salte_cambio
fue_7 movlw .7
goto salte_cambio
fue_8 movlw .8
goto salte_cambio
fue_9 movlw .9

salte_cambio return

esperams clrf cont_mili

espera50 movlw .100


subwf cont_mili,w
btfss status,z
goto espera50

return

end

You might also like