Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] problem in defining bits in Winavr

Status
Not open for further replies.

shahbaz.ele

Advanced Member level 1
Joined
Aug 12, 2008
Messages
454
Helped
72
Reputation
146
Reaction score
73
Trophy points
1,308
Location
Islamabad, Pakistan
Activity points
3,669
dear all
I want to set and clear the bits of MCUCR register
but I do not know how to define the SM0,1,2 bits and SE bit and how to set these bits.
 

you can use following instructions to set or clear bits of any register

Code:
MCUCR |= (1<<0); //to set bit 0 of MCUCR
MCUCR |= (1<<7); //to set bit 7 of MCUCR

MCUCR &= ~(1<<0); //to  clear bit 0 of MCUCR
MCUCR &= ~(1<<7); //to clear bit 7 of MCUCR
 
Last edited by a moderator:
Note that the bits of each register are defined in the header file with the name used in the datasheet.

For example for mega8 the header iom8.h includes
Code:
/* MCUCR */
#define SE	7
#define SM2	6
#define SM1	5
#define SM0	4
#define ISC11	3
#define ISC10	2
#define ISC01	1
#define ISC00	0

so this allows you to use bit names instead of numbers if you want

Code:
MCUCR |= (1<<ISC00); //to set bit 0 of MCUCR
MCUCR |= (1<<SE); //to set bit 7 of MCUCR

also take a look at https://www.edaboard.com/blog/861/

I like to use
Code:
#define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT)) 
#define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT)) 


SETBIT(MCUCR,ISC00); // //to set bit 0 of MCUCR
CLEARBIT(MCUCR,ISC00)  //to clear bit 0 of MCUCR

Alex
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top