首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Arduino Uno在船上闪烁,由装配代码显示错误,没有发现标签/变量/常量名为PD0

Arduino Uno在船上闪烁,由装配代码显示错误,没有发现标签/变量/常量名为PD0
EN

Stack Overflow用户
提问于 2021-03-06 02:09:31
回答 1查看 264关注 0票数 0

我发现了如下的程序集代码

blink.asm

代码语言:javascript
复制
; 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

我的ATmega328P处理器( Arduino uno )的车载发光二极管。

我试图通过以下命令将代码编译为十六进制

代码语言:javascript
复制
avra blink.asm

但我收到

代码语言:javascript
复制
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.

如何修正这些错误?

我的操作系统是Ubuntu16.04。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-06 03:36:53

此错误告诉您,汇编程序不知道您所说的PD0PD1...etc的含义。

解决方案

而不是从零开始定义寄存器和引脚--这些定义已经存在.您可以下载并使用m328Pdef.inc

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

代码语言:javascript
复制
.include "./m328Pdef.inc"

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66501714

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档