论坛风格切换切换到宽版
  • 4993阅读
  • 6回复

mplab ide编译出错 [复制链接]

上一主题 下一主题
离线XLDZZ
 
发帖
443
只看楼主 倒序阅读 0楼 发表于: 2009-09-01
在对以下程序编译时报错
报错内容为overwriting previous address contents (0004)

list   p=16f877
#include "p16f877a.inc"
__config b�'0x3b31

cunt     equ 30h;ccp中断计数暂存
cunt_pro   equ 31h;用于计算中间寄存器
cunt_back   equ 32h
temp_cunt   equ 33h;用于显示代码暂存
cunt_time   equ 34h;2s延时计数器
ge       equ 35h;个位
shi       equ 36h;十位
bai       equ 37h;百位
mpy_h     equ 38h;乘积高8位
mpy_l     equ 39h;乘积低8位
time_cunt   equ 4ah;时间寄存器
flg       equ 4bh;标志寄存器(bit0为2s时间到,bit1表示ccp1中断,bit3表示允许tmr1中断)
temp     equ 4ch;中间寄存器
status_temp equ 4dh;状态位暂存
w_temp     equ 4eh;w暂存
pcl_temp   equ 4fh;pcl暂存
cunt_deg   equ 50h


org 000h
movlw 0ah
movwf cunt_time
movlw 01dh
movwf cunt_deg
goto main
org 004h
goto int
;----中断地址分配----------------

main
call io_reset;io初始化
call int_reset;中断初始化
open_check
btfss portc,4
goto open_check
call delay750us
btfss portc,4
goto open_check
banksel pie1
bsf pie1,2;开ccp中断
banksel portc
loop_next
btfss portc,5
goto loop_dsp
clrf portd
call sc
call delay750us
btfss portc,5
goto loop_dsp
goto pro_2s
;----------主程序--------
int
btfss pir1,2;ccp是否中断
goto int_next
bcf pir1,2;清标记
call zh
goto int_next
;-------ccp部分----------
int_next
btfss flg,3;是否允许tmr1中断
goto int_tm1if
btfss pir1,0
goto int_tm1if
bcf pir1,0;请标记
call time
goto int_ret
int_tm1if
bcf pir1,0;清定时器1中断标记
goto int_ret
int_ret
retfie
;----------中断服务------------
pro_2s
banksel pie1
bcf pie1,2;关ccp中断
banksel tmr1l
movf cunt,0
movwf cunt_pro;把cunt(ccp中断次数计数器)值送往cunt_pro计数器
clrf cunt;清ccp中断计数器
clrf ge
clrf shi
clrf bai
bsf flg,3 ;开定时器软件中断标志
banksel pie1
bsf pie1,2;开ccp中断
bsf pie1,0;开定时器1中断
banksel t1con
bsf t1con,0;开定时器1
bcf flg,0 ;清时2s间到标记
bsf portd,4
call sc
s2_check
btfss flg,0
goto s2_check
banksel pie1
bcf pie1,2
bcf pie1,0
banksel pir1
goto loop_dsp
bsf portd,6
call sc
call mpy
call dev
goto loop_dsp
mpy
movf cunt,0
movwf cunt_back
mpy_loop
addwf cunt,0
btfss status,0
goto mpy_np
incf mpy_h
mpy_np
decfsz cunt_deg
goto mpy_loop
goto mpy_end
mpy_end
movwf mpy_l
return
;-----------cunt*30-------------
dev
clrf ge
clrf shi
clrf bai
movf cunt_pro,0
subwf mpy_l,1
btfsc status,0
goto dev_call
btfss flg,4
goto dev_nx
goto dev_return
dev_nx
decf mpy_h,1
btfsc status,2
goto dev_call
bsf flg,4
dev_call
call zh
goto dev
dev_return
return
;-------------除法程序------------

loop_dsp
movf ge,0
movwf temp_cunt
call table
movwf portb
call sc_ge
movf shi,0
movwf temp_cunt
call table
movwf portb
call sc_shi
movf bai,0
movwf temp_cunt
call table
movwf portb
call sc_bai
goto loop_next
;-----------动态显示----------------


io_reset
banksel trisc
movlw 0ffh
movwf trisc
movlw 00h
movwf trise
movwf trisd
movwf trisb
banksel portc
clrf portc
clrf portd
clrf portb
clrf porte
clrf ge
clrf shi
clrf bai
clrf flg
clrf time_cunt
call sc
return
;-----------io初始化---------------
int_reset
banksel intcon
movlw b�'开总中断
movwf intcon
banksel pie1
movlw   b�'
movwf pie1;只允许tmr1,ccp未开中断
banksel pir1
movlw b�'
movwf t1con;分频比1:8,不同步,关tmr1
movlw b�'
movwf ccp1con
clrf pir1;清第二中断标志
clrf tmr1l
clrf tmr1h
return
;----------中断初始化--------------




zh
movlw 0ah
movwf temp
incf cunt,1;ccp中断计数器加1
incf ge,1 ;个位加1
movf temp,0
subwf ge,0
btfss status,2
goto zh_return
incf shi,1
clrf ge
movf temp,0
subwf shi,0
btfss status,2
goto zh_return
incf bai,1
clrf shi
movf temp,0
subwf bai,0
btfss status,2
goto zh_return
clrf ge
clrf shi
clrf bai
zh_return
return
;---------------计算转速-------------

time
decfsz cunt_time
goto int_ret
bsf flg,0;2s标志位置位
movlw 0ah
movwf cunt_time
return
;---------------2s定时-------------------


delay1ms:   movlw 09fh
        movwf 20h
lp01:     movlw 0ffh
        movwf 21h
lp11:     movlw 02ch
        movwf 22h
lp21:     decfsz 22h
        goto   lp21
        decfsz 21h
        goto   lp11
        decfsz 20h
        goto   lp01






        return
;----------1ms延时程序---------------



delay750us:
        movlw 0ffh
        movwf 26h
        loop750
        nop
        nop
        nop
        nop
        decfsz 26h,1
        goto loop750
        return
;----------750us延时程序----------------
delayn
nop
nop
nop
nop
nop
return





sc
movlw 06h
movwf porte
call delay750us
clrf porte
return
;--------374锁存程序--------------------

sc_ge
movlw 01h
movwf portd
movlw 06h
movwf porte
call delayn
clrf porte
return
;-------动态个位显示锁存----------------
sc_shi
movlw 02h
movwf portd
movlw 06h
movwf porte
call delayn
clrf porte
return
;-------动态十位显示锁存----------------
sc_bai
movlw 04h
movwf portd
movlw 06h
movwf porte
call delayn
clrf porte
return
;-------动态百位显示锁存----------------
table
movf temp_cunt,0
addwf pcl,1
retlw 0d7h
retlw 012h
retlw 0cbh
retlw 05bh
retlw 01eh
retlw 05dh
retlw 0ddh
retlw 013h
retlw 0dfh
retlw 05fh
;-----------显示解码程序-----------------
end
离线BG2WAH
发帖
603
只看该作者 1楼 发表于: 2009-09-02
org   000h
movlw   0ah     (00)
movwf   cunt_time (01)
movlw   01dh     (02)
movwf   cunt_deg   (03)
goto   main     (04) ??????????????
org   004h     (05)
goto   int     (06)

地址0x0004是中断入口,已经被你占用了!!!???

正确的作法:
org   0x0000     ; 存放程序启地址
goto   main       ; 到主放序
org   0x0004     ; 中断入口
movwf w_temp     ; 保护工作寄存器内容
;.............
另外,表格要尽可的靠前。
离线BG2IVR
发帖
243
只看该作者 2楼 发表于: 2009-09-02
楼上正解

楼主为什么不用c语言呢?
离线XLDZZ
发帖
443
只看该作者 3楼 发表于: 2009-09-02
我不是学这个行业的,单片机是业余爱好。

现在只会用汇编,过些时间在往c上走
离线BG2IVR
发帖
243
只看该作者 4楼 发表于: 2009-09-04
c比汇编好学多了,真的
离线XLDZZ
发帖
443
只看该作者 5楼 发表于: 2009-09-04
遇到一个怪问题,问题如下。


  上述程序是一个测无刷电机转速的程序,大概原理为:
当霍尔信号上升跳变时利用ccp捕获并发生中断,来测量转速。并显示在led上。

  可是当触发中断以后(不稳定,有时几个,有时几十个)就不在显示数字了,类似中断死循环。可查看中断程序也没有问题。后来怀疑是否为跨页面调用才出现问题。
 
后来把放在最后的表格往前移动后,能显示了。就是还有些字体不该显示部分有些微亮。

不知道pic的程序量如何计算,是否为1条程序就占用一个13未宽的地址,还是不同的指令占用不同宽度的地址。
离线BG2WAH
发帖
603
只看该作者 6楼 发表于: 2009-09-05
1、ccp是捕捉,当条件满足时捕捉tmr1值,可以用来测脉冲宽度。计数建议用tmr1试试,最大计数值65535,测转数应该可以。2、pic16f读表是通过修改pc偏移量实现的,所以,表格要放在程序地址255以内(若采用读大表方式没有地址限制)。3、led如果是动态扫描方式显示,建议在送数前将显示消隐(关闭)之后送数,既消隐--送数--显示……如果是静态方式,可能是刷新率太高造成显示混乱,每秒钟刷新3至5次就可以。4、如果你想写延时子程序,ide里有跑表,比计算更方便。个人观点,仅供参考。