Você está na página 1de 14

INSTITUTO POLITÉCNICO NACIONAL

ESCUELA SUPERIOR DE INGENIERÍA


MECÁNICA Y ELÉCTRICA
UNIDAD ZACATENCO
PROYECTO
SISTEMA DE APERTURA DE PUERTA
Alumnos
Antonio Hurtado y Dagda
Raúl Alejandro Crisóstomo Avilés

6CM3
Electrónica Digital
31-Mayo-2016
DIAGRAMA DE FLUJO

MAIN

CONFIGURAR PUERTOS
CONFIGURAR INTERRUPCION

SLEEP
ISR_INT0

CALL ABRIR

CONTADOR=15

CALL RETARDO

CONTADOR=0?

CALL CERRAR

LIMPIAR BANDERAS

RETFIE
ABRIR

LATA=LETRA A
AUX=12
LATD=EEh

CALL RETARDO

LATD<<

CALL RETARDOM

AUX=0?

RETURN
CERRAR

AUX=12
LATD=EEh

CALL RETARDO

LATD>>

CALL RETARDOM

AUX=0?

LATA=00h

RETURN
RETARDO

CONFIGURAR TIMER
ENCENDER EL TIMER

TMR0IF=1?

APAGAR TIMER
LIMPIAR BANDERA

RETURN

RETARDOM

CONFIGURAR TIMERM
ENCENDER EL TIMER

TMR0IF=1?

APAGAR TIMER
LIMPIAR BANDERA

RETURN
CONFIGURAR TIMER

CARGAR LOS REGISTROS PARA


1 SEGUNDO

LIMPIAR BANDERAS

RETURN

CONFIGURAR TIMERM

CARGAR LOS REGISTROS PARA


50 MILISEGUNDOS

LIMPIAR BANDERAS

RETURN
CODIGO
;******************************************************************************
; This file is a basic template for assembly code for a PIC18F4550. Copy *
; this file into your project directory and modify or add to it as needed. *
; *
; The PIC18FXXXX architecture allows two interrupt configurations. This *
; template code is written for priority interrupt levels and the IPEN bit *
; in the RCON register must be set to enable priority levels. If IPEN is *
; left in its default zero state, only the interrupt vector at 0x008 will *
; be used and the WREG_TEMP, BSR_TEMP and STATUS_TEMP variables will not *
; be needed. *
; *
; Refer to the MPASM User's Guide for additional information on the *
; features of the assembler. *
; *
; Refer to the PIC18FXX50/XX55 Data Sheet for additional *
; information on the architecture and instruction set. *
; *
;******************************************************************************
; *
; Filename: Display A mediante interrupciones *
; Date: 29/05/16 *
; File Version: 1.0 *
; *
; Author: Ing. Alejandro Vicente Lugo Silva *
; Company: Acad. Computación ICE - ESIME Zac. *
; *
;******************************************************************************
; *
; Files required: P18F4550.INC *
; *
;******************************************************************************

LIST P=18F4550, F=INHX32 ;directive to define processor


#include <P18F4550.INC> ;processor specific variable definitions

;******************************************************************************
;Configuration bits

CONFIG PLLDIV = 5 ;(20 MHz crystal on PICDEM FS USB board)


CONFIG CPUDIV = OSC1_PLL2
CONFIG USBDIV = 2 ;Clock source from 96MHz PLL/2
CONFIG FOSC = HSPLL_HS
CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG PWRT = OFF
CONFIG BOR = ON
CONFIG BORV = 3
CONFIG VREGEN = ON ;USB Voltage Regulator
config WDT = OFF
config WDTPS = 32768
config MCLRE = ON
config LPT1OSC = OFF
config PBADEN = OFF ;NOTE: modifying this value here won't have an effect
;on the application. See the top of the
main() function.
;By default the RB4 I/O pin is used to
detect if the
;firmware should enter the bootloader or
the main application
;firmware after a reset. In order to do
this, it needs to
;configure RB4 as a digital input, thereby
changing it from
;the reset value according to this
configuration bit.
config CCP2MX = ON
config STVREN = ON
config LVP = OFF
config ICPRT = OFF ; Dedicated In-Circuit Debug/Programming
config XINST = OFF ; Extended Instruction Set
config CP0 = OFF
config CP1 = OFF
config CP2 = OFF
config CP3 = OFF
config CPB = OFF
config CPD = OFF
config WRT0 = OFF
config WRT1 = OFF
config WRT2 = OFF
config WRT3 = OFF
config WRTB = OFF ; Boot Block Write Protection
config WRTC = OFF
config WRTD = OFF
config EBTR0 = OFF
config EBTR1 = OFF
config EBTR2 = OFF
config EBTR3 = OFF
config EBTRB = OFF
;******************************************************************************
;Variable definitions
; These variables are only needed if low priority interrupts are used.
; More variables may be needed to store other special function registers used
; in the interrupt routines.
CONTADOR EQU 0X00
AUX EQU 0X01
;******************************************************************************
;Reset vector
; This code will start executing when a reset occurs.

