;*******************************************************************
;			TITLE:	New 16F88 project
;			AUTHOR:	
;			DATE:	
;*********************************************************************
;*********************************************************************

; This is the system the operator uses to operate the weapon
;*********************************************************************
;			DEFINITIONS
;*********************************************************************
LIST	P = 16F88	;tells the assembler which PIC chip to program for
		
	
;****** REGISTER USAGE ******

;For PIC16F88, user RAM starts at 20h. The following definitions
;(the names are arbitrary) will be found useful in many programs.

        
STATUS	EQU h'03'          ;name program location 3 as STATUS
TRISA	EQU h'05'        ;
PORTA	EQU h'05'          ;name program location 5 as PORTA
TRISB	EQU h'06'        ;
PORTB	EQU h'06'          ;name program location 6 as PORTB

W	EQU h'00'          ;Working register
F	EQU h'01'          ;File
C	EQU h'00'          ;Carry flag
Z	EQU h'02'          ;Zero flag
        
INDF    EQU 00
TMR0    EQU 01
PCL     EQU 02
FSR     EQU 04
EEDATA  EQU 08
EEADR   EQU 09
PCLATH  EQU 0A
INTCON  EQU 0B
OPSHUN  EQU 81
EECON1  EQU 88
EECON2  EQU 89

temp1   EQU 2C    ; delay duration reg1
temp2   EQU 2D    ; delay duration reg2
temp3   EQU 2E    ; delay duration reg3
temp4   EQU 2F    ; delay duration reg4

;CMCON EQU H'1F'	; USED WITH 16F628A
ANSEL EQU H'9B'	; USED WITH 16F88

;*********************************************************************
;			VECTORS
;*********************************************************************

;The PIC16F84 vectors live at the bottom of memory (0000h-0007h)
ORG 00			;Reset vector address
	goto 	start	;Goes to first instruction on reset/power-up
ORG 04          		;Interrupt vector address
ORG 05          		;Start of program memory

	
;*********************************************************************
;			SUBROUTINES
;*********************************************************************

;By convention, subroutines are placed after the vectors so that they
;are at the bottom of memory. This avoids memory bank-switching for
;small programs.

; Delay subroutine 'onems'=1ms,'tenths'=0.1s 'quart'= 1/4s  'half'=1/2s
onems   movlw  h'FD'             ;set up the value of onems          
        movwf  temp1          ;save the value into temp1

again1  nop                   ;no operation
        decfsz temp1,F        ;take 1 away from temp1 and check if 0
        goto   again1         ;if not, continue counting down
        nop                   ;no operation
        return                ;return to operation

tenth   movlw  64             ;set up the value of tenth  
        movwf  temp2          ;save the value to temp2

again2  call   onems          ;call the value of onems
        decfsz temp2,01       ;take 1 away from temp2 and check if 0
        goto   again2         ;if not, contiune counting down
        return                ;return to operation

quart   movlw  h'FF'            ;set up the value of quart   
        movwf  temp3          ;save the value into temp3

again3  call   onems          ;call the value of onems
        decfsz temp3,F        ;take 1 away from temp3 and check if 0
        goto   again3         ;if not, continue counting down
        return                ;return to operation

second  movlw  04             ;set up the value of second
        movwf  temp4          ;save the value to temp4

again4  call   quart          ;call up the value of onems
        decfsz temp4,F        ;take 1 away from temp4 and check if 0
        goto   again4         ;if not, continue counting down
        return                ;return to operation

	
;*********************************************************************
;			MAIN PROGRAM
;*********************************************************************

start   ;CLRF PORTA		; WHEN USING PIC 16F628A MAKE SURE PORTA BITS 0,1,2,3 ARE I/O PINS NOT ANALOGUE INPUT COMPARATOR INPUTS
        ;MOVLW 07
        ;MOVWF CMCON
        ;BCF STATUS,6           

        BANKSEL PORTA	; WHEN USING PIC16F88 MAKE SURE PORTA BITS 0,1,2,3 ARE I/O PINS NOT ANALOGUE INPUT
        CLRF PORTA
        BANKSEL ANSEL
        MOVLW 0x00
        MOVWF ANSEL

ST1     BSF    STATUS,05      ;Move to PAGE 1
        MOVLW  1F             ;Set up Inputs for port A
        MOVWF  TRISA          ;Write WReg to TRISA
        MOVLW  00             ;Set up Inputs for port B
        MOVWF  TRISB          ;Write WReg to TRISB
        BCF    STATUS,05      ;Mover to PAGE 0
        CLRF   PORTB          ;Clear PORTA in its entirety
        CLRF   PORTA          ;Clear PORTB in its entirety
	
T	MOVLW H'FF'
	MOVWF PORTB
	CALL second
	MOVLW H'F0'
	MOVWF PORTB
	CALL second
	GOTO T


;*********************************************************************
;			INTERRUPT SERVICE ROUTINE
;*********************************************************************

;The interrupt service routine (if required) goes here

inter

        END			;all programs must end with this
