In SX Microcontrollers, SX/B Compiler and SX-Key Tool, JonnyMac wrote: All high level SX/B instructions set the pin as needed (input or output) without regard to the present state which would just take more code to check. So if there was a 0 in the pin driver for your midi output it that output will go low as soon as the TRIS is updated. There is no harm since the next instruction is going to take it low, anyway. Keep in mind that manipulating the TRIS bit does not affect the driver bit. In this case it gets initialized to zero (low when in output mode). It's easy to manipulate the TRIS bit by copying the midi data bit to it. When the midi data bit is a 0 that will cause the TRIS register to make your pin an output. Since the pin driver has been initialized to zero the output will go low. When you have a "1" data bit that will cause the TRIS to make the pin an input, and the pullup on the pin (be definition OT serial pins must have a pull-up) will bring the pin back high. Easy-peezy. In general, it works like this: for the open modes (OTxxxx, ONxxxx) the pin driver is initialized and the TRIS register is manipulated by the data bits; for driven modes (Txxxx, Nxxxx) the TRIS register is initialized (to make the pin an output) and the pin driver is manipulated by the data bits. Knowning this you can use a simple loop to send custom serial. I created a LanC controller for a customer that gets the start bit from the camera. I have a custom serial output loop that waits one bit period after detecting the start and then writes the byte. The LanC output is Open True as well so the controller can stomp on the first two bytes (which are $FF meaning the serial line is being pulled up) to send commands to the camera. [code]' Use: LANC_TX aByte ' -- asserts 'aByte' onto LANC line after start bit ' -- used only for bytes 0 and 1 of LANC stream SUB LANC_TX tmpB1 = __PARAM1 ' get byte to send Wait_For_Start: \ JB LancIn, $ ' hold for start bit PAUSEUS 102 ' delay for start bit TX_Bits: FOR tmpB2 = 0 TO 7 ' send eight bits LancOut = tmpB1.0 ' put bit on LANC pin PAUSEUS 98 ' trimmed for loop tmpB1 = tmpB1 >> 1 ' position next bit NEXT LancOut = 0 ' turn off driver ENDSUB[/code] Keep in mind that serial devices tend to sample in the middle of the bit so a little slop one way or the other doesn't hurt anything, especially since LanC runs at the very tame baud rate of 9600. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=287096#m287141 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)