无效的寄存器



我想让闪烁变成led。我不明白为什么寄存器不起作用。这是我的代码:

; Main.asm file generated by New Project wizard
;
; Created:   Ср апр 7 2021
; Processor: ATmega328P
; Compiler:  AVRASM (Proteus)
.include "C:UsersuserDownloadsm328Pdef.inc"
; DEFINITIONS
.list
.def temp=r16
.cseg
.org 0
; Reset Vector
rjmp  Start

Start:
ser temp
out DDRB, temp
clr temp
SBR TCCR1C, 0x00
SBR TCCR1B, 0x09
SBR TCCR1A, 0x40
Loop:
ldi temp, 1
out PortB, temp
clr temp
out PortB, temp
SBR OCR1AH, 0x0F
SBR OCR1AL, 0xFF
rjmp  Loop

寄存器是inc文件我的代码连接方案WIDW?非常感谢。

请参阅AVR指令集手册

指令SBR设置CPU(而非I/O(寄存器中的指定位SBR是指令ORI(带立即数的逻辑或(的同义词。指令SBR anything, 0x00没有任何意义,因为它不执行

您可能想要使用SBI(在I/O寄存器中只设置一个位:第二个操作数应该是位数(。但请注意,SBICBI仅适用于低32 I/O寄存器。像INOUT这样的指令使用最低64个I/O寄存器。其他寄存器应使用其内存空间(数据空间(地址进行访问。

在ATmega328P中(见数据表,30。第278页的寄存器摘要(寄存器TCCR1C TCCR1B TCCR1A只能使用其存储器地址访问。因此,不能在它们上使用SBIIN/OUT。相反,您必须使用LDS读取它们的内存位置,然后使用STS进行回写。例如:

// TCCR1B = 0x09
LDI temp, 0x09
STS TCCR1B, temp
// TCCR1B |= 0x09
LDS temp, TCCR1B
ORI temp, 0x09 // or you can use SBR here - it is the same instruction
STS TCCR1B, temp

最新更新