0

我一直在尝试使用带有 Arduino ATMega 328P 的 Proteus 8 在 AVR 中制作比较器。有人告诉我,比较实际上是由 Arduino 进行的,所以我只需要从该位置获取值,但我无法访问它。我尝试过使用 LDI、SBI 和 IN/OUT 指令,但没有奏效。

这是我现在的代码

    ;When the voltage on the positive pin AIN0 is higher than the voltage on the negative pin AIN1, the Analog Comparator output, ACO, is set.

;------Preps--------
LDI R16,0xFF    ;16 inFF
LDI R17,0x00    ;17 in00
LDI R18,0x80
LDI R19,0x40
LDI R21,0x20
OUT DDRC,R16    ;C out
;CBR ACSR,0x40  ;Clean the 6th ACSR bit to get the AIN0 input
STS ADCSRA,R18  ;Set the 7th ADCSRA bit (ADEN) to get AIN1 input
STS ADCSRB,R19  ;Set the 6th ADCSRB bit (ACME) to get AIN1 input
;CBR ACSR,0x0D   ;Clean 0,1 and 3 in ACSR to obtain toggle with ACO and disable the interruption
OUT ACSR,R21    ;Clean ACSR register


;----------------------------------------------------*

;----------------------------------------------------*
loop:
    NOP
    NOP
    IN  R20, ACSR       
    CPI R20,0x80  ;Compare registers r1 and r0
    BREQ aco1      ;If equal
    RJMP aco0      ;IFNE aco0 
    
aco1:
    OUT PORTC,R16 ;Turns on the led
    RJMP loop     ;Goes back to verify if ACO changed

aco0:
    OUT PORTC,R17 ;Turns off the led
    RJMP loop     ;Goes back to verify is ACO changed

这是大会

我无法配置输入,因为我无法存储在 ADCSRA/B

4

0 回答 0