November 23, 2024, 07:38:15 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


PINS - DIRS

Started by JackMan, September 23, 2010, 11:24:31 PM

Previous topic - Next topic

JackMan

What's the result of eliminating the typical PINS - DIRS code on initialization? I've written quite a few of my own programs and have never included this, all have worked fine.

JonnyMac

It will of course depend on the program.  Most of the time you will "get away with it" but in some cases you won't -- depends on hour you're using pins.  For example, I don't like to use HIGH and LOW to turn pins on and off.  Why?  Because there are active-low circuits in the world and I prefer to write code like this:

  MyOutput = IsOff

In order for that to work, however, the DIRS bit for that pin must be pre-set (HIGH and LOW do this internally).

Most of my programs start out like this:

Reset:
  PINS = %00000000
  DIRS = %00111111


This allows me a place to jump back to and reset all IO to a known state.

In the end, I'm a very conservative programmer; this stems from years of developing products/programs for public consumption and needing them to be as "bullet proof" as possible.



Jon McPhalen
EFX-TEK Hollywood Office

JackMan

Good answer. I do use HIGH - LOW in my programs. I have also successfully used IsOff - IsOn for trigger input without including PINS - DIRS in initialization. Does this work because that particular PIN is being used as an input?

JonnyMac

Yes; when the BASIC Stamp resets all pins are defined as inputs.  Technically, you only have to define outputs -- using the DIRS register lets you setup all IO pins in one line of code.
Jon McPhalen
EFX-TEK Hollywood Office