Main Menu
Home
AVR News
Atmel AVR
AVR Development Tools
Valuable Tools
WinAVR toolset
Makefile for WinAVR
AVR Virtual Simulators
Hardware for prototyping
GCC and AVR-GCC
Short introduction to C
AVR-GCC Tutorial
Example AVR Projects
AVR-GCC articles
WinAVR Site Map
Scienceprog FORUM
ScienceProg BLOG
Disclaimer
WinARM Tutorial
Login Form





Lost Password?
No account yet? Register
Latest comments
Measuring motor speed and...
Dear Administrator The code above...
More...

Programming AVR ADC module...
hi please send me example usart with...
More...

Measuring motor speed and...
main.c: In function...
More...

Running TX433 and RX433 RF...
(Hopefully this is not a re-post). I am...
More...

Running TX433 and RX433 RF...
I just bnought a pair of the RX/TX 433...
More...

Syndicate
Friendly sites

Related Items:

Recommended sites


Latest News
AVR-GCC code compatibility PDF Print E-mail
Written by Administrator   
Tuesday, 24 July 2007

AVR-GCC compiler is changing during the time. There are so many things changed from recent versions of WinAVR to now. C language itself doesn't change much, but functions that deal with hardware all the time. Earlier even set up interrupt service routines would take some brain, now it is simplified to just one simple function ISR(). All necessary job is handled in macro level.

Another very important issue is operations with I/O bits. Functions with bits have changed since old versions of WinAVR. Compiler just throws errors that functions cannot be found. One solution is to write your own macros to support them or change the code with new syntax. Or use special Patch program which returns old functions to new WinAVR. You can download this patch from myrobot.ru. This patch returns functions that are not supported since WinAVR20050214. This is handy when you are trying to compile older source versions and do not want to change the code and do not want to download older WinAVR tools.

Patch returns inp, outp, sbi and cbi functions. According to these functions also there are no more bit_is_set and bit_is_clear logical tests. Dont wary, patch only returns these functions and leaves other as it is.

Table shows how these functions changed from old to new version:

Old

New

Comment

outp(0xff,DDRB);

DDRB = 0xff;

All port B pins as output

outp(0xff,PORTB);

PORTB = 0xff;

All port pins set to “1”

sbi(DDRB, DDB2);

DDRB |= 1<<DDB2;

Set port D pin 2 as output

cbi(DDRB, DDB2);

DDRB &= ~(1<<DDB2);

Set port D pin 2 as input

sbi(PORTB,PB2);

PORTB |= _BV(PB2); or

PORTB |= 1<<2; or

PORTB |= 1<<PINB2;

Set port B pin 2 to “1”

cbi(PORTB,PB2);

PORTB &= ~_BV(PB2); or

PORTB &= ~(1<<2); or

PORTB &= ~1<<PINB2;

Set port B pin 2 to “0”

if (bit_is_set(PIND,3))
{
...
}

if (PIND & (1<<PIND3))
{
...
}

Check if port D pin 3 equal to “1”

if (bit_is_clear(PIND,3))
{
...
}

if (!(PIND & (1<<PIND3)))
{
...
}

Check if port D pin 3 equal to “0”


As you see in table, there is always several ways to write same sentence. Version with PORTB |= 1<<PINB2; have been always supported and working as shift syntax is C standard bitwise operation, but it is no the most optimal solution as _BV() is more optimal as compiler itself shifts bits before writing result to compiled code. So this saves performance as microcontroller do not have to perform shift operation during execution - it just takes results that have been prepared by compiler during preprocessing.

As we can see WinAVR toolset is changing all the time. Some people like this some not. But for me WinAVR AVR-GCC toolset gives flexibility with open possibilities to write, modify, adapt microcontroller code.

Source: http://myrobot.ru


Related Items:

   

Users' Comments  
 

Average user rating

 


Add your comment
Only registered users can comment an article. Please login or register.

No comment posted



mXcomment 1.0.6 © 2007-2008 - visualclinic.fr
License Creative Commons - Some rights reserved
Next >

© 2008 WinAVR AVR-GCC Tutorial
Joomla! is Free Software released under the GNU/GPL License.