AVR - Defining Ports and Bits

Thread Starter

Mazaag

Joined Oct 23, 2004
255
Hi guys,

I came across this piece of code for a 8051 interfacing with an ADC :
Rich (BB code):
Program: 
 
#include <reg51.h>
#include "io.h"
sbit READ = P3^2; 
sbit WRITE = P3^3;
sbit INTR = P3^4;
void main( void ) 
{    
unsigned char adVal;    
unsigned long volts;   
 InitIO();   
 READ = 1; 
 WRITE = 1;    
INTR = 1;
Here the programmer sets READ WRITE and INTR to be certain bits of a specific port, and later he changes the values of these bits by changing the corresponding variable.. I was wondering if there is an equivalent code for the AVR AVmega8515 .... Thanks guys
 

nanovate

Joined May 7, 2007
666
This is a compiler specific thing. The 'sbit' is a Keil compiler specific data type that accesses the individual bits.

For WinAVR:
See " _BV() "
For setting a '1' on pin 1 of PortA --> PORTA |= _BV(PA1); //shift in a '1'
For setting a '0' on pin 1 of Porta --> PORTA |= ~(_BV(PA1));

Codevision has a similiar syntax -- PORTA.1 = 0;
 

hgmjr

Joined Jan 28, 2005
9,029
For the "_BV()" function to work you will need to put the line

#include <avr/sfr_def.h>

at the beginning of the source file if it is not already there. This is the header file that contains the associated macro definition.

hgmjr
 

Thread Starter

Mazaag

Joined Oct 23, 2004
255
Another question ,

in AVR Studio , how do i set the folder which the compiler will look for when including files ? ( #include .. )
 

hgmjr

Joined Jan 28, 2005
9,029
Another question ,

in AVR Studio , how do i set the folder which the compiler will look for when including files ? ( #include .. )
Once you are in the WINAVR application click on "PROJECT" up in the toobar. From the dropdown window choose "Configuration Options".

In the resulting window you can look over on the lefthand side and you will notice the icon for "INCLUDE IDRECTORIES". CLick on this icon to go to the window. At the top of this window you will see a folder icon. CLick on this and it will open up a browse window. Click on the elipsis (...). From there you can browse to the folder that contains the include file you need.

Hope this is not too confusing.

hgmjr
 
Top