0

所以我的任务是创建一个正弦波,我想出了这个,它使用两个寄存器并且可以工作......

 DAC    EQU 0600h   ;DAC memory mapped at address 600h
tbl_len EQU 24  ;length of sine wave table

    ORG 8100H       ;start of program

sine:   mov R7, #tbl_len    ;initialise table counter
    mov R6, #0  ;initialise table pointer

sloop:  mov dptr, #table    ;load dptr with address of table
    mov a, R6   ;load acc with table pointer
    movc    a, @a+dptr  ;read from table + table pointer

    mov dptr, #DAC  ;load dptr with 0600 DAC base address
    movx    @dptr, a    ;Output table value from DAC
    acall   delay
    inc R6  ;inc table pointer
    djnz    R7, sloop   ;dec table counter until zero
    sjmp  sine  ;Repeat loop

delay:  mov R0, #11
loop:   djnz    R0, dloop   ;go around this loop 11 times
    ret

table:  DB  1,5,18,38,65,95,128,161,192,218,238,251
    DB  255,251,238,218,192,161,128,95,65,38,18,5

现在我被要求只使用一个寄存器。尽管我觉得这可能是一个非常简单的解决方案,但我还是有点困惑。任何提示都会很棒。

4

0 回答 0