Code:
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=%11100011 'set PORTA as all input apart from A2,A3 & A4
TRISB=%00000000 'set PORTB as all output
DATA @1,word 625,0,word 545,word 750 ' pre-setting EEPROM
@RC_OSC_NOCLKOUT
@WDT_ON
@PWRT_ON
@MCLR_OFF
@BOD_ON
@LVP_OFF
@CPD_OFF
@PROTECT_OFF
;set up pattern data
Patt1 DATA 17,16,1,2,4,8,16,32,64,128,128,64,32,16,8,4,2,1
Patt2 DATA 9,8,129,66,36,24,24,36,66,129
Patt3 DATA 17,16,1,3,2,6,4,12,8,24,16,48,32,96,64,192,128,0
Patt4 DATA 17,16,1,128,2,64,4,32,8,16,8,32,4,64,2,128,1,0
Patt5 DATA 13,12,24,60,126,255,231,195,129,0,129,195,231,255
Patt6 DATA 14,13,1,2,4,8,17,34,68,136,16,32,64,128,0
Patt7 DATA 9,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
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
SWcount var byte ;used as a place holder for patterns
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>4 then swcount=4 ;error trap for exceeding max patterns
If SWcount<1 then swcount=1 ;error trap for exceeding min patterns
TRISB = 0
READ Patt1, steps ;get number of EEPROM entries
FOR counts = 1 TO steps ;advance to through the entries
READ (Patt1+counts), PORTB ;read the next entry and send the result to PORTB
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
END
When this is compiled I was expecting the PIC to run through just the first pattern in the sequence (Patt1). But the instead it cycles in a loop through all 7 sequences and then lights all LEDS on portB for a short period (about the same as that set by D ) and then repeats over and over.
Bookmarks