AVRstudio and WinAVR

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

  1. Mazaag

    Thread Starter Senior Member

    Oct 23, 2004
    255
    0
    I just installed AVRstudio followed by WinAVR..

    When i look under the plug-in manager for AVRstudio, it says that there is a AVR-GCC plugin by atmel.... is this from installing WinAVR? or is this something different? and what is the difference between this and WinAVR... ?

    If it not WinAVR, how do i use WinAVR in conjunction with AVRstudio?

    Thanks
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    WINAVR is the C-language compiler. What you describe sounds like you were successful in installing AVRSTUDIO4 and WINAVR.

    If you want to write your AVR code in C then all need to do launch AVRSTUDIO4 and select AVR-GCC. After answering a few startup question you should find yourself in the C-language editor.

    hgmjr
     
  3. Mazaag

    Thread Starter Senior Member

    Oct 23, 2004
    255
    0
    okay perfect,

    I have everythign now, everything is ste up , i tested the STK and its working fine, serial port working fine, everything PERFECT

    now its time to start programming..
    I have some experience programming in Assembly and C, but I am not exactly sure how to access registers and set registers to values using C.

    Are there any code samples that I could look at ? like very basic code samples ( set portB to output, output to LEDs , delay , etc)
     
  4. Mazaag

    Thread Starter Senior Member

    Oct 23, 2004
    255
    0
    Another thing,

    When i'm using the C compiler, I can't use the include files that are in AVRStudio (since they are asm) ...

    To my understanding, these include files have the port and registers addresses saved as variables , so that you can access the ports by name... is that correct?

    If i'm going to be programming in C , does WinAVR have the equivalent include files for the different AVRs ?
     
  5. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Give me a moment and I will get you a sample c program.

    Are you going to be around for the next 30 minutes to an hour?

    hgmjr
     
  6. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Take a look at this website. It has tons of examples on how to program the AVR using WINAVR.

    hgmjr
     
  7. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    If you haven't already found it by now, the WINAVR folder containing the include files to which you will be referencing from time to time in your code. When you use the "#include" compiler directive you will need to know the folder it is in so that you can properly specify the path to the folder.

    hgmjr
     
  8. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Code ( (Unknown Language)):
    1.  
    2. #include <avr/io.h>
    3.  
    4. void delay(unsigned int delay_val)
    5. {
    6.   unsigned int temp;
    7.   temp=0;
    8.   do
    9.   {
    10.  
    11.   temp++;
    12.   } while(temp <= delay_val);
    13. }
    14.  
    15. int main(void)
    16. {
    17.  DDRB = 0x01;
    18.  PORTB = 0X01;
    19.  
    20.  for(;;)
    21.  {
    22.  delay(30000);
    23.  PORTB = PINB & ~0x01; // on
    24.  delay(9000);
    25.  PORTB = PINB | 0x01; // off
    26.  delay(6000);
    27.  PORTB = PINB & ~0x01; // on
    28.  delay(6000);
    29.  PORTB = PINB | 0x01; // off
    30.  }
    31.  return(0);
    32. }
    33.  
    34.  
    Take a look at this example.

    This was an early effort at coding in which I was turning an LED off and on. In this example I was flashing the LED that I had cabled to the least significant bit in PORTB.

    There will be the occasional small rock in your shoe as you become familiar with WINAVR software development tool. Don't get too frustrated. It is usually something simple that needs to be satisfied before you can proceed.

    hgmjr
     
    farwafab likes this.
  9. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    The same include files are used by both ASM and C.

    hgmjr
     
  10. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    If you can, I would recommend you get yourself an inexpensive IC puller. It will pay for itself by preventing you from damaging the board or the IC when removing the AVR microprocessor from the ATK500 socket.

    RadioShack has one that is pretty cheap.

    hgmjr
     
  11. Mazaag

    Thread Starter Senior Member

    Oct 23, 2004
    255
    0
    I played around and managed to do a really nice output pattern on the board LEDs :D

    now i'm investigating taking inputs.. I'm trying to make each swtich control the corresponding LED above it...

    this is what I tried, and it doesn't seem to work:

    Code ( (Unknown Language)):
    1.  
    2. #include <avr/io.h>
    3. int main (void)
    4. {
    5.  
    6. PORTB = 0xFF;
    7. DDRB = 0xFF;
    8. DDRD = 0x00;
    9.  
    10. while (1)
    11. {
    12.  PORTB = PORTD ;
    13. }
    14. return 1;
    15. }
    16.  
    17.  
    18.  
    19.  
    20.  

    Port B is connected to the LEDs
    and PORT D is connected to the swtiches....
     
  12. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Try this slight change and let me know what you see.

    hgmjr
     
  13. Mazaag

    Thread Starter Senior Member

    Oct 23, 2004
    255
    0
    yup i just tried it and it worked :D

    but why PIND ? what is the difference between PIND and PORTD ? can PINB be used instead of PORTB in the output code ?
     
  14. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    I only have a vague notion of PIND versus PORTD but as I understand it PIND reflects the input state of the physical pins on portd. PORTD is the latched version of PIND. Whenever I read an input from a IO pin I alway use PINX not PORTX.

    I really should have warned you that this AVR stuff is addictive. I have been playing with AVRs for over a year and I can't get enough of it.

    hgmjr
     
  15. Mazaag

    Thread Starter Senior Member

    Oct 23, 2004
    255
    0
    its pretty sick, thanks alot for your help, you got me addicted too to this stuff !
     
  16. Mazaag

    Thread Starter Senior Member

    Oct 23, 2004
    255
    0
    Is it possilbe to implement arrays in AVRs ?
     
  17. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    You now have a new tool in your arsenal with which to build the robot of your dreams. Just remember, if you find that one AVR is not providing you the processing horsepower you need don't hesitiate to revert to distributed processing. You can divide up the job and assign each slave processor with its own task and have a master processor orchestrate the entire group.

    Several things that I can help you avoid.

    1. The ATMEGA16 microcontroller that comes with the STK500 may have its JTAG configuration fuse set. The port IO pins that correspond to the JTAG lines will not operate as discrete IO lines if this is the case. AVRSTUDIO4 allows you to disable the JTAG disable the feature by using the FUSE control panel.

    2. The STK500, while the latest version of development board out there, is hard pressed to keep up the evolution of some of the newer AVR devices. The sockets work for the many of the newer devices but in some cases a couple of the IO pins are not brought out to the configuration headers for use with the LEDs and switches. The pdf schematic to the STK500 is on the CD that came with the kit. Copy it to your computer and consult it often.

    3. When you use the internal RC oscillator as the sole clock source in your project, be careful not to accidentally set the clock select fuse for external clock. If you do the AVR device will go catatonic. All is not lost however. You will just need to put the AVR on your STK500 board and jumper the board to provide the external clock source so that you can access the clock select fuse and set it back to internal RC clock.

    4. The STK500 can be used to program about 40 of the AVR variants. That is what is so nice about the darn thing. One size fits pretty much all.

    Websites to bookmark:

    www.avrfreaks.net - a forum/community of AVR knowledgeable folks.
    www.avrbeginners.net - a nice simple assembly language for AVR tutorial
    www.sparkfun.com - this website sells some fairly neat prototyping boards that are very attractively priced.
    www.atmel.com - Go here for all the datasheets and some pretty useful application notes. When in doubt read the datasheet.

    If I think of anythingelse I will post it here.

    Happy roboting,
    hgmjr
     
  18. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    Just to add to the above comments:

    Have you tried the simulator in AVRStudio? It can be great tool.
    Using the 6-pin ICSP you can program off-chip devices which comes in handy. It supplies enough juice to power the chip.
    The tutorial section of the AVRfreaks website has some really good tutorials on Timers and EEPROM.

    enjoy!
     
  19. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    Yes WinAVR is a full function compiler.

    Code ( (Unknown Language)):
    1. unsigned char array[5] = {0,1,2,3,4};
    On a microcontroller you have limited resources so I usually try to use the smallest type of variable that will do the job.
     
Loading...