In SX Microcontrollers, SX/B Compiler and SX-Key Tool, capdiamont wrote: I have a sx48 protoboard with sx key. The code seems to work great in debug with no hardware attached, until i added a button. pull up resistor is enabled, but watching the pin in debug, it goes crazy. The lead to the button is about 1 to 2 feet. I want to install this in to an old UPS case, I thought the long lead would make it easier. Long day working with my mistakes, 1st sx program. code: DEVICE SX48, OSC4MHZ IRC_CAL IRC_4MHZ FREQ 4_000_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 ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- 'flash delay time, wait period between on/off, word size MaxDelay CON 1000 ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- 'delaytemp, wait time counter, word size DelayTemp Var Word 'mode, on/off bit size ModeTemp Var Bit watch DelayTemp watch ModeTemp ' ------------------------------------------------------------------------- ' INTERRUPT ' ------------------------------------------------------------------------- 'ISR_Start: ' ISR code here 'ISR_Exit: ' RETURNINT ' {cycles} ' ========================================================================= PROGRAM Start ' ========================================================================= 'Pgm_ID: ' DATA "LightHouseVbeta0.01", 0 ' ------------------------------------------------------------------------- ' Subroutines / Jump Table ' ------------------------------------------------------------------------- ' OnMode SUB 0 OnMode: rc.1 = 1 if DelayTemp >= MaxDelay then toggle rc.0 DelayTemp = 0 endif DelayTemp = DelayTemp + 1 ' DelayTemp = 255 ' Return goto Main ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: ' initialization code here TRIS_A = %0000 'outputs %=bitwise TRIS_B = 255 'input dec TRIS_C = 0 'output dec TRIS_d = 0 'output dec, unused TRIS_e = 0 'output dec, unused PLP_b = 255 'MAKE rb port PINS PULLUP RESISTOR ON ' ST_B = 255 'make rb port pins schmitt trigger ra = 0 'set putput low rc = 0 'set output low rd = 0 'set output low re = 0 'set output low ' on/off swtich =rb.0 ' lighthouse = rc.0 ' pump = rc.1 Main: ' main code here ' modetemp/delaytemp/maxdelay if rb.0 = 1 then toggle ModeTemp endif if ModeTemp = 0 then rc.0 = 0 rc.1 = 0 endif if ModeTemp = 1 then goto OnMode GOTO Main ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=205092 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)