微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Arduino Uno 通过汇编代码闪烁板载 LED 给出错误 Found no label/variable/constant named PD0 解决方案

如何解决Arduino Uno 通过汇编代码闪烁板载 LED 给出错误 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.

如何修复这些错误

我的操作系统是 Ubuntu 16.04。

解决方法

这个错误告诉你汇编器不知道你说的PD0PD1...等是什么意思

解决方案

您可以下载并使用 m328Pdef.inc

,而不是从头开始定义这些定义。

将其与您的代码添加到同一文件夹中,然后将其包含在您的代码顶部,如下所示

.include "./m328Pdef.inc"

请注意m328Pdef.inc 只是 ATmega328P 的一些寄存器和位定义

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。