我有一个较小的8051微控制器(AT89C4051(连接到较大的微控制器(AT89S52(,并且较大的一个运行较小的时钟。大个子的晶体速度为22.1184MHz。文档指出,由于啤酒线控制较小的微型,因此其时钟速度限制为3.6MHz。
两个micros仅使用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字符处理程序中,也可以在任何时候触发硬件。
。我可以在此处对此代码执行哪些优化以使其运行速度更快?
无需在中断中进行nibble处理。只需存放4位进入时即可。
假设您可以在全球分配R0,则代码可以像:
一样简单org 13h
mov @r0, p1
inc r0
reti
不会比那快得多。
如果您绝对不能保留R0,但是您至少可以安排使用一个不同的注册银行,例如#0和#1,然后您可以使用位设置/清除在2个周期中切换并返回,而不是5用于push psw
方法。