;======================================================================
;
; Author        : ADI - Apps
;
; Date          : 13 March 2003
;
; Filename      : DemoCode.asm
;
; Hardware      : ADuC8xx
;
; Description   : Blinks LED continuously.
;                 Pressing Int0 slows LED toggle rate each time 
;                 it is pressed.
;
;======================================================================
$MOD52                        ; Use 8052 predefined Symbols
;Definitions
LED1     EQU     P3.3         ; P3.3 is LED on ADuC814 eval boards
LED2     EQU     P3.4         ; P3.4 is LED on all other ADuC8xx eval boards
FLAG	   BIT     00H          ; define Flag variable

CSEG                          ; Defines the following as a segment of code
ORG     0000H                 ; Load Code at '00H'

         JMP     MAIN         ; Jump to MAIN

;======================================================================
;INT0 ISR (Interrupt Service Routine)
ORG 0003h				;
         INC     A		; Increment Acc
         RETI			; Return from Interrupt

;======================================================================
ORG 060h                      ; Start MAIN outside ISR space
MAIN:	                        ; (main program)
         SETB    IT0          ; INT0 edge triggered
         SETB    EA           ; enable interrupts
         SETB    EX0          ; enable INT0

         CLR     FLAG         ; Clear Bit defined as FLAG

         MOV     A,#01H       ; Initialize A to 1
BLINK:   CPL     LED1         ; blink LED1 using compliment instruction
         CPL     LED2         ; blink LED2 
         CALL    DELAY	      ; Jump to subroutine DELAY
         JNB     FLAG,BLINK   ; If FLAG is still cleared the jump to Blink

;------------------------------------------------------------------
DELAY:                        
         MOV     R0,A         ; Acc holds delay variable
 DLY0:   MOV     R1,#019h     ; Set up delay loop0
 DLY1:   MOV     R2,#0FEh     ; Set up delay loop1
         DJNZ    R2,$         ; Dec R2 & Jump here until R2 is 0
         DJNZ    R1,DLY1      ; Dec R1 & Jump DLY1 until R1 is 0
         DJNZ    R0,DLY0      ; Dec R0 & Jump DLY0 until R0 is 0
         RET                  ; Return from subroutine

;======================================================================
END



