Steve,
Here is the complete code (less the data for light patterns)
Code:
;************* set up PIC ********************
ADCON1=$0F
CMCON = 7 ' Digital inputs
CCP1CON = 0 ' PWM off
TRISA=%11111111 'set PORTA as all input
TRISB=%00000000 'set PORTB as all output
PORTB=0
PORTA=0
SW1 var PORTA.1 ;pattern selection switch
;************* set up variables ***************
Patt var byte [8] ;used to store the sequences
Patt[1]=Patt1
Patt[2]=Patt2
Patt[3]=Patt3
Patt[4]=Patt4
Patt[5]=Patt5
Patt[6]=Patt6
Patt[7]=Patt7
C var byte ;used to advance through pattern
D var byte ;used for the speed the sequence runs at
scale var byte ;used in the POT command
Scale = 254
steps var byte ;used for storing the number of steps in a sequence
swcount var byte ;used to select the required sequence required
swcount=1 ;set for testing only or default sequence
;**************** main program ********************
main:
if sw1=0 then swcount=swcount+1 ;check to see if up button pressed, if so add 1 to SWcount
pause 60 ;debounce delay
If swcount>7 then swcount=1 ;error trap for exceeding max patterns
;Pot PORTA.1,scale,D ;used to read value from 10k pot and set the speed
read patt[swcount],steps ;read the first value of the selected patter and place it in the variable steps
for C = 1 to steps ;for / next loop
READ PATT[SWCOUNT]+ C,PORTB ;reads the step value for selected pattern and send it to PORTB
PAUSE 250 ;delay for speed
NEXT
GOTO MAIN
In this example I've removed the wire from the 10 pot and set SW to the same pin as I have the pot working fine - and it works. If I set SW to RA0, RA2, RA3 etc the LEDs run through each pattern from 1 - 7 in a loop.
As you stated, it must be something is the setting of port A for digital. However I will at some point want one pin to be det up to use the A to D conversion as I want to input the line signal from a CD player to get the LEDs to flash / run to music at some stage in the future, all other inputs.
Sorry if it seems so basic, but as the other Steve can vouch for.. I'm very rusty on the PBP coding !
Bookmarks