I'm learing PBP and although its been a steep learning curve, the support of this forum has been great and I've taken onboard what I've been given.
I'm just playing about with the "flash some LEDs", basic stuff really, and I now have the basis for what could turn into a nice project for some disco lights. I've detailed my code below, which basically has a chase pattern, the speed of which is set by a 10k pot.
However now I would like to add further patterns and ideally store / code them as data strings or binary patters that are repeated, egCode: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=%00000111 'set PORTA as all output apart from A0, A1 and A2 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 varibles PORTBbit var byte 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.2 ;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 ;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 sw2=0 then swcount=swcount-1 ;check to see if down button pressed pause 120 ;debounce delay If swcount>2 then swcount=2 ;error trap for exceeding max patterns If SWcount<1 then swcount=1 ;error trap for exceeding min patterns if swcount=1 then pattern1 ;goto selected pattern based on value if swcount=2 then pattern2 pattern1: ;standard chase pattern 1 - 8 For PORTBbit=0 to 7 if D<5 then D=5 ;set the minimum pause time to 5ms HIGH PORTBbit pause D LOW PORTBbit pause D Next goto main pattern2: ;standard pattern reveresed 8 -1 For PORTBbit=7 to 0 step -1 if D<5 then D=5 HIGH PORTBbit pause D LOW PORTBbit pause D Next goto main
[code]
10000001
01000010
00100100
00011000
00100100
01000010
10000001
or
129, 66, 36, 24, 36, 66,129
[code]
I've browswed through the manual, but can't see any clear reference on how to write these values in a loop to portB. ie something like
[code]
for i = 1 to number of steps
write value to port
make port high
delay
port low
next
[code]
My evential goal would be to use the UART in the chip to communicate with a PC and allow the additional patterns to be uploaded to the PIC.. but I think I had better learn to walk before I start running![]()




Bookmarks