[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] strange c
From: |
Rich Neswold |
Subject: |
Re: [avr-gcc-list] strange c |
Date: |
Tue, 18 Dec 2001 12:09:40 -0600 |
User-agent: |
Mutt/1.2.5i |
Wasn't it 18-Dec-2001, at 02:24PM, when Torsten Hahn said:
> im a bit new to low-level c, but what does e.g 1<<TOIE1 do ? From the
> languege reference i know the shift operator to use like value<<1 but not
> the other way around.
1 << n
Creates a value that has the n'th bit set (the lowest bit is the 0th bit.)
So:
1 << 0 gives 0x01
1 << 1 gives 0x02
1 << 2 gives 0x04
The IO headers files in avr-libc define all the bits in the I/O registers
in terms of their position (i.e. 0-7 values). This works well when using
the cbi()/sbi() macros. If you want to load several bits at the same time
(using outp()), you could use the BV() macro, which computes the formula (1
<< arg). By ORing together several BV() instances, you build up a value
with several bits:
outp(BV(first_bit_of_interest) | BV(second_bit), target_register);
The previous statement will generate one line of assembly (as long as
"target_register" is an I/O register.)
Hope this helps...
--
Rich Neswold
efax: 1.240.536.7092
web: www.enteract.com/~rneswold/
rand: 439099df4a7197c92c7a3de1aaae16
pgpJ94mooZYJ3.pgp
Description: PGP signature