how to alternate pins?
mikea
Posts: 283
Hi,
is there a way to alternate pins each time through a code. In other words pin 3 high/low the first time through the code, i would like to add pin 4 high/low the second time through. i thought toggle would accomplish this, but it seems to only deal with a single pin and toggle its state, not switch between two pins.-mike
is there a way to alternate pins each time through a code. In other words pin 3 high/low the first time through the code, i would like to add pin 4 high/low the second time through. i thought toggle would accomplish this, but it seems to only deal with a single pin and toggle its state, not switch between two pins.-mike
Tag_Found: GOSUB Show_Name ' print name HIGH Latch ' remove latch ,pin3 pause 500 LOW Latch ' restore latch ,pin3 GOTO Main
Comments
The OUTS,OUTA,OUTB,OUTC,OUTD,OUTL and OUTH are all instructions that directly affect the status of the I/O pins PO through P15. Simultaneously which is a really nice feature.
OUTS is a 16 bit register, in notation the right hand side is the least significant bit (LSB) so P3 is the 4th bit from the right (P0 P1 P2 P3 = 4 bits). To set P3 high you would make the 4th bit a 1 eg: 0000000000001000 this binary number is equivalent to decimal 8. To set it low you would make bit 4 a zero eg: 0000000000000000 = dec 0
With different values assigned to OUTS you can set any combination of outputs to high or low just by giving the respective bits a 1 or a 0.
In your situation where you want to move onto the next output after each succesive loop through the program you could use the binary operator Bitshift Left which is represented "value=value<<1". Bitshifting left has the following effect, for example shifting bit 4 we would start with 0000000000001000 (dec 8 ) and end up with 0000000000010000 (dec 16 ).
Here is an example of scrolling through all 16 ports setting each to 1 and then zero. To set the OUTS register to zero there is another operator used called XOR.
This all might seem a little daunting at first sight but if you can grasp an understanding of controlling the DIRS, INS and OUTS registers then I think you will have control of one of the more powerful features of the BS2
Jeff T.