;*******************************************************************
;                       TEMPLATE PROVIDED BY CENTRE
;
;			TITLE:	New PIC project
;			AUTHOR:	
;			DATE:
;******************************************************************
;                       Sequenced Guitar FX gate
;*********************************************************************

;Sequenced guitar gate

;*********************************************************************
;			DEFINITIONS
;*********************************************************************
LIST	P = 16F84	;tells the assembler which PIC chip to program for
#DEFINE PAGE0 	bcf STATUS,5	;sets PAGE0 as the instruction to access memory bank 0		
#DEFINE PAGE1 	bsf STATUS,5	;sets PAGE1 as the instruction to access memory bank 1
#DEFINE	GATE	PORTA,0			;Audio gate pin	
#DEFINE SQPNS	PORTB			;Pins that the sequencer UI are attached to
#DEFINE Prgup	PORTA,1			;sequence change up
#DEFINE Prgdwn	PORTA,2			;Sequence change down
#DEFINE Tap		PORTA,3			;Tap tempo button
	
;****** REGISTER USAGE ******

;For PIC16F84, user RAM starts at 0Ch. 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
        
SEQA	EQU h'0C'	;Sequence bank
SEQB	EQU h'0D'
SEQC	EQU h'0E'
SEQD	EQU h'0F'
SEQE	EQU h'10'

POS		EQU	h'12'	;current position within sequence
CUR		EQU	h'13'	;currently loaded sequence
TEMPO	EQU	h'14'	;Speed of sequence
BANK	EQU	h'15'	;Stores current bank number
SQINM	EQU	h'16'	;Tempory storage for seqpins input
TMR		EQU	h'17'	;Timer for tap tempo
;*********************************************************************
;			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.

; A delay subroutine

DELAY	MOVLW 	TEMPO	; Change the value to alter the delay time.
	MOVWF	temp1	
DELAB	DECFSZ	temp1,F
	GOTO	DELAB
	RETURN


	
;*********************************************************************
;			MAIN PROGRAM
;*********************************************************************

;****** INITIALISATION ******

;The data direction registers TRISA and TRISB live in the special register set. A '1' in
;these registers sets the corresponding port line to an Input, and a
;'0' makes the corresponding line an output.

; You will need to change '?' in lines 96 and 98 to a '0' or a 1' as appropriate.

start	PAGE1			;select special register set		
	movlw	b'00011110'	;set port A data direction to '############'
	movwf	TRISA
	movlw	b'11111111'	;set port B data direction to '############'
	movwf	TRISB	
	PAGE0				;select normal register set			
	MOVLW	d'100'
	MOVWF	TEMPO
	MOVLW	d'1'
	MOVWF	POS
	MOVLW	SEQA
	MOVWF	CUR
	MOVLW	d'1'
	MOVWF	BANK
	MOVLW	d'0'
	MOVWF	SQINM
	MOVLW	TMR
;****** MAIN PROGRAM ******



;*********************************************************************
;			INTERRUPT SERVICE ROUTINE
;*********************************************************************

;The interrupt service routine (if required) goes here

inter

        END			;all programs must end with this






