[SOLVED] toggle multiple pins in C

Status
Not open for further replies.

sri5496

Junior Member level 3
Joined
Sep 28, 2012
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
UK
Visit site
Activity points
1,469
hi .


am bit new to programming am using dspic33f..need to toggle multiple pins in C progrm.. would appreciate if any one can help...
 

You must evaluate '0'´s and '1'´s separatelly.
Try this :
Code:
\\ iWord <= input operator pattern in which pins to be toggled bits are designed by '1'
\\ PORTx <= global variable representing I/O uC port

int iTemp = PORTx ;

PORTx &= ~ ( iWord & iTemp ) ;
PORTx |=  ( ~iWord & iTemp ) ;
 

Use a mask and the bitwise exclusive OR (XOR) operator, ^

PORTA ^= 0b00000011; //toggle bit0, bit1
PORTB ^= 0b00001100; //toggle bit2, bit3
 

Individual PIN Toggling

RB0 = ~RB0 // PORTB bit0
RC2 = ~RC2 // PORTC bit2


whats the different b/w LATB & PORTB ( LATCH & PORT )
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…