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.

IAR for AVR C Compiler Question.....

Status
Not open for further replies.

ron

Junior Member level 3
Joined
Dec 24, 2001
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
173
Hi all,
Just using the IAR C-Compiler for AVR for the first time, and I simply cannot figure out how to access a single bit of say PortA.
If I write for example PORTA=0x01 this is fine as its on the whole port, but if I write PA0=1 I keep getting an error "PA0 is undefined" even though I have include the <io8515.h> header.
Cant seem to find an IAR example program anywhere to show me how, can anyone tell me before I've pulled all my hair out !!
Thanks in advance. :) :)
 

Hi,

do not forget to look into that io8515.h file. You will find:

/* Data Register, Port A */
#define PA7 7
#define PA6 6
#define PA5 5
#define PA4 4
#define PA3 3
#define PA2 2
#define PA1 1
#define PA0 0

As you see, PA0 is a constant.

For example, to set PA5 use:

PORTA |= 1<<PA5;

To set PA3 and PA6 at the same time:

PORTA |= (1<<PA3) + (1<<PA6);

Best Wishes! klug.
 

Also you can define port bits as bit masks:

#define PA0 0x01
#define PA1 0x02
#define PA2 0x04
#define PA3 0x08


if(PINA & PA0)
{
PORTA |= PA0; //set PA0
PORTA &= ~PA1; //reset PA1
}
 

Try this



#define SETBIT(Adress, Index) Adress |=(1<<Index)
#define CLEARBIT(Adress, Index) Adress &=~(1<<Index)


call

SETBIT(PORTB, 0); // for setting bit0 in PORTB
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top