RESET_VECTOR ORG 0

goto Inicio ;go to start of main code

;******************************************************************************

;******************************************************************************
;Start of main program
; The main program code is placed here.
ORG 0x1000 ;Inicio de la ISR del Reset
Inicio
goto Main
;******************************************************************************
ORG 0X1008 ;Inicio de la ISR de alta prioridad
goto ISR_INT0
retfie
;******************************************************************************
ORG 0x1018 ;Inicio de la ISR de baja prioridad

retfie
;******************************************************************************

ORG 0x1030 ; *** main code goes here **


Main
call Confpuertos
call Conf_Int
;call Conf_Timer

ciclo
sleep
goto ciclo
; end of main
;******************************************************************************
; Confpuertos- Define las líneas de E/S
;******************************************************************************
Confpuertos
movlw 0x0F ;Configuración de los puertos en modo digital
movwf ADCON1
clrf TRISD ;Puerto D son salidas todos las terminales.
clrf LATD ;Salidas apagadas inicialmente por seguridad.
CLRF TRISA ;Puerto A son salidas todos las terminales.
MOVLW 0XFF
MOVWF LATD ;Salidas apagadas inicialmente por seguridad.

return
;******************************************************************************
; Conf_Int- Configuración del modo de operación del timer 0
;******************************************************************************
Conf_Int
movlw 0xB0 ;Habilitas int_ext y timer 1011 0000
movwf INTCON
return

;******************************************************************************
; Conf_Timer- Configuración del modo de operación del timer 0
;******************************************************************************
Conf_Timer
movlw 0x07 ; configuracion medio segundo 0000 0110
movwf T0CON
movlw 0x48
movwf TMR0H
movlw 0xE5
movwf TMR0L
bcf INTCON,TMR0IF ;cero las banderas de la int
return

;******************************************************************************
; ISR_INT0
;******************************************************************************
ISR_INT0
CALL ABRIR
MOVLW 0X0E; 0X0F
MOVWF CONTADOR
MAMA
CALL RETARDO
DECFSZ CONTADOR
GOTO MAMA
CALL CERRAR

bcf INTCON,TMR0IF
bcf INTCON,INT0IF
MOVLW 0XFF
MOVWF LATD
retfie

RETARDO
call Conf_Timer
bsf T0CON,7 ;Enciendes el timer
cicloISR ; flanco de subida
btfss INTCON,TMR0IF ; compara y salta si es 1
goto cicloISR
bcf T0CON,7 ;apagas el timer
bcf INTCON,TMR0IF
RETURN

ABRIR
movlw 0xFF ;letra A en el puerto D
movwf LATA
MOVLW D'12';PASOS PARA 90°
MOVWF AUX
MOVLW 0XEE
MOVWF LATD
CALL RETARDOM
MOVERI RLNCF LATD
CALL RETARDOM
DECFSZ AUX
GOTO MOVERI
RETURN

CERRAR MOVLW D'12';PASOS PARA 90°


MOVWF AUX
CALL RETARDOM
MOVERD RRNCF LATD
CALL RETARDOM
DECFSZ AUX
GOTO MOVERD
MOVLW 0X00
movwf LATA
RETURN
RETARDOM
CALL CONFIGT0M
CALL RUTINAM
RETURN

CONFIGT0M
movlw 0x03 ; configuracion de 0000 0011
movwf T0CON ; Configuracion para 30ms
movlw 0x6D ; configuracion d'54286'=D40E
movwf TMR0H
movlw 0x84
movwf TMR0L
bcf INTCON,2
return
RUTINAM
BSF T0CON,7
UNO BTFSS INTCON,TMR0IF
GOTO UNO
bcf INTCON,TMR0IF
bcf INTCON,7
RETURN
;******************************************************************************
;End of program
END
DIAGRAMA

Você também pode gostar