Jump to content

Dúvidas com alguns "operadores"


Recommended Posts

Posted

Olá,

Tenho visto algumas linhas de código que nao tenho entendido. Se me pudessem esclarecer, agradecia. Aqui vao elas:

uint8_t pidTimer:1;
uint8_t dummy:7;

TCCR0A = (1<<CS00);

TIFR  |= _BV(OCIE0)|_BV(TOIE0);

UBRR0H = (BAUD_RR >> 8) & 0xff;

Será que me podem explicar o que é feito (de forma genérica) em cada uma destas linhas?

Posted
uint8_t pidTimer:1;
uint8_t dummy:7;

Isto define pidTimer como uma variável do tipo uint8_t, mas só será formada por 1 bit, assim como dummy só será formada por 7 bits. São os chamados bit fields.

TCCR0A = (1<<CS00);

Realiza o shift aritmético à esquerda do 1.

TIFR  |= _BV(OCIE0)|_BV(TOIE0);

Realiza o OR (bit a bit) entre TIFR, _BV(OCIE0) e _BV(TOIE0)

http://en.wikipedia.org/wiki/Bitwise_operation

UBRR0H = (BAUD_RR >> 8) & 0xff;

Faz o shift aritmético à direita e depois realiza o AND bit a bit entre o resultado e o 0xff.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.