You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

寻求PIC16F1503平台下可行的函数跳转表实现示例

PIC16F1503函数跳转表实现问题(MPLAB X v6.20 + XC8 v2.46)

使用MPLAB X IDE v6.20搭配XC8 v2.46开发PIC16F1503时,尝试实现函数跳转表,通过索引调用独立库中的Function1和Function2,但现有代码执行异常。

经测试:

  • 将跳转表中的goto替换为BRA指令可正常运行
  • DW指令无法实现预期功能
  • 已验证PCL与PCLATH的地址设置逻辑可行,当前需完善动态表项选择代码

现有代码

; 调用目标例程
movlw   1   ; 应调用第二个函数
movwf   programIndex
call    runCurrentProgram

runCurrentProgram:
bcf     programIndex, 7     ; 清除旋转用的高位
rlf     programIndex, W     ; 将索引乘2
addlw   low programTable
movwf   tabLow              ; tabLow为临时变量
movlw   high programTable
btfsc   STATUS,STATUS_CARRY_POSITION
addlw   1
movwf   PCLATH
movf    tabLow,w
movwf   PCL

programTable:
goto    Function1
goto    Function2

汇编列表信息

Function1地址为014B,Function2为016F,使用BRA和DW指令生成的代码如下:

340     0100  324A                  bra Function1
341     0101  326D                  bra Function2
340     0100  014B                  dw  Function1
341     0101  016F                  dw  Function2

内容的提问来源于stack exchange,提问作者NomadAU

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 20:22:35