从硬件中的半字节接受字节的最快方法(8051)

时间:2018-02-05 22:59:18

标签: performance assembly optimization microcontroller 8051

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

两个微处理器仅通过4条I / O线和一条中断线相互通信。我试图尽可能快地接收一个字节,但我提出的代码让我觉得我没有选择最佳解决方案,但这是我到目前为止所得到的:

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字符处理例程中也是如此。

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

1 个答案:

答案 0 :(得分:2)

无需在中断中进行半字节处理。只需将4位存储起来。

假设您可以全局分配R0,代码可以简单如下:

Did not run any tasks
This progress looks :| because there were tasks that were not granted run permission by the scheduler

不会比那更快。

如果你绝对不能保留R0,但你至少可以安排使用不同的寄存器组,例如#0和#1,那么你可以使用bit set / clear切换回2个周期,而不是5个org 13h mov @r0, p1 inc r0 reti 方法。