Skip to content

DIRECT PORT MANIPULATION help #474

Answered by SpenceKonde
dattasaurabh82 asked this question in Q&A
Discussion options

You must be logged in to vote

byte c = 0; //byte (uint8_t ) not int, int takes two instructions to act on instead of 1, even though you're eventually assigning it to an 8-bit register that will truncate it to 8 bits.

uint16_t period = 100;

//1 us is not going to happen, that's 20 instructions :-P 32 if you overclock that thing as hard as you can without busting out the dry ice & acetone bath or liquid nitrogen. So use something sane.

Never do this, it's silly and inefficient:

PORTB.OUT |= anything;
// or
PORTB.OUT &= anything;

That generates:
LDS (3 clock cycles) to load the value into a working register (let's say r0, because that's a perfectly reasonable one for it to pick)
OR/AND what it just read with the anything.

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@dattasaurabh82
Comment options

Comment options

You must be logged in to vote
1 reply
@dattasaurabh82
Comment options

Answer selected by dattasaurabh82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants