6
;********************************************************************** ; 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 *

semáforo

Embed Size (px)

Citation preview

Page 1: semáforo

;**********************************************************************; 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 *

Page 2: semáforo

; dos semaforos en el puerto B, las repeticiones sirven para *; alargar o acortar los tiempos de activación. *;**********************************************************************

list p=16F84A ; list directive to define processor#include <p16F84A.inc> ; processor specific variable

definitions

__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

;***** VARIABLE DEFINITIONSw EQU 0 ; w=guardar en wf EQU 1 ; f=guardar en el registroestado EQU 0x03

cblock 0x0CPDel0PDel1PDel2repeatrepeaux

endc;**********************************************************************

ORG 0x000 ; processor reset vector goto main ; go to beginning of program

ORG 0x04 ;**Vector de interrupción

main bsf STATUS,RP0movlw 0x1Fmovwf PORTA ;PA entradasmovlw 0x00movwf PORTB ;PB salida

bcf STATUS,RP0

clrwdt;***************************************************************************

clrf PORTB ;Borra el puerto

swi0 btfsc PORTA,0goto swi1goto tempo0

swi1 btfsc PORTA,1goto swi2goto tempo1

swi2 btfsc PORTA,2goto swi3goto tempo2

swi3 btfsc PORTA,3goto tempo4goto tempo3

Page 3: semáforo

tempo4 movlw 0x05movwf repeatgoto intreci

tempo0 movlw 0x01movwf repeatgoto intreci

tempo1 movlw 0x02movwf repeatgoto intreci

tempo2 movlw 0x03movwf repeatgoto intreci

tempo3 movlw 0x04movwf repeat

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

intreci bcf PORTB,5 ;Apaga el rojo2bsf PORTB,0 ;Enciende el rojo1bsf PORTB,3 ;Enciende el verde2call PDelaycall PDelaycall PDelaycall PDelay

bcf PORTB,3 ;Apaga el verde2

bsf PORTB,4 ;Enciende el Amarillo2call DEMORA

bcf PORTB,4 ;Apaga el Amarillo2call DEMORA

bsf PORTB,4 ;Enciende el Amarillo2call DEMORA

bcf PORTB,4 ;Apaga el Amarillo2call DEMORA

bsf PORTB,4 ;Enciende el Amarillo2call DEMORA

bcf PORTB,4 ;Apaga el Amarillo2call DEMORA

bcf PORTB,0 ;Apaga el rojo 1bsf PORTB,2 ;Enciende el Verde1bsf PORTB,5 ;Enciende el Rojo2call PDelaycall PDelay

Page 4: semáforo

call PDelaycall PDelay

bcf PORTB,2 ;Apaga el verde1

bsf PORTB,1 ;Enciende el Amarillo1call DEMORA

bcf PORTB,1 ;Apaga el Amarillo1call DEMORA

bsf PORTB,1 ;Enciende el Amarillo1call DEMORA

bcf PORTB,1 ;Apaga el Amarillo1call DEMORA

bsf PORTB,1 ;Enciende el Amarillo1call DEMORA

bcf PORTB,1 ;Apaga el Amarillo1call DEMORA

goto swi0

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

PDelay movf repeat,wmovwf 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 watchdogPDelL1 goto PDelL2 ; 2 cycles delayPDelL2 goto PDelL3 ; 2 cycles delayPDelL3 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, loopPDelL4 goto PDelL5 ; 2 cycles delayPDelL5 goto PDelL6 ; 2 cycles delayPDelL6 goto PDelL7 ; 2 cycles delayPDelL7 clrwdt ; 1 cycle delay

decfsz repeaux,fgoto PDelay1

return ; 2+2 Done;***********************************************************************************

DEMORA movlw .14 ; 1 set numero de repeticion (C) movwf PDel0 ; 1 |

Page 5: semáforo

PLoop01 movlw .72 ; 1 set numero de repeticion (B) movwf PDel1 ; 1 |PLoop11 movlw .247 ; 1 set numero de repeticion (A) movwf PDel2 ; 1 |PLoop21 clrwdt ; 1 clear watchdog decfsz PDel2, 1 ; 1 + (1) es el tiempo 0 ? (A) goto PLoop21 ; 2 no, loop decfsz PDel1, 1 ; 1 + (1) es el tiempo 0 ? (B) goto PLoop11 ; 2 no, loop decfsz PDel0, 1 ; 1 + (1) es el tiempo 0 ? (C) goto PLoop01 ; 2 no, loopPDelL11 goto PDelL21 ; 2 ciclos delayPDelL21 clrwdt ; 1 ciclo delay return ; 2+2 Fin.

end