gpt4 book ai didi

assembly - PIC汇编器中如何进行bank切换?

转载 作者:行者123 更新时间:2023-12-02 21:34:39 25 4
gpt4 key购买 nike

我对 PIC 汇编器中的库切换感到困惑...这适用于在 usart 上放置“Q”:

bsf PORTB,1         ;Set Transmit DIR (PORTB (0x6) not mirrored in other banks)
movlw 'Q' ;'Q' to work reg
movwf TXREG ;work reg to TXREG (TXREG (0x19) not mirrored in other banks)
clrwdt ;Clear watchdog
btfss TXSTA,TRMT ;Wait until 'Q' is shifted (TXSTA is 0x18, not mirrored)
goto $-2
bcf PORTB,1 ;Set Recive DIR

这同样有效:

BCF 0x3, 0x5        ;Switch to bank 0
BCF 0x3, 0x6
bsf PORTB,1 ;Set Transmit DIR
movlw 'Q' ;'Q' to work reg
movwf TXREG ;work reg to TXREG
BSF 0x3, 0x5 ;Switch to bank 1
clrwdt ;Clear watchdog
btfss TXSTA,TRMT ;Wait until 'Q' is shifted
goto $-2
BCF 0x3, 0x5 ;Switch to bank 0
bcf PORTB,1 ;Set Recive DIR

我已经检查过,当我不观看时,编译器不会进行任何库切换...什么时候必须切换库?

最佳答案

最好只使用 BANKSEL 自动进行银行切换。它是一个特殊的汇编程序指令,告诉汇编程序切换到正确的库。因此,如果您想访问 PORTB,只需在使用它之前使用 BANKSEL(PORTB) 即可。

PS:PORTB 位于 PIC16 系列的 BANK0 中,而不是代码中的 BANK1。

关于assembly - PIC汇编器中如何进行bank切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/824505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com