Move byte to PORT

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all.

 

Is there a most efficient way of moving a byte to 8 pins on a port? (Such as for an LCD data port). I'd rather not test each bit and set each pin accordingly, and shifting seems efficient only when it's close to a word boundary.

 

Is there some other smarter way?

 

TIA.

L

This topic has a solution.
Last Edited: Tue. Apr 5, 2022 - 08:04 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Shifting on an ARM is efficient even for large shift values (any shift, 1 to 31 bits, takes a single cycle (plus setting it up, of course.)  Of course, it's only really helpful if your output pins are actually contiguous...

 

There's the lovely XOR hack if your chip has an "toggle pins" register for GPIO:

    gpio->OUTTGL = (gpio->OUT ^ value) & mask;

(also, most of the Microchip ARM chips can write single bytes worth of 32bit IO ports.  Though the definitions provided don't make that easy for the programmer.)

 

Last Edited: Tue. Apr 5, 2022 - 07:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you! I guess I need to better study the instruction set to see what's under the hood.

 

By Microchip ARM chips do you mean the PICs rather than the SAMs?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

By Microchip ARM chips do you mean the PICs rather than the SAMs?

No.  All SAM*+PIC32MC* support byte and halfword access.  I'm just trying to stop using "Atmel."  :-(
(Hmm.  SAMD, anyway.  I'm not sure about the other SAMs.)