Shop OBEX P1 Docs P2 Docs Learn Events
Best way to address only 4 pins of a port — Parallax Forums

Best way to address only 4 pins of a port

Jim FouchJim Fouch Posts: 395
edited 2006-01-19 19:40 in General Discussion
This may seem simple, but I was wondering what was the best way to clear the states of only 4 pins on a port w/o·disturbing the others.

In my project I'm using Port B (pins 1-3) for an A/D and also pins 4-7 to drive a stepper motor·.

Here is the code I'm using now...

SendMotorCommand:
 Read HalfSteps + StepIndex, Temp1
 RB.7 = 0
 RB.6 = 0
 RB.5 = 0
 RB.4 = 0
 RB = RB or Temp1
Return
 
RelaxMotor:
 RB.7 = 0
 RB.6 = 0
 RB.5 = 0
 RB.4 = 0
Return

 
HalfSteps:
  Data %00000000
  Data %00010000
  Data %00110000
  Data %00100000
  Data %01100000
  Data %01000000
  Data %11000000
  Data %10000000
  Data %10010000



Just wondering is there is a better way to address (clear) the states of only 4 pins on a port.
Thanks,

Jim

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-01-19 18:58
    Using the logic operand AND is the most efficient means of clearing a series of bits, RB = RB AND #$0F, would clear bits 4-7, I may have the syntax wrong since I don't use SX/B that much.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • BeanBean Posts: 8,129
    edited 2006-01-19 19:22
    Paul,
    Without the "#" though. RB = RB AND $0F
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Ability may get you to the top, but it takes character to keep you there."
    ·
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-01-19 19:40
    Thanks Bean, that was what I suspected was incorrect.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
Sign In or Register to comment.