November 27, 2024, 07:35:28 AM

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.


Spin code methods to access the HC-8+ standard features

Started by bsnut, January 27, 2013, 04:47:21 PM

Previous topic - Next topic

bsnut

Jon,

I am looking for the Spin code methods so I can use the HC-8+ standard features, this way I can connect it to a Propeller chip or connect to the HC-8+ itself.
William Stefan
The Basic Stamp Nut

JonnyMac

Can you be a little more specific about what you're looking for? I've released several versions of the template to enable "hacking" for control use.
Jon McPhalen
EFX-TEK Hollywood Office

bsnut

Jon,

Sorry for not being clear enough with the first post. What I was looking for was the spin code so I can connect two HC-8+ together, one hacked using those spin code methods to access the standard features on the other HC8-+ that isn't been hacked.   
William Stefan
The Basic Stamp Nut

JonnyMac

January 28, 2013, 09:09:31 AM #3 Last Edit: January 30, 2013, 11:04:53 AM by JonnyMac
Give this a try; I've created a variation of the template that handles the serial IO (I added another serial object that is setup for half-duplex serial on the SIO pin at 38.4K baud) for the HC-8+.

See post below for new version of template.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

I've updated the template to add AP-16+ commands and "virtualized" a couple features accessing local and remote outputs.  Let me know how this works for you.
Jon McPhalen
EFX-TEK Hollywood Office

bsnut

Thanks Jon for reading my mind ;D. I didn't get around to test the first template that you posted the first time. I just tested your edited template after reading your post and it worked fine, but I have one question. Can you show me how to read the TTL inputs using these two methods?

pub ttl_pin | btns

'' Reads TTL header for 1-of-8 input
'' -- returns -1 (no input)
'' -- returns 0 to 7 for input on IN0 to IN7
''    * only one input allowed

  btns := ttl_inputs(true)                                      ' read ttl inputs

  if (bit_count(btns) == 1)                                     ' only one button pressed?
    return bit_pos(btns, 0)                                     '  yes, return button #
  else
    return -1                                                   '  none or bad input


pub ttl_inputs(rescan)

'' Return TTL inputs status
'' -- updates global var "lastscan" if rescan is true

  if (rescan)
    lastscan := x165_in(16, MSBFIRST) | (ina[DMX_A8] << 16)     ' read in0..in7, dmx addresss
   
  return (lastscan & $FF)                                       ' return TTL input bits

William Stefan
The Basic Stamp Nut

JonnyMac

Those methods do different things.

At the core is ttl_inputs() which scans the physical input port and gives you eight bits back that define the states of the input header.

The second, ttl_pin, returns a value of -1 (no inputs) or 0 to 7 (which pin is active) if only one input is active. This routine can be used when you want to look for specific individual inputs. 

Here are two ways to accomplish the same thing:

  case ttl_inputs(true)
    %0000_0001:
      run_process_0
    %0000_0010:
      run_process_1
    %0000_0100:
      run_process_2


  if (ttl_pin == 0)
    run_process_0
  elseif (ttl_pin == 1)
    run_process_1
  elseif (ttl_pin == 2)
    run_process_2


Both of these fragments are looking for a single active pin. That said, I think the second is a little easier to follow.

Now... if you want to be able to deal with multipe active pins at the same time, you simply read them like this:

  myinputs :=  ttl_inputs(true)

Now myinputs holds an eight-bit value that is a snap-shot of the pin states on the input header. Remeber that Spin doesn't have direct bit access so if you want to scan yourself, you have to do something like this:

  if (myinputs & (1 << 7))
    run_process_7


In this case we're creating a mask for bit 7 (by left shifting) and ANDing that with the raw value. If myinputs.7 is 1 then the expression will evaluate as true and run_process_7 will be called.
   
Jon McPhalen
EFX-TEK Hollywood Office

bsnut

I will give it a try it later on friday morning. It looks even easier then I though was. Now only if the RS485 was this easy, which I am still trying to get working for my signal project that I am working on, but that is for another thread.
William Stefan
The Basic Stamp Nut

JonnyMac

My HC-8+s have been on loan to other projects; I'll see if I can pull them and sort out the RS-485 thing. We have a commercial customer using the HC-8+ in an RS-485 network with my HFCP (human friendly control protocol); I'll start there.
Jon McPhalen
EFX-TEK Hollywood Office