Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/12/03 04:06
Read: times


 
#52468 - RE: update pins on a port on the byte level
Responding to: ???'s previous message
As a variation of Michael's method, I have sometimes found it beneficial to have a sort of software "output latch" associated with a port, especially if there are read-modify-write issues associated with the port. This scheme also works well for write-only memory mapped hardware output latches. In the example below, I have P2's upper nibble configured as input and the lower nibble configured as output. I want to write a 4-bit incrementing value to the port (nonsensical, but illustrates use).

/* PORT_WR() performs a buffered write of the "mask"ed bits of "val" to
 * "port" (P1, P2, etc.) through the port's output latch register.  This
 * technique is especially useful to deal with any read-modify-write
 * issues a port may have.
 */
#define PORT_WR(port, val, mask) 
        (port = (port##_OLR ^= (port##_OLR ^ (val)) & (mask)))

unsigned char P2_OLR;   /* OLR: Output Latch Register */

void main(void)
{
    unsigned char i;

    P2_OLR = 0xF0;
    P2     = P2_OLR;

    for (i = 0; /* forever */ ; i++)
        PORT_WR(P2, i, 0x0F);
}



List of 11 messages in thread
TopicAuthorDate
update pins on a port on the byte level            01/01/70 00:00      
   RE: update pins on a port on the byte level            01/01/70 00:00      
   RE: update pins on a port on the byte level            01/01/70 00:00      
      RE: update pins on a port on the byte level            01/01/70 00:00      
      RE: update pins on a port on the byte level            01/01/70 00:00      
         RE: update pins on a port on the byte level            01/01/70 00:00      
            RE: update pins on a port on the byte level            01/01/70 00:00      
               RE: update pins on a port on the byte level            01/01/70 00:00      
   RE: update pins on a port on the byte level            01/01/70 00:00      
   RE: update pins on a port on the byte level            01/01/70 00:00      
   RE: update pins on a port on the byte level            01/01/70 00:00      

Back to Subject List