I/O Ports (Part 2)

Part 12345

And now some results related to the performances measured while using one or the other options for setting PORTS.

Brute force setting

PORTB  =  0x00;
PORTB  =  0x01;
PORTB  =  0x00;

Takes 62 ns to generate a positive pulse

Simple method

PORTB  =  0x00;
PORTB |=  0x01;
PORTB &= ~0x01;

Takes 125 ns to generate a positive pulse

Classic method

PORTB  =  0x00;
PORTB |=  (1 << PINB0);
PORTB &= ~(1 << PINB0);

Takes 125 ns to generate a positive pulse

Flip flop method

PORTB  =  0x00;
PORTB ^=  (1 << PINB0);
PORTB ^=  (1 << PINB0);

Takes 187 ns to generate a positive pulse

Elegant method

PORTB  =  0x00;
PORTB ^=  (PORTB ^ (1 << PINB0));
PORTB ^=  (PORTB ^ (0 << PINB0));

Takes 352 ns to generate a positive pulse

Next post on same subject

Leave a Reply

You must be logged in to post a comment.