Winavr Avr GCC
Winavr Avr GCC
GCC
AVR GCC
GNU Binutils
contains the GNU assembler (gas), and the GNU linker (ld), and many other utilities.
avr-as The Assembler. avr-ld The Linker. avr-ar Create, modify, and extract from libraries (archives). avr-ranlib Generate index to library (archive) contents. avr-objcopy Copy and translate object files to different formats. avr-objdump Display information from object files including disassembly. avr-size List section sizes and total size.
avr-nm List symbols from object files. avr-strings List printable strings from files. avr-strip Discard symbols from files. avr-readelf Display the contents of ELF format files. avr-addr2line Convert addresses to file and line. avr-c++filt Filter to demangle encoded C++ symbols.
AVR-Libc provides
many of the same functions found in a regular Standard C Library, and many additional library functions that is specific to an AVR.
GNU Make
interprets and executes a Makefile that is written for a project. A Makefile contains dependency rules and instructions on how to build output files from input files.
AVRDUDE
AVaRICE
is a back-end program to AVR GDB interfaces to the Atmel JTAG In-Circuit Emulator (ICE), to provide emulation capabilities.
WinAVR
Variable Types
Type bit char unsigned char signed char int short int unsigned int signed int long int unsigned long int signed long int float double Size (bits) 1 8 8 8 16 16 16 16 32 32 32 32 32 Range 0,1 -128 to 127 0 to 255 -128 to 127 -32768 to 32767 -32768 to 32767 0 to 65536 -32768 to 32767 -2147483648 to 2147483647 0 to 4294967295 -2147483648 to 2147483647 1.175e-38 to 3.402e38 1.175e-38 to 3.402e38
Memory Sections
Memory Sections
Memory Areas
Many of the devices have a minimal amount of RAM. This needs to be shared between
initialized and uninitialized variables (sections .data and .bss), the dynamic memory allocator, and the stack that is used for calling subroutines and storing local (automatic) variables.
PROGMEM
byte = mydata[i][j];
Inline Assembler
asm(code : output operand list : input operand list [: clobber list]);
assembler instructions as a single string constant: "in %0, %1" A list of output operands, separated by commas: "=r" (value) A comma separated list of input operands: "I" (_SFR_IO_ADDR(PORTD)) To avoid compiler optimization
asm volatile("in %0, %1" : "=r" (value) : "I" (_SFR_IO_ADDR(PORTD)));
asm volatile( "cli" "ld r24, %a0" "inc r24" "st %a0, r24" "sei" : : "e" (ptr) : "r24" ); cli ld r24, Z inc r24 st Z, r24 sei
Example C Program 1
// C version of led.asm #include <avr/io.h> unsigned char z; void main(void) { DDRB=0xFF; DDRD=0x00; while(1){ } } //I/O definition header file //declare z
//set all bits of portB for output //set all bits of portD for input
//infinite loop z = PIND; //read from PortD pins PORTB = z; //write to PortB port
Example C Program 1
Size VMA LMA File off Algn 00000076 00000000 00000000 00000094 2**0 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .data 00000000 00800060 00000076 0000010a 2**0 CONTENTS, ALLOC, LOAD, DATA 2 .bss 00000001 00800060 00800060 0000010a 2**0 ALLOC 3 .noinit 00000000 00800061 00800061 0000010a 2**0 CONTENTS 4 .eeprom 00000000 00810000 00810000 0000010a 2**0
. .
Example C Program 1
Example 2: (1)
void delay(){ int count_delay = 255; while(count_delay>0) count_delay--; return; } //function delay
void longdelay(){ //function longdelay int count_longdelay = 255; while(count_longdelay>0){ count_longdelay--; delay(); //function call } return; }
Example 2: (2)
void delay(){ int count_delay = 255; while(count_delay>0) count_delay--; return; } //function delay
void longdelay(){ //function longdelay int count_longdelay = 255; while(count_longdelay>0){ count_longdelay--; delay(); //function call } return; }
Example 2: (3)
#define F_CPU 4000000UL #include <util/delay.h> //void //void _delay_us (double __us) // The maximal possible delay is 262.14 ms / F_CPU in Mhz. _delay_ms (double __ms) // The maximal possible delay is 768 us / F_CPU in MHz.
led = 0x00; //Initial led value for (;;) { // loop forever timer interupts will change the led value outp(led, PORTB); } }
//Set data frame format: asynchronous mode,no parity, 1 stop bit, 8 bit size UCSRC=(1<<URSEL)|(0<<UMSEL)|(0<<UPM1)|(0<<UPM0)| (0<<USBS)|(0<<UCSZ2)|(1<<UCSZ1)|(1<<UCSZ0); //Enable Transmitter and Receiver and Interrupt on receive complete UCSRB=(1<<RXEN)|(1<<TXEN)|(1<<RXCIE); set_sleep_mode(SLEEP_MODE_IDLE); sei(); //enable global interrupts
UDR=Temp;
Pulse-width modulator (PWM) will ramp an LED on and off every two seconds.