AVR - Defining Ports and Bits

Discussion in 'Embedded Systems and Microcontrollers' started by Mazaag, Aug 29, 2007.

  1. Mazaag

    Thread Starter Senior Member

    Oct 23, 2004
    255
    0
    Hi guys,

    I came across this piece of code for a 8051 interfacing with an ADC :
    Code ( (Unknown Language)):
    1.  
    2.  
    3. [SIZE=4][U]Program: [/U][/SIZE]
    4.  
    5. [SIZE=3]#include <reg51.h>[/SIZE]
    6. [SIZE=3]#include "io.h"[/SIZE]
    7. [SIZE=3]sbit READ = P3^2; [/SIZE]
    8. [SIZE=3]sbit WRITE = P3^3;[/SIZE]
    9. [SIZE=3]sbit INTR = P3^4;[/SIZE]
    10. [SIZE=3]void main( void ) [/SIZE]
    11. [SIZE=3]{    [/SIZE]
    12. [SIZE=3]unsigned char adVal;    [/SIZE]
    13. [SIZE=3]unsigned long volts;   [/SIZE]
    14. [SIZE=3] InitIO();   [/SIZE]
    15. [SIZE=3] READ = 1; [/SIZE]
    16. [SIZE=3] WRITE = 1;    [/SIZE]
    17. [SIZE=3]INTR = 1;[/SIZE]
    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
     
  2. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    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;
     
  3. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    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
     
  4. Mazaag

    Thread Starter Senior Member

    Oct 23, 2004
    255
    0
    Another question ,

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

    Moderator

    Jan 28, 2005
    9,030
    214
    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
     
  6. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    If you #include<avr/io.h> it will include this file also.
     
Loading...