【问题标题】:Fastest method to accept a byte from a nibble in hardware (8051)在硬件中接受半字节字节的最快方法 (8051)
【发布时间】:2018-02-05 22:59:17
【问题描述】:

我有一个较小的 8051 微控制器 (AT89C4051) 连接到一个较大的微控制器 (AT89S52),较大的微控制器运行较小的微控制器的时钟。大的晶体速度是22.1184Mhz。文档指出,由于 ALE 线控制的是较小的微控制器,因此其时钟速度限制为 3.6Mhz。

两个微控制器之间只有 4 条 I/O 线和 1 条中断线相互通信。我试图让一个字节的接收尽可能快,但我想出的代码让我觉得我没有选择最好的解决方案,但这是我到目前为止得到的:

org 0h
ljmp main ;run initialization + program

org 13h         ;INT1 handler - worse case scenario: 52uS processing time I think?
  push PSW      ;save old registers and the carry flag
  mov PSW,#18h  ;load our register space
  mov R7,A      ;save accumulator (PUSH takes an extra clock cycle I think)
  mov A,P1      ;Grab data (wish I could grab it sooner somehow)
  anl A,#0Fh     ;Only lowest 4 bits on P1 is the actual data. other 4 bits are useless
  djnz R2,nonib2   ;See what nibble # we are at. 1st or 2nd?
        orl A,R6   ;were at 2nd so merge previously saved data in
        mov @R0,A  ;and put it in memory space
        inc R0     ;and increment pointer
        mov R2,#2h ;and reset nibble number
  nonib2:
  swap A           ;exchange nibbles to prevent overwriting nibble later
  mov R6,A         ;save to R6 high nibble
  mov A,R7         ;restore accumulator
  pop PSW          ;restore carry and register location
reti               ;return to wherever

main:
  mov PSW,#18h ;use new address for R0 through R7 to not clash with other routines
  mov R1,#BUFCMD ;setup start of buffer space as R1
  mov R2,#2h     ;set # nibbles needed to process byte
  mov PSW,#0h
  mov IE,#84h    ;enable external interrupt 1
  ..rest of code here...

我们必须假设这可以在任何时候由硬件触发,即使在使用所有寄存器和累加器的时间敏感 LCD 字符处理例程中也是如此。

我可以在此处对此代码执行哪些优化以使其运行得更快?

【问题讨论】:

    标签: performance assembly optimization microcontroller 8051


    【解决方案1】:

    中断中不需要做半字节处理。只需在输入时存储 4 位即可。

    假设你可以全局分配R0,代码可以很简单:

    org 13h 
    mov @r0, p1
    inc r0
    reti
    

    不会比这更快。

    如果您绝对不能保留 R0,但您至少可以安排使用单个位不同的寄存器组,例如#0 和 #1,然后您可以使用 bit set/clear 在 2 个周期内切换和返回,而不是 push psw 方法的 5。

    【讨论】:

    • 但我需要进行处理,因为我实际上是通过半字节通道传输字节,而且我的寄存器用于其他目的。例如,如果我正在同一芯片上进行内存到内存复制操作,那么我将使用地址 R0 和 R1 将字节从一个空间传输到另一个空间,那么您提供的代码将无法正常工作我。
    • 您可以用普通代码进行处理。您也没有在中断中显示任何其他处理。至于分配 R0,一切都是有代价的。你可以在没有它的情况下进行内存到内存的复制,它只会更慢。您决定要快速制作哪一个,ISR 或副本;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-14
    相关资源
    最近更新 更多