;====================================================================
; CPE 345 LAB 03 FILE 3
; Created:   Sun Oct 23 2022
; Processor: PIC16F877A
; Compiler:  MPASM (Proteus)
;====================================================================

;====================================================================
; DEFINITIONS
;====================================================================

#include p16f877a.inc                ; Include register definition file

;====================================================================
; RESET and INTERRUPT VECTORS
;====================================================================

      ; Reset Vector
RST   code  0x0 
      goto  Start

;====================================================================
; CODE SEGMENT
;====================================================================

PGM   code
Start
CountOuter0	equ	D'2';
CountInner0	equ	D'6';

	cblock	0x28
	        pointer
		CountOuter
		CountInner
        
	endc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Initialise Port B 
     org 0xc   
	BANKSEL	TRISB		; Select bank 1
    MOVLW   b'00000000'    	; Port B Direction Code
    MOVWF	TRISB          	; Load the DDR code into F86
    BANKSEL	PORTB		; Select bank 0
	GOTO	reset		; Jump to main loop


; 'delay' subroutine ........................................
        

delay
	movlw	CountOuter0;
	movwf	CountOuter;
DecO	
	movlw	CountInner0;
	movwf	CountInner;
DecI	
	nop;
	decfsz	CountInner, F;
	goto	DecI;
	decfsz	CountOuter, F;
	goto	DecO;	
	return;
;..........................................................
table:addwf PCL,1;
     RETLW 51;
     RETLW 67;
     retlw 30;
     retlw 11;
     retlw 40;


; Start main loop ...........................................

reset:clrf pointer;
loop:movf pointer,0;
      call table;
      movwf PORTB;
      call delay;
      incf pointer,1;
      btfss pointer,2;
      goto  loop; 
      goto $;
 END               	; Terminate source code
   