Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] accessing bits (e.g. of ports)

2005-01-31 by Stefan Trethan

On Mon, 31 Jan 2005 14:21:19 +0100, Svenn Dahlstrøm <svenn@symetrics.no>  
wrote:

> I use ICCAVR and do it this way :
> #define setbit(ADDRESS,BIT) ((ADDRESS) |= (1<<(BIT)))
> #define clrbit(ADDRESS,BIT) ((ADDRESS) &= ~(1<<(BIT)))
> #define chkbit(ADDRESS,BIT) ((ADDRESS) & (1<<(BIT)))
> #define togglebit(ADDRESS,BIT) ((ADDRESS) ^= (1<<(BIT)))
> and write code like this :
> setbit(PORTA, 2);
> togglebit(PORTB, 6);
> clrbit(DDRC, 0);
> And this can be used to set, clear, check or toggle one bit on any  
> register
> or variable.
> Svenn


i like that. It's still not as clear to me as e.g. PORTB.1 but it is a very
good solution already.

thanks

ST

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.