打印

PIC18 汇编程序

[复制链接]
1983|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
crazybee|  楼主 | 2010-3-24 07:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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后就乱跳了呢?
沙发
NE5532| | 2010-3-24 20:42 | 只看该作者
老大,PCL是几个bit呀?

另外18的汇编支持表读了,别老retlw了

使用特权

评论回复
板凳
crazybee|  楼主 | 2010-3-24 21:20 | 只看该作者
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. ;****************************************************************************** ;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 $ [img][/img]

使用特权

评论回复
地板
NE5532| | 2010-3-24 21:27 | 只看该作者
“The contents of PCLATH and PCLATU are transferred to the program counter by any operation that writes to PCL.  ”

就这句话了,你没设置PCLATH 和PCLATU,所以查表查飞了。

使用特权

评论回复
5
crazybee|  楼主 | 2010-3-25 05:24 | 只看该作者
谢谢,我是想学学汇编啊,了解一下PIC18,看来手册中的代码有误了,ADDWF PCL,F ,看来之前还有读操作才行,MOVF PCL,F

使用特权

评论回复
6
NE5532| | 2010-3-25 10:32 | 只看该作者
不是要读操作,是你的表所在的地址超过了PCL这8bit的表达范围,对PCL的操作又会自动加载PCLATH和PCLATU,这两个寄存器你没设置,为0,所以PC组装出来的结果并不是你要的表内的数据地址,所以飞了。
还是建议用18的表读指令来写

使用特权

评论回复
7
落雁惊鸿| | 2010-3-27 10:18 | 只看该作者
我是新来的:lol

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

149

主题

800

帖子

5

粉丝