Arduino Uno 通过汇编代码闪烁板载 LED 给出错误 Found no label/variable/constant named PD0
Arduino Uno blink onboard LED by an assembly code gives error Found no label/variable/constant named PD0
我找到了一个汇编代码如下
blink.asm
; blink.asm
; Pin Constant Values
; PD0 - 0
; PD1 - 1
; PD2 - 2
; PD3 - 3
; PD4 - 4
; PD5 - 5
; PD6 - 6
; PD7 - 7
; PB0 - 8
; PB1 - 9
; PB2 - 10
; PB3 - 11
; PB4 - 12
; PB5 - 13 - System LED
.DEF PTD = r16
.DEF PTB = r17
.MACRO Delay1
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
.ENDMACRO
start:
rcall init ; Initialize pins
loop:
Delay1
rcall setpinhigh
Delay1
rcall setpinlow
rjmp loop
init:
; Set pins 0-7 to low
ldi r16,(0<<PD7)|(0<<PD6)|(0<<PD5)|(0<<PD4)|(0<<PD3)|(0<<PD2)|(0<<PD1)|(0<<PD0)
out PORTD,r16
; Set pins 8-13 to low
ldi r17,(0<<PB5)|(0<<PB4)|(0<<PB3)|(0<<PB2)|(0<<PB1)|(0<<PB0)
out PORTB,r17
; Set pins 0-7 to output mode
ldi r18,(1<<DDD7)|(1<<DDD6)|(1<<DDD5)|(1<<DDD4)|(1<<DDD3)|(1<<DDD2)|(1<<DDD1)|(1<<DDD0)
out DDRD,r18
; Set pins 8-13 to output mode
ldi r19,(1<<DDB5)|(1<<DDB4)|(1<<DDB3)|(1<<DDB2)|(1<<DDB1)|(1<<DDB0)
out DDRB,r19
nop ; nop for settling down after pins set
ret ; return from subroutine
setpinhigh:
ldi PTD,1<<PD0
out PORTD, PTD
ret
setpinlow:
ldi PTD,0<<PD0
out PORTD, PTD
ret
delay:
ldi ZH,HIGH(65535)
ldi ZL,LOW(65535)
count:
sbiw ZL,1
brne count
ret
使我的 Arduino uno(ATmega328P 处理器)的板载 LED 闪烁。
我试图通过这个命令将代码编译成十六进制
avra blink.asm
但是我收到了
AVRA: advanced AVR macro assembler Version 1.3.0 Build 1 (8 May 2010)
Copyright (C) 1998-2010. Check out README file for more info
AVRA is an open source assembler for Atmel AVR microcontroller family
It can be used as a replacement of 'AVRASM32.EXE' the original assembler
shipped with AVR Studio. We do not guarantee full compatibility for avra.
AVRA comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of avra under the terms
of the GNU General Public License.
For more information about these matters, see the files named COPYING.
Pass 1...
Warning : No .DEVICE definition found. Cannot make useful address range check !
Pass 2...
blink.asm(62) : Error : Found no label/variable/constant named PD7
blink.asm(62) : Error : Found no label/variable/constant named PD6
blink.asm(62) : Error : Found no label/variable/constant named PD5
blink.asm(62) : Error : Found no label/variable/constant named PD4
blink.asm(62) : Error : Found no label/variable/constant named PD3
blink.asm(62) : Error : Found no label/variable/constant named PD2
blink.asm(62) : Error : Found no label/variable/constant named PD1
blink.asm(62) : Error : Found no label/variable/constant named PD0
blink.asm(63) : Error : Found no label/variable/constant named PORTD
blink.asm(66) : Error : Found no label/variable/constant named PB5
blink.asm(66) : Error : Found no label/variable/constant named PB4
blink.asm(66) : Error : Found no label/variable/constant named PB3
blink.asm(66) : Error : Found no label/variable/constant named PB2
blink.asm(66) : Error : Found no label/variable/constant named PB1
blink.asm(66) : Error : Found no label/variable/constant named PB0
blink.asm(66) : Maximum error count reached. Exiting...
done
Used memory blocks:
Code : Start = 0x0000, End = 0x0040, Length = 0x0041
Assembly aborted with 15 errors and 1 warnings.
如何修复这些错误?
我的 OS 是 Ubuntu 16.04.
这个错误告诉你汇编器不知道你所说的PD0
、PD1
...等等
是什么意思
解决方案
无需从头开始定义寄存器和引脚,这些定义已经存在...您可以下载并使用 m328Pdef.inc
将其添加到与您的代码相同的文件夹中,然后将其包含在代码的顶部,如下所示
.include "./m328Pdef.inc"
注意:
m328Pdef.inc 只是 ATmega328P
的一些寄存器和位定义
我找到了一个汇编代码如下
blink.asm
; blink.asm
; Pin Constant Values
; PD0 - 0
; PD1 - 1
; PD2 - 2
; PD3 - 3
; PD4 - 4
; PD5 - 5
; PD6 - 6
; PD7 - 7
; PB0 - 8
; PB1 - 9
; PB2 - 10
; PB3 - 11
; PB4 - 12
; PB5 - 13 - System LED
.DEF PTD = r16
.DEF PTB = r17
.MACRO Delay1
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
.ENDMACRO
start:
rcall init ; Initialize pins
loop:
Delay1
rcall setpinhigh
Delay1
rcall setpinlow
rjmp loop
init:
; Set pins 0-7 to low
ldi r16,(0<<PD7)|(0<<PD6)|(0<<PD5)|(0<<PD4)|(0<<PD3)|(0<<PD2)|(0<<PD1)|(0<<PD0)
out PORTD,r16
; Set pins 8-13 to low
ldi r17,(0<<PB5)|(0<<PB4)|(0<<PB3)|(0<<PB2)|(0<<PB1)|(0<<PB0)
out PORTB,r17
; Set pins 0-7 to output mode
ldi r18,(1<<DDD7)|(1<<DDD6)|(1<<DDD5)|(1<<DDD4)|(1<<DDD3)|(1<<DDD2)|(1<<DDD1)|(1<<DDD0)
out DDRD,r18
; Set pins 8-13 to output mode
ldi r19,(1<<DDB5)|(1<<DDB4)|(1<<DDB3)|(1<<DDB2)|(1<<DDB1)|(1<<DDB0)
out DDRB,r19
nop ; nop for settling down after pins set
ret ; return from subroutine
setpinhigh:
ldi PTD,1<<PD0
out PORTD, PTD
ret
setpinlow:
ldi PTD,0<<PD0
out PORTD, PTD
ret
delay:
ldi ZH,HIGH(65535)
ldi ZL,LOW(65535)
count:
sbiw ZL,1
brne count
ret
使我的 Arduino uno(ATmega328P 处理器)的板载 LED 闪烁。
我试图通过这个命令将代码编译成十六进制
avra blink.asm
但是我收到了
AVRA: advanced AVR macro assembler Version 1.3.0 Build 1 (8 May 2010)
Copyright (C) 1998-2010. Check out README file for more info
AVRA is an open source assembler for Atmel AVR microcontroller family
It can be used as a replacement of 'AVRASM32.EXE' the original assembler
shipped with AVR Studio. We do not guarantee full compatibility for avra.
AVRA comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of avra under the terms
of the GNU General Public License.
For more information about these matters, see the files named COPYING.
Pass 1...
Warning : No .DEVICE definition found. Cannot make useful address range check !
Pass 2...
blink.asm(62) : Error : Found no label/variable/constant named PD7
blink.asm(62) : Error : Found no label/variable/constant named PD6
blink.asm(62) : Error : Found no label/variable/constant named PD5
blink.asm(62) : Error : Found no label/variable/constant named PD4
blink.asm(62) : Error : Found no label/variable/constant named PD3
blink.asm(62) : Error : Found no label/variable/constant named PD2
blink.asm(62) : Error : Found no label/variable/constant named PD1
blink.asm(62) : Error : Found no label/variable/constant named PD0
blink.asm(63) : Error : Found no label/variable/constant named PORTD
blink.asm(66) : Error : Found no label/variable/constant named PB5
blink.asm(66) : Error : Found no label/variable/constant named PB4
blink.asm(66) : Error : Found no label/variable/constant named PB3
blink.asm(66) : Error : Found no label/variable/constant named PB2
blink.asm(66) : Error : Found no label/variable/constant named PB1
blink.asm(66) : Error : Found no label/variable/constant named PB0
blink.asm(66) : Maximum error count reached. Exiting...
done
Used memory blocks:
Code : Start = 0x0000, End = 0x0040, Length = 0x0041
Assembly aborted with 15 errors and 1 warnings.
如何修复这些错误?
我的 OS 是 Ubuntu 16.04.
这个错误告诉你汇编器不知道你所说的PD0
、PD1
...等等
解决方案
无需从头开始定义寄存器和引脚,这些定义已经存在...您可以下载并使用 m328Pdef.inc
将其添加到与您的代码相同的文件夹中,然后将其包含在代码的顶部,如下所示
.include "./m328Pdef.inc"
注意: m328Pdef.inc 只是 ATmega328P
的一些寄存器和位定义