You are on page 1of 5

;********************************************************************** ; PIC16F84A ; ------U-----; [ RA2 RA1 ] ; [ RA3 RA0 ] ; [ RA4 OSC1 ] * ; [ MCL OSC2 ] * ; [ Vss Vdd ] * ; [ RB0 RB7

] * ; [ RB1 RB6 ] ; [ RB2 RB5 ] ; [ RB3 RB4 ] ; ----------; ; This file is a basic code template for assembly code generation * ; on the PICmicro PIC16F84A. This file contains the basic code * ; building blocks to build upon. * ; * ; If interrupts are not used all code presented between the ORG * ; 0x004 directive and the label main can be removed. In addition * ; the variable assignments for 'w_temp' and 'status_temp' can * ; be removed. * ; * ; Refer to the MPASM User's Guide for additional information on * ; features of the assembler (Document DS33014). * ; * ; Refer to the respective PICmicro data sheet for additional * ; information on the instruction set. * ; * ; Template file assembled with MPLAB V4.00.00 and MPASM V2.20.12. * ; * ;********************************************************************** ; * ; Filename: semaforo.asm * ; Date: 06/06/08 * ; File Version: 1.0 * ; * ; Author: Ing. Roberto Moreno Elizalde * ; Company:Electronica Steren SA de CV ; Este programa verifica el estado de los dip switches conectados * ; al puerto A, asignando una cantidad de repeticiones dependiendo * ; del switch activado, para posteriormente ejecutar las rutinas de * ; dos semaforos en el puerto B, las repeticiones sirven para * ; alargar o acortar los tiempos de activacin. * ;********************************************************************** list p=16F84A #include <p16F84A.inc> definitions __CONFIG ; list directive to define processor ; processor specific variable

_CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

;***** VARIABLE DEFINITIONS w EQU 0 f EQU 1 estado EQU 0x03

; w=guardar en w ; f=guardar en el registro

cblock 0x0C PDel0 PDel1 PDel2 repeat repeaux endc ;********************************************************************** ORG 0x000 ; processor reset vector goto main ; go to beginning of program ORG 0x04 ;**Vector de interrupcin main bsf STATUS,RP0 movlw 0x1F movwf PORTA movlw 0x00 movwf PORTB bcf STATUS,RP0

;PA entradas ;PB salida

clrwdt ;************************************************************************ *** clrf PORTB ;Borra el puerto swi0 btfsc PORTA,0 goto swi1 goto tempo0 PORTA,1 goto swi2 goto tempo1 PORTA,2 goto swi3 goto tempo2 PORTA,3 goto tempo4 goto tempo3 0x05 movwf goto 0x01 movwf goto 0x02 repeat intreci repeat intreci

swi1

btfsc

swi2

btfsc

swi3

btfsc

tempo4 movlw

tempo0 movlw

tempo1 movlw

movwf goto tempo2 movlw 0x03 movwf goto 0x04 movwf

repeat intreci repeat intreci repeat

tempo3 movlw

;************************************************************* intreci bcf bsf bsf call call call call bcf bsf call bcf call bsf call bcf call bsf call bcf call bcf bsf bsf call call call call bcf bsf call bcf call DEMORA PORTB,1 ;Apaga el Amarillo1 DEMORA DEMORA PORTB,4 ;Apaga el Amarillo2 DEMORA PORTB,4 ;Enciende el Amarillo2 DEMORA PORTB,4 ;Apaga el Amarillo2 DEMORA PORTB,4 ;Enciende el Amarillo2 DEMORA PORTB,4 ;Apaga el Amarillo2 DEMORA PORTB,0 ;Apaga el rojo 1 PORTB,2 ;Enciende el Verde1 PORTB,5 ;Enciende el Rojo2 PDelay PDelay PDelay PDelay PORTB,2 ;Apaga el verde1 PORTB,1 ;Enciende el Amarillo1 PORTB,5 ;Apaga el rojo2 PORTB,0 ;Enciende el rojo1 PORTB,3 ;Enciende el verde2 PDelay PDelay PDelay PDelay PORTB,3 ;Apaga el verde2 PORTB,4 ;Enciende el Amarillo2

bsf call bcf call bsf call bcf call goto

PORTB,1 ;Enciende el Amarillo1 DEMORA PORTB,1 ;Apaga el Amarillo1 DEMORA PORTB,1 ;Enciende el Amarillo1 DEMORA PORTB,1 ;Apaga el Amarillo1 DEMORA swi0

;************************************************************************ *** PDelay movf repeat,w movwf repeaux PDelay1 movlw .239 ; 1 set number of repetitions (B) movwf PDel0 ; 1 | PLoop1 movlw .232 ; 1 set number of repetitions (A) movwf PDel1 ; 1 | PLoop2 clrwdt ; 1 clear watchdog PDelL1 goto PDelL2 ; 2 cycles delay PDelL2 goto PDelL3 ; 2 cycles delay PDelL3 clrwdt ; 1 cycle delay decfsz PDel1, 1 ; 1 + (1) is the time over? (A) goto PLoop2 ; 2 no, loop decfsz PDel0, 1 ; 1 + (1) is the time over? (B) goto PLoop1 ; 2 no, loop PDelL4 goto PDelL5 ; 2 cycles delay PDelL5 goto PDelL6 ; 2 cycles delay PDelL6 goto PDelL7 ; 2 cycles delay PDelL7 clrwdt ; 1 cycle delay decfsz repeaux,f goto PDelay1 return ; 2+2 Done ;************************************************************************ *********** DEMORA PLoop01 PLoop11 PLoop21 movlw .14 movwf PDel0 movlw .72 movwf PDel1 movlw .247 movwf PDel2 clrwdt decfsz PDel2, 1 goto PLoop21 decfsz PDel1, 1 goto PLoop11 decfsz PDel0, 1 goto PLoop01 goto PDelL21 clrwdt ; 1 set numero de repeticion (C) ; 1 | ; 1 set numero de repeticion (B) ; 1 | ; 1 set numero de repeticion (A) ; 1 | ; 1 clear watchdog ; 1 + (1) es el tiempo 0 ? (A) ; 2 no, loop ; 1 + (1) es el tiempo 0 ? (B) ; 2 no, loop ; 1 + (1) es el tiempo 0 ? (C) ; 2 no, loop ; 2 ciclos delay ; 1 ciclo delay

PDelL11 PDelL21

return end

; 2+2 Fin.

You might also like