AVRstudio and WinAVR

Thread Starter

Mazaag

Joined Oct 23, 2004
255
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
 

hgmjr

Joined Jan 28, 2005
9,027
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
 

Thread Starter

Mazaag

Joined Oct 23, 2004
255
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)
 

Thread Starter

Mazaag

Joined Oct 23, 2004
255
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 ?
 

hgmjr

Joined Jan 28, 2005
9,027
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
 

hgmjr

Joined Jan 28, 2005
9,027
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
 

hgmjr

Joined Jan 28, 2005
9,027
Rich (BB code):
#include <avr/io.h>
 
void delay(unsigned int delay_val)
{
  unsigned int temp;
  temp=0;
  do
  {
 
  temp++; 
  } while(temp <= delay_val);
}
 
int main(void)
{
 DDRB = 0x01;
 PORTB = 0X01;
 
 for(;;)
 {
 delay(30000);
 PORTB = PINB & ~0x01; // on
 delay(9000);
 PORTB = PINB | 0x01; // off 
 delay(6000);
 PORTB = PINB & ~0x01; // on
 delay(6000);
 PORTB = PINB | 0x01; // off
 }
 return(0);
}
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
 

hgmjr

Joined Jan 28, 2005
9,027
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 ?
The same include files are used by both ASM and C.

hgmjr
 

hgmjr

Joined Jan 28, 2005
9,027
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
 

Thread Starter

Mazaag

Joined Oct 23, 2004
255
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:

Rich (BB code):
#include <avr/io.h>
int main (void)
{

PORTB = 0xFF;
DDRB = 0xFF;
DDRD = 0x00;
 
while (1)
{
 PORTB = PORTD ;
}
return 1;
}

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

hgmjr

Joined Jan 28, 2005
9,027
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:

Rich (BB code):
#include <avr/io.h>
int main (void)
{
 
PORTB = 0xFF;
DDRB = 0xFF;
DDRD = 0x00;
 
while (1)
{
 PORTB = PIND ;
}
return 1;
}

Port B is connected to the LEDs
and PORT D is connected to the swtiches....
Try this slight change and let me know what you see.

hgmjr
 

Thread Starter

Mazaag

Joined Oct 23, 2004
255
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 ?
 

hgmjr

Joined Jan 28, 2005
9,027
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
 

hgmjr

Joined Jan 28, 2005
9,027
its pretty sick, thanks alot for your help, you got me addicted too to this stuff !
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
 

nanovate

Joined May 7, 2007
666
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!
 

nanovate

Joined May 7, 2007
666
Is it possilbe to implement arrays in AVRs ?
Yes WinAVR is a full function compiler.

Rich (BB code):
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.
 
Top