PIC18 汇编程序

[复制链接]
 楼主| 发表于 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后就乱跳了呢?
发表于 2010-3-24 20:42 | 显示全部楼层
老大,PCL是几个bit呀?

另外18的汇编支持表读了,别老retlw了
 楼主| 发表于 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]
发表于 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,所以查表查飞了。
 楼主| 发表于 2010-3-25 05:24 | 显示全部楼层
谢谢,我是想学学汇编啊,了解一下PIC18,看来手册中的代码有误了,ADDWF PCL,F ,看来之前还有读操作才行,MOVF PCL,F
发表于 2010-3-25 10:32 | 显示全部楼层
不是要读操作,是你的表所在的地址超过了PCL这8bit的表达范围,对PCL的操作又会自动加载PCLATH和PCLATU,这两个寄存器你没设置,为0,所以PC组装出来的结果并不是你要的表内的数据地址,所以飞了。
还是建议用18的表读指令来写
发表于 2010-3-27 10:18 | 显示全部楼层
我是新来的:lol
您需要登录后才可以回帖 登录 | 注册

本版积分规则

149

主题

800

帖子

5

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