11.07.2015 Views

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>PICBASIC</strong> <strong>PLUS</strong> CompilerThe SHIN instruction causes the following sequence of events to occur:-Makes the clock pin (cpin) output low.Makes the data pin (dpin) an input.Copies the state of the data bit into the msb(lsb- modes) or lsb(msbmodes) either before (-pre modes) or after (-post modes) the clockpulse.Pulses the clock pin high.Shifts the bits of the result left (msb- modes) or right (lsb-modes).Repeats the appropriate sequence of getting data bits, pulsing theclock pin, and shifting the result until the specified number of bits isshifted into the variable.Making SHIN work with a particular device is a matter of matching themode and number of bits to that device’s protocol. Most manufacturersuse a timing diagram to illustrate the relationship of clock anddata.SYMBOL CLK = PORTB.0SYMBOL DTA = PORTB.1SHIN DTA , CLK , MSBPRE , [Var]' Shiftin msb-first, pre-clock.In the above example, both SHIN instructions are set up for msb-firstoperation, so the first bit they acquire ends up in the msb (leftmost bit)of the variable.The post-clock Shift in, acquires its bits after each clock pulse. Theinitial pulse changes the data line from 1 to 0, so the post-clock Shiftinreturns %01010101.By default, SHIN acquires eight bits, but you can set it to shift anynumber of bits from 1 to 16 with an optional entry following the variablename. In the example above, substitute this for the first SHIN instruction:SHIN DTA , CLK , MSBPRE , [Var \ 4]'Shift in 4 bits.Some devices return more than 16 bits. For example, most 8-bit shiftregisters can be daisy-chained together to form any multiple of 8 bits;16, 24, 32, 40... You can use a single SHIN instruction with multiplevariables.Each variable can be assigned a particular number of bits with thebackslash (\) option. Modify the previous example: -' 5 bits into Var1; 8 bits into Var2.SHIN DTA , CLK , MSBPRE , [ Var1 \ 5 , Var2 ]PRINT "1st variable: " , BIN8 Var1PRINT "2nd variable: " , BIN8 Var2121Copyright Crownhill 2001

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!