;	25-03-2008
;	Practica 1.ASM
;	Prender y apagar una alarma
;	PIC 16f84a
;	MPLAB 8.00
;	PROTEUS 7.2 SP2
;	Guido Carmona Girón

	LIST	P=16F84A,				; usar PIC 16F84A
	#include <p16f84A.inc>
	errorlevel      -302    			; Eliminar banco mensajes
	__CONFIG _CP_OFF&_PWRTE_ON&_WDT_OFF&_XT_OSC	; code protec		off
							; power up timer	on
							; watchdog		off
							; osc: 4 MHz		XT

PDel0	equ	0C
PDel1	equ	0D


	ORG	0
	BSF	STATUS,5	; activa la pagina 1
	MOVLW	B'00000'	; carga 00000 en W
	MOVWF	TRISA		; puerto a todos salidas
	MOVLW	B'00000000'	; carga 00000000 en W
	MOVWF	TRISB		; puerto b todos salidaS
	BCF	STATUS,5	; volvemos a la pagina 0

	MOVLW	B'00000000'	; ponemos a cero el
	MOVWF	PORTB		; el puerto b
				; usando esta opcion se ahorran
				; 6 bytes

INICIO				; etiqueta
	BSF	PORTB,0		; pone a 1 RB0
	CALL	DEMORA		; llama a demora de 1 seg
	BCF	PORTB,0		; pone a 0 RB0
	CALL	DEMORA		; llama a demora de 1 seg
	GOTO	INICIO		; va a inicio


;------------------------------------------------------------------
; Code generated by PDEL  ver 1.0  on 25/03/2008 at 11:24:21 a.m.
; Description: Waits 500000 cycles
;------------------------------------------------------------------
DEMORA  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
        return              ; 2+2 Done
;------------------------------------------------------------------
END			    ; fin de programa
;------------------------------------------------------------------