Code:
;************ set up PIC *****************
PORTA = 0 ' declare port level BEFORE port direction = safe power-on
CMCON = 7 ' PortA Digital inputs
CCP1CON = 0 ' PWM off
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
D var byte ;used to store the result of the pot on port A1 and thus set timing delay
scale var byte ;used in the POT command
Scale = 254 ;used to set range
SW1 var PORTA.6 ;pattern cycle switch
SW2 var PORTA.0 ;select music or clock
mus var PORTA.2 ;music input pin A2
SWcount var byte ;used to count the button SW1 presses
SWcount2 var byte
swcount=1 ;set 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 ****************
counts = 0 ;set the value of counts to the start of each pattern
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 goto music
pause 60 ;debounce delay
If swcount>7 then swcount=1 ;error trap for exceeding max patterns
gosub sel1 ;go to subroutine to select pattern based on Swcount value
FOR counts = 1 TO steps ;advance to through the entries
gosub sel2 ;go to subroutine to advance through sequence
PAUSE D ;pause period set by varible D
NEXT counts ;advance through loop to next position
goto main: ;go back to the main program and run again
music:
if sw1=0 then swcount=swcount+1 ;cycles through the patterns by adding 1 to SWcount
pause 60 ;debounce delay
If swcount>7 then swcount=1 ;error trap for exceeding max patterns
gosub sel1 ;go to subroutine to select pattern based on SWcount value
If mus = 1 then counts = counts + 1 ;if bass or beat present move to the next step in pattern
gosub sel2 ;go to subroutine to display pattern in current step
If counts = steps then counts = 0 ;if counts then reset counts to 1
goto music: ;go back to the start of the music section
;************* Subroutines *****************
Sel1:
if swcount = 1 then read Patt1, steps ;read the first value in data string patt1 and place it in 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 ;read the next value in patt1 and display it on 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
And this is the warning that I get after it compiles
Bookmarks