In SX Microcontrollers, SX/B Compiler and SX-Key Tool, capdiamont wrote: The other thing is I use two word variables for counts down. Do loop, etc seem to only take one argument, so i ORed both DelayTemp0 and 1 in to DelayTemp and did a if DelayTemp=0 then exit to get out of the loop. [code]'very quick method, run pattern a, 'wait another 12 house run pattern b, wait 12 hours, repeat 'pattern 0 all zones 'pattern 1 only baby tears 'use arrays of constants in minutes for each pattern 5 min incraments 0 zone is off 'use look up index is pattern zone / 5 if > 0 'twoi lookups one for each timer temp word value 'timer temp is for both the off time and the on time ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX48, OSC128KHZ IRC_CAL IRC_4MHZ FREQ 128_000 ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- ' PORT RA 4 bit reserve for serial on all programs, unused set to outout low ' port rb 8 bit, input ' port rc 8 bit, output ' port rd and re 8 bit, unused set to output, low RAUnused PIN RA OUTPUT ' serial network RBUnused PIN RB INPUT PULLUP 'buttons RCUnused PIN RC OUTPUT 'relays RDUnused PIN RD OUTPUT 'leds REUnused PIN RE OUTPUT 'unused Switch PIN RB.0 INPUT PULLUP 'start and stop 'SwitchL PIN RB.1 INPUT PULLUP 'learn cat tag, press, then cat btn to learn that cat's tag Transformer PIN RC.0 OUTPUT 'transformer on/off to save money during peak electric times Zone1 PIN RC.1 OUTPUT 'zone 1 on/off drip waterfall Zone2 PIN RC.2 OUTPUT 'zone 2 on/off drip roses Zone3 PIN RC.3 OUTPUT 'zone 3 on/off baby tears Zone4 PIN RC.4 OUTPUT 'zone 4 on/off rubarb AutoLED PIN RD.0 OUTPUT 'the only LED Zone1LED PIN RD.1 OUTPUT 'zone 1 status Zone2LED PIN RD.2 OUTPUT 'zone 2 status Zone3LED PIN RD.3 OUTPUT 'zone 3 status Zone4LED PIN RD.4 OUTPUT 'zone 4 status ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- 'on delay time, wait period between on/off, word size MaxTime CON 65535 'Debounce CON 1 'Pressed CON 0 ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- 'delaytemp var to measure time DelayTemp0 VAR WORD DelayTemp1 VAR WORD 'mode, auto, unlocked, locked, inonly, outonly 'ModeTemp Var Byte SwitchTemp VAR BIT IndexLookup VAR BYTE PatternMode VAR BIT Pattern0 VAR BYTE (4) Pattern1 VAR BYTE (4) DelayTemp VAR WORD Watch DelayTemp0, 16, udec Watch DelayTemp1, 16, udec Watch DelayTemp, 16, udec Watch PatternMode, 1, udec Watch IndexLookup, 8, udec 'mouse VAR Bit ' Value can be 0 or 1 'cat VAR Nib ' Value can be 0 to 15 'dog VAR Byte ' Value can be 0 to 255 'rhino VAR Word ' Value can be 0 to 65535 'max 17 bytes mem or about 8 word size variable ' ------------------------------------------------------------------------- ' INTERRUPT ' ------------------------------------------------------------------------- 'ISR_Start: ' ISR code here 'ISR_Exit: ' RETURNINT ' {cycles} ' ========================================================================= PROGRAM Start ' ========================================================================= 'Pgm_ID: ' DATA "CatdoorVbeta0.05", 0 ' ------------------------------------------------------------------------- ' Subroutines / Jump Table ' ------------------------------------------------------------------------- CountDown SUB 0 LookupTime SUB 0 RunPattern SUB 0 ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: ' initialization code here RA = 0 'set putput low RC = 0 'set output low RD = 0 'set output low RE = 0 'set output low IndexLookup = 5 PatternMode=0 'Pattern0 Pattern0(0)=15 Pattern0(1)=15 Pattern0(2)=15 Pattern0(3)=15 'pattern1 Pattern1(0)=0 Pattern1(1)=0 Pattern1(2)=15 'babytears Pattern1(3)=0 Main: DO ' DelayLoop ' DelayLoop ' UnlockI ' DelayLoop ' DelayLoop ' LockI ' DelayLoop ' main code here ' ModeTemp/DelayTemp/MaxDelay ' IF Switch = Pressed THEN, 'INC ModeTemp ' PAUSE Debounce ' DO ' LOOP UNTIL Switch <> Pressed ' PAUSE Debounce ' TOGGLE SwitchTemp ' ENDIF '2 modes ' IF SwitchTemp = 0 THEN ' ClearButton ' ENDIF ' IF SwitchTemp = 1 THEN ' CountButton ' ENDIF RunPattern RunPattern LOOP ' ------------------------------------------------------------------------- ' Subroutine Code ' ------------------------------------------------------------------------- SUB CountDown 'counts the time down LookupTime 'TheLED = 1 DO IF DelayTemp0 <> 0 THEN 'only if upper most varable can be decreased DEC DelayTemp0 ELSE 'advance DelayTemp7 when DelayTemp6 IF DelayTemp1 <> 0 THEN DEC DelayTemp1 DelayTemp0 = MaxTime ENDIF ENDIF DelayTemp = DelayTemp0 OR DelayTemp1 IF DelayTemp = 0 THEN EXIT LOOP ENDSUB SUB LookupTime ' Use IndexLookup /5 to put correct times in to DelayTemp 'lookup values are in inc of 5 min IF IndexLookup > 0 THEN IndexLookup = IndexLookup / 5 ENDIF ' Lookup IndexLookup=0 is off time '1st lookup is main DelayTemp(most used) '263,478.8 per min at 400_000 hz 'NOTE NOW AT 128KHZ 'divide by 65536 for a word var '12hours=1_952_868_240 '5min=1_317_394 LOOKUP IndexLookup, 19_182, 28_350, 0, 19_514, 0, 10_678, 0, DelayTemp0 '2nd lookup is 2nd DelayTemp LOOKUP IndexLookup, 926, 6, 13, 19, 26, 32, 39, DelayTemp1 ENDSUB SUB RunPattern 'execute pattern Transformer = 1 'Turn on 24vAC transformer IF PatternMode = 0 THEN IF Pattern0(0) >= 1 THEN Zone1LED = 1 Zone1 = 1 IndexLookup = Pattern0(0) CountDown Zone1LED = 0 Zone1 = 0 ENDIF IF Pattern0(1) >= 1 THEN Zone2LED = 1 Zone2 = 1 IndexLookup = Pattern0(1) CountDown Zone2LED = 0 Zone2 = 0 ENDIF IF Pattern0(2) >= 1 THEN Zone3LED = 1 Zone3 = 1 IndexLookup = Pattern0(2) CountDown Zone3LED = 0 Zone3 = 0 ENDIF IF Pattern0(3) >= 1 THEN Zone4LED = 1 Zone4 = 1 IndexLookup = Pattern0(3) CountDown Zone4LED = 0 Zone4 = 0 ENDIF ENDIF IF PatternMode = 1 THEN IF Pattern1(0) >= 1 THEN Zone1LED = 1 Zone1 = 1 IndexLookup = Pattern1(0) CountDown Zone1LED = 0 Zone1 = 0 ENDIF IF Pattern1(1) >= 1 THEN Zone2LED = 1 Zone2 = 1 IndexLookup = Pattern1(1) CountDown Zone2LED = 0 Zone2 = 0 ENDIF IF Pattern1(2) >= 1 THEN Zone3LED = 1 Zone3 = 1 IndexLookup = Pattern1(2) CountDown Zone3LED = 0 Zone3 = 0 ENDIF IF Pattern1(3) >= 1 THEN Zone4LED = 1 Zone4 = 1 IndexLookup = Pattern1(3) CountDown Zone4LED = 0 Zone4 = 0 ENDIF ENDIF PatternMode = NOT PatternMode Transformer=0 'Turnoff 24vAC transformer IndexLookup = 0 'Set delay time to off period CountDown 'delay time ENDSUB[/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=273648#m273919 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)