When I try to build my program containing these lines
.equ PORTB =0x18 ;Port B's output register .equ DDRB =0x17 ;Port B's Data Direction Register
I get the following error messages
Invalid redefinition of 'PORTB'
Invalid redefinition of 'DDRD'
What's wrong? I'm using Atmel Studio 6.2
Ah, that's consequence of a underworld activity done by atmel studio (but for a good cause). The error says that DDRB and PORTB are redefined, which means that they are already defined somewhere. If you see the build command line closely you will understand the details :-) C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR Assembler\Native\2.1.1103\avrassembler\avrasm2.exe -fI -o "AssemblerApplication1.hex" -m "AssemblerApplication1.map" -l "AssemblerApplication1.lss" -S "AssemblerApplication1.tmp" -W+ie -im128def.inc -d "C:\Users\soundararajan\Documents\Atmel Studio\6.2\AssemblerApplication1\AssemblerApplication1\Debug/AssemblerApplication1.obj" "C:\Users\soundararajan\Documents\Atmel Studio\6.2\AssemblerApplication1\AssemblerApplication1\AssemblerApplication1.asm" -I "C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR Assembler\Native\2.1.1103\avrassembler\Include" It would have included -im128def.inc which already defines PORTB and DDRB. So the assembler throws redefinition error. ! To fix it , you have two solutions. 1. Don't include the "Include file". To do that . i. Go to Solution explorer. ii. Right click Project Node -> Then Properties iii. Go to general tab. iv. Delete the entry $(IncludeFile). Now build the project, it should work. :-) as follows
.equ PORTB = 0x17
.equ DDRB = 0x19
LDI R20, 0x18
OUT PORTB, R20 ;Port B's output register
OUT DDRB, R20 ;Port B's Data Direction Register
2. Don't redefine the "macros". They are predefined and ready for use. To use them type the following code i. Make sure you have $(IncludeFile) in Include option of project properties. ii. Paste the following code LDI R20, 0x18 OUT PORTB, R20 ;Port B's output register LDI R20,0x17 OUT DDRB, R20 ;Port B's Data Direction Register As always, Happy working with Atmel studio :-)