In SX Microcontrollers, SX/B Compiler and SX-Key Tool, datacps wrote: Bean I tried using the code I get an error on mindelay and maxdelay var 100 and VAR 1000 also it flags me INTR_FALL . The code below does not generate errors but I still can't get it to work I wanted to add the LCD to see the pause value. ' ========================================================================= ' ' File...... TEMPLATE.SXB ' Purpose... SX/B Programming Template ' Author.... ' E-mail.... ' Started... ' Updated... ' ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- 'adjust Pause with encoder and display value on LCD ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX FREQ 4_000_000 ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- led VAR RB.5 ' LED pin led2 VAR RB.6 EncoderPort PIN RC Encoder1A PIN RC.0 INPUT PULLUP SCHMITT Encoder1B PIN RC.1 INPUT PULLUP SCHMITT LCD PIN RA.2 OUTPUT ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- mindelay CON 10 ' Lowest allowable delay maxdelay CON 1000 ' Highest allowable delay LCDBaud CON "T19200" ' LCD Baud rate ClearScreen CON 12 ' Clears LCD screen NewLine CON 13 ' Put LCD cursor on the next line Home CON 128 ' Move LCD cursor to upper left without clearing the screen LcdBLon CON 17 'TURN ON LCD BACK LIGHT DELAY2 con 2000 WAIT CON 100 ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- delay VAR WORD tempW VAR WORD ' Used by Setdelay, LCDStr, LCDWord temp VAR BYTE ' Used by Setdelay, LCDChar, LCDStr tempW2 VAR WORD ' Used by Setdelay encoder var word encoder1 VAR word encoder1Last VAR word ' ------------------------------------------------------------------------- INTERRUPT ' Interrupt caused by falling edge of EncoderB input WKPND_B = 0 ' Clear interrupt flag to enable further interrupts IF Encoder1 = 0 THEN ' Change "0" to "1" if direction is backwards DEC delay delay = delay MIN MinDelay ' Min delay must be > 0 ELSE INC delay delay = delay MAX MaxDelay ENDIF RETURNINT ' ========================================================================= PROGRAM start ' ========================================================================= ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- 'delay SUB 1,2 ' Pass delay wanted (0, 1 to 1000) (0 = OFF) LCDChar SUB 1 ' Sends 1 character (byte) to the LCD LCDStr SUB 2 ' Sends a string to the LCD LCDWord SUB 2 ' Sends a value to the LCD as ASCII GetEncoder1 FUNC 1 UpdateEncoders SUB 0 setdelay sub 1,2 ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: DO HIGH LCD ' For LCD High is idle state PAUSE 10 ' Let LCD settle LCDChar ClearScreen PAUSE WAIT LCDChar LcdBLon LCDStr " delay test " PAUSE delay2 LCDChar ClearScreen PAUSE WAIT LCDStr "< delay led test > " LCDStr "<< pauseus >>" PAUSE DELAY2 LCDChar ClearScreen PAUSE WAIT encoder1Last = GetEncoder1 do tempW = delay */ 180 ' this is just a test value to test PAUSE tempW HIGH LED ' turn LED on PAUSE Delay ' delay LOW LED ' turn LED off PAUSE Delay ' delay HIGH LED2 ' turn LED on PAUSE Delay ' delay LOW LED2 ' turn LED off PAUSE Delay DO IF delay <> tempW THEN LCDChar Home LCDStr " delay = " LCDWord delay tempW = delay ENDIF loop ' ------------------------------------------------------------------------- ' Subroutine Code ' ------------------------------------------------------------------------- SUB Setdelay IF __PARAMCNT = 1 THEN delay = __PARAM1 ELSE delay = __WPARAM12 ENDIF IF delay < 1000 THEN delay = 0 ENDIF '----------------------------------------------------------------- ' LCD ROUTINE '------------------------------------------------------- SUB LCDChar temp = __PARAM1 SEROUT LCD, LCDBaud, temp UpdateEncoders ENDSUB SUB LCDStr tempW = __WPARAM12 DO READINC tempW, temp IF temp = 0 THEN EXIT LCDChar temp LOOP ENDSUB SUB LCDWord tempW = __WPARAM12 temp = "0" DO IF tempW < 1_000 THEN EXIT INC temp tempW = tempW - 1_000 LOOP LCDChar temp temp = "0" DO IF tempW < 1_000 THEN EXIT INC temp tempW = tempW - 1_000 LOOP LCDChar temp temp = "0" DO IF tempW < WAIT THEN EXIT INC temp tempW = tempW - WAIT LOOP LCDChar temp temp = "0" DO IF tempW < 10 THEN EXIT INC temp+ tempW = tempW - 10 LOOP LCDChar temp temp = "0" + tempW_LSB LCDChar temp ENDSUB '--------------------------------auto---------------------- FUNC GetEncoder1 temp = EncoderPort AND 3 RETURN temp ENDFUNC SUB UpdateEncoders encoder1 = GetEncoder1 IF encoder1 <> encoder1Last THEN IF encoder1 = 3 THEN IF encoder1Last = 1 THEN delay = delay + 1 delay = delay MAX maxdelay ELSEIF encoder1Last = 2 THEN delay = delay - 1 delay = delay MIN mindelay ENDIF ENDIF encoder1Last = encoder1 ENDIF ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=226156#m226686 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2007 (http://www.dotNetBB.com)