Code:
;************ set up PIC *****************
PORTA = 0 ' declare port level BEFORE port direction = safe power-on
CMCON = 7 ' PortA Digital inputs
CCP1CON = 0 ' PWM off
VRCON = 0 ' Voltage reference disabled
OPTION_REG.7 = 0
TRISA=%11100111 'set PORTA as all input apart from A3 & A4
TRISB=%00000000 'set PORTB as all output
@RC_OSC_NOCLKOUT
@WDT_ON
@PWRT_ON
@MCLR_OFF
@BOD_ON
@LVP_OFF
@CPD_OFF
@PROTECT_OFF
;************* set up pattern data **********
Patt1 DATA 16,1,2,4,8,16,32,64,128,128,64,32,16,8,4,2,1
Patt2 DATA 8,129,66,36,24,24,36,66,129
Patt3 DATA 16,1,3,2,6,4,12,8,24,16,48,32,96,64,192,128,0
Patt4 DATA 16,1,128,2,64,4,32,8,16,8,32,4,64,2,128,1,0
Patt5 DATA 12,24,60,126,255,231,195,129,0,129,195,231,255
Patt6 DATA 13,1,2,4,8,17,34,68,136,16,32,64,128,0
Patt7 DATA 8,128,64,32,16,8,4,2,1
;************* set up varibles ************
i var byte ;used for for next loops
M var byte
D var byte ;used to store the result of the pot on port A1
scale var byte ;used in the POT command
Scale = 254 ;used to set range
SW1 var PORTA.6 ;up switch
SW2 var PORTA.0 ;down switch
mus var PORTA.2 ;pin for music input
SWcount var byte ;used as a place holder for patterns selwction
swcount=1 ;set place holder to default to pattern 1
steps VAR BYTE ;used to store the number of steps in the pattern sequence
counts VAR BYTE ;used in the FOR NEXT loop to run through the sequence
;************* main program ****************
Main:
Pot PORTA.1,scale,D ;used to read value from 10k pot
if sw1=0 then swcount=swcount+1 ;check to see if up button pressed, if so add 1 to SWcount
if sw2=0 then swcount=swcount-1 ;check to see if down button pressed if so delete 1 to SWcount
pause 60 ;debounce delay
If swcount>7 then swcount=7 ;error trap for exceeding max patterns
If SWcount<0 then swcount=0 ;error trap for exceeding min patterns
IF swcount = 0 then all:
TRISB = 0
gosub sel1 ;go to subroutine to select pattern
counts = 1 ;set position marker
gosub sel2 ;go to subroutine to advance through sequence
PAUSE D ;pause period set by varible D
If mus = 1 then counts = counts + 1 ;check to see if music trigger is present and if so advance position by 1
If counts > steps then counts =1 ;check to see if at the end of sequence
goto main: ;go back to the main program and run again
;************* Subroutines *****************
Sel1:
if swcount = 1 then read Patt1, steps
if swcount = 2 then read Patt2, steps
If swcount = 3 then read Patt3, steps
if swcount = 4 then read Patt4, steps
if swcount = 5 then read Patt5, steps
If swcount = 6 then read Patt6, steps
If swcount = 7 then Read patt7, steps
return
Sel2:
if swcount = 1 then READ (Patt1+counts), PORTB
if swcount = 2 then READ (Patt2+counts), PORTB
if swcount = 3 then READ (Patt3+counts), PORTB
if swcount = 4 then READ (Patt4+counts), PORTB
if swcount = 5 then READ (Patt5+counts), PORTB
if swcount = 6 then READ (Patt6+counts), PORTB
if swcount = 7 then READ (Patt7+counts), PORTB
RETURN
I also tried modifying the previous arrangement using the for next loop
Bookmarks