搜索
bottom↓
回复: 6

PIC18 查表程序为什么会出错?

[复制链接]

出0入0汤圆

发表于 2010-3-24 07:10:19 | 显示全部楼层 |阅读模式
Main:
        MOVLW D'4'
        MOVWF EXAMPLE
        MOVF EXAMPLE,W
        CALL TABLE
        GOTO $
       
        ;ORG 0x0200
TABLE
         ADDWF PCL,F
        RETLW H'01'
        RETLW H'02'
        RETLW H'03'
        RETLW H'04'
       
;        *** main code goes here ***

如果ORG 0X0200注释掉,程序就工作很正常,为什么加上去后,PC在ADDWF PCL,F后就乱跳了呢?

出0入0汤圆

发表于 2010-3-24 08:27:34 | 显示全部楼层
要设置pclath=2

出0入0汤圆

发表于 2010-3-24 08:29:16 | 显示全部楼层
example=4,是RETLW H'04' 的下一个地址

出0入0汤圆

 楼主| 发表于 2010-3-24 09:05:03 | 显示全部楼层
谢谢,还要这样用啊,那就不大方便了,手册里这样写的

The contents of PCLATH and PCLATU are transferred
to the program counter by any operation that writes to
PCL.  Similarly,  the  upper  2  bytes  of  the  program
counter are transferred to PCLATH and PCLATU by an
operation that reads PCL. This is useful for computed
offsets  to  the  PC  (see  Section 5.1.6.1  “Computed
GOTO”).
The PC addresses bytes in the program memory. To
prevent the  PC  from  becoming misaligned  with  word
instructions,  the Least  Significant  bit (LSb)  of  PCL  is
fixed  to  a  value  of ‘0’.  The  PC  increments  by  two  to
address   sequential   instructions   in   the   program
memory.
The   CALL,   RCALL,   GOTO   and   program   branch
instructions write to the program counter directly. For
these   instructions,   the   contents   of   PCLATH   and
PCLATU are not transferred to the program counter.



(原文件名:未命名.jpg)

上面不是说在读PCL的时候 PCLATH,PCLATU不是自动从PC更新过来吗?奇怪

;******************************************************************************
;Start of main program
; The main program code is placed here.
        ORG 0x1000
TABLE
        ;ADDWF PCL
        ;MOVWF PCL,F
       
        ADDWF PCL,F
        RETLW H'0F'
        RETLW H'0E'
        RETLW H'0D'
        RETLW H'0C'
        RETLW H'0B'
        RETLW H'0A'
        RETLW H'09'
        RETLW H'08'
        RETLW H'07'



Main:
        MOVLW H'10'
        MOVWF PCLATH
        MOVLW D'4'
        CALL TABLE
        GOTO $

出0入0汤圆

 楼主| 发表于 2010-3-24 16:34:18 | 显示全部楼层
wheat,在吗?

出0入0汤圆

发表于 2010-3-25 13:18:28 | 显示全部楼层
18F,你最好不要用16F的模式来搞。用专门的查表指令去弄。

出0入0汤圆

 楼主| 发表于 2010-3-25 16:54:37 | 显示全部楼层
嗯,谢谢,PIC18我这样搞搞就是为了学习一下,它的内部结构,编程主要还是用C,目前!
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-8 22:43

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表