• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users




(1) 2 »


pic16F685的問題
#1
初級會員
初級會員


查看用戶資訊
我的問題
MPLINK 4.21, Linker
Copyright (c) 2008 Microchip Technology Inc.
Error - section '.org_2' can not fit the absolute section. Section '.org_2' start=0x00000050, length=0x00000014
Errors : 1

用的是PIC16F685
看過之前的文章,修改LKR文件可以,可是不知道怎麼改

有試著把page0和page1的START和END做變動,但是還是會得到上面的問題,麻煩大大們指導一下,感謝!

LKR文件(16F685.lkr)

LIBPATH .
CODEPAGE NAME=page0 START=0x0 END=0x7FF
CODEPAGE NAME=page1 START=0x800 END=0xFFF
CODEPAGE NAME=.idlocs START=0x2000 END=0x2003 PROTECTED
CODEPAGE NAME=.config START=0x2007 END=0x2007 PROTECTED
CODEPAGE NAME=.calib START=0x2008 END=0x2008 PROTECTED
CODEPAGE NAME=eedata START=0x2100 END=0x21FF PROTECTED

我的程式
org 0x00
goto start
org 0x04
goto timer_isr
start:
.
.
.
main:
movfw count_tb
call LDTAB
movwf PORTC
goto main
timer_isr:
.
.
.
retfie

LDTAB movwf PC
org 0x0050
retlw 0xa0 ;0
retlw 0xbb ;1
retlw 0x62 ;2
retlw 0x2a ;3
retlw 0x39 ;4
retlw 0x2c ;5
retlw 0x24 ;6
retlw 0xb8 ;7
retlw 0x20 ;8
retlw 0x28 ;9
END

最後是查表的東西

發表於: 2008/10/29 23:01
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: pic16F685的問題
#2
高級會員
高級會員


查看用戶資訊
LDTAB movwf PC
; org 0x0050 <---------------此行是多餘的 , 不然就將查表放到 goto timer_isr 後
retlw 0xa0 ;0
retlw 0xbb ;1
retlw 0x62 ;2
retlw 0x2a ;3
retlw 0x39 ;4
retlw 0x2c ;5
retlw 0x24 ;6
retlw 0xb8 ;7
retlw 0x20 ;8
retlw 0x28 ;9
END

發表於: 2008/10/30 10:31
學問就是要多學多問
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: pic16F685的問題
#3
版主
版主


查看用戶資訊
org 0x00
goto start
org 0x04
goto timer_isr
start
:
.
.
.
main:
movfw count_tb
call LDTAB
movwf PORTC
goto main
timer_isr
:
.
.
.
retfie

LDTAB movwf PC
org 0x0050
retlw 0xa0 
;0
retlw 0xbb 
;1
retlw 0x62 
;2
retlw 0x2a 
;3
retlw 0x39 
;4
retlw 0x2c 
;5
retlw 0x24 
;6
retlw 0xb8 
;7
retlw 0x20 
;8
retlw 0x28 
;9
END


1. org 的語法請儘量改用 code 的定址方式
2. 建議將表格放在 0xnn00 的起始位址。
改寫你的程式如下:
[color=ff0000]

RESET_VECTOR    CODE    0x0000    processor reset vector
        
goto    start             go to beginning of program


INT_VECTOR      CODE    0x0004    
interrupt vector location    code     0x00

    
goto     timer_isr

 
Main_Prog    code    0x0100
LDTAB
     addwf     PCL
,F
    retlw     0xa0 
;0
    retlw     0xbb 
;1
    retlw     0x62 
;2
    retlw     0x2a 
;3
    retlw     0x39 
;4
    retlw     0x2c 
;5
    retlw     0x24 
;6
    retlw     0xb8 
;7
    retlw     0x20 
;8
    retlw     0x28 
;9
;
start:
    
movfw     count_tb ; ???
    
movlw    0x00
    call     LDTAB
    movwf     PORTC
    
goto     main
;
timer_isr:
.
.
.
    
retfie[/color]

發表於: 2008/10/30 11:06
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: pic16F685的問題
#4
初級會員
初級會員


查看用戶資訊
感謝大大們的回應,我把程式改成ryang大的寫法,然後出現2個問題

1.實際動作無預期,故用模擬方法去除錯,發現在call LATAB這裡時,它會進入LATAB去,可是執行addwf PCL,F後指標就消失了。
我把start中call之前改成
movlw 0x05
所以應該會回傳0x2c,只是指標消失。

2.我有以下訊息:
Message[305] C:\DSPIC\685FIRST\MAIN.ASM 95 : Using default destination of 1 (file).

有問題的程式
incf shift
我是要在中斷中對shift做累加的動作,後來發現,只要有incf的都會有這樣的訊息,可否問一下是為什麼?

再次麻煩各位大大了。

發表於: 2008/10/30 14:21
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: pic16F685的問題
#5
版主
版主


查看用戶資訊
"執行addwf PCL,F後指標就消失了"
1. 不了解你所謂的指標消失為何?

"有問題的程式
incf shift"

2. 程式的寫法有錯,正式寫法 incf shift,F

發表於: 2008/10/30 14:43
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: pic16F685的問題
#6
初級會員
初級會員


查看用戶資訊
指標消失指的是當模擬時按下F7會有一個綠色的指標,顯示程式執行到何處,就是這個綠色的指標

第2點已解決

後來再試,把查表的部份移動到中斷程式後面就可以了。

======================================

新的問題,我想把PORTA的0~2拿來做輸入腳,判斷按鍵,於是寫下下面程式:
start:
banksel TRISA
movlw b'11111111'
movwf TRISA
.
.
.
main:
call bottom_state
call LDTAB
movwf PORTC
.
.
.
bottom_state:
btfsc PORTA,1
goto bottom_exit
movlw 0x09
return
bottom_exit:
movlw 0x02
return
.
.
.

目的是想要依PORTA的第1腳來判斷有沒有被按下,以7段來觀察,有被按下則改變輸出。

問題是,當我把PORTA.1的腳接HIGH或LOW,都不會使7段變動,後來試了第0腳、第2腳,PORTB的第4~6腳皆無法動作,只有PORTB的第7腳會有反應,可是我想要的是讓PORTA的0和1腳做輸入...

發表於: 2008/10/30 18:45
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: pic16F685的問題
#7
版主
版主


查看用戶資訊
給個建議,寫程式一定要先讀過 Data Sheet 後再動手。16F685 有 12 個 AD channel 輸入,要先關掉AD輸入的功能。

4.2.1 ANSEL AND ANSELH REGISTERS
The ANSEL and ANSELH registers are used to disable
the input buffers of I/O pins, which allow analog voltages
to be applied to those pins without causing excessive
current. Setting the ANSx bit of a corresponding pin will
cause all digital reads of that pin to return ‘0’ and also
permit analog functions of that pin to operate correctly.
The state of the ANSx bit has no effect on the digital
output function of its corresponding pin. A pin with the
TRISx bit clear and ANSx bit set will operate as a digital
output, together with the analog input function of that
pin. Pins with the ANSx bit set always read ‘0’, which
can cause unexpected behavior when executing read
or write operations on the port due to the
read-modify-write sequence of all such operations.

發表於: 2008/10/31 9:55
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: pic16F685的問題
#8
資深會員
資深會員


查看用戶資訊
查表法是否放在中斷內----無差別 ,因為那是一種很快速的程式寫法,不過副程式的呼叫要小心 因為PIC只有8層推疊 所以如果超過 會死的很難看!

查表法是將PCL加上OFFSET 直接跳到返回參數所在的地方直接將參數放進 W 再跳回 所以不能用MOVWF 而要用 ADDWF

同樣道理 所以 ORG 不能放在 ADDWF PCL , F 的後面

INCF FXX 還有一個參數 ( F or W ) ( 將 FXX + 1 的值放回 FXX or W )你沒指定 它當然會給你警告 , 但其內定值 為,F 所以也不算錯的太離譜

PIC 的I/O 接腳有些有多種用途 所以如要將它當作普通I/O 來用, 則要將優先權較高的用法(如A/D)DISABLE 才能將其當作普通I/O 來用 , 這一點可參考 I/O 章節裏的小示範程式 及A/D 章節

你說 RB6 不能用 , 會不會是在胡說八道啊 , 因為這個只是普通I/O , 很單純的 跟本不會有那些問題存在 ...... 還是你忘記切回 BANK0 ?????

正如班主有言, 多看書有益無害.......

發表於: 2008/11/3 3:48
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: pic16F685的問題
#9
初級會員
初級會員


查看用戶資訊
感謝2位大大的回覆

RB6我是經實驗後確定不能用,至於切回BANK,我的程式經初始化完後就沒切BANK,所以應該不會RB7可以用,RB6不能用吧。

目前還沒試I/O的DISABLE,因為不知道組語的寫法,所以沒有注意,這點說聲抱歉~~~

等試過後小的會再回來回報結果。

發表於: 2008/11/3 14:50
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: pic16F685的問題
#10
初級會員
初級會員


查看用戶資訊
我有試過對ADC的暫存器做設置,在設完後有正常動作過,但不久就又出現無法讀取的問題。

我的設置為PORTA全拿來做輸入,PORTB和PORTC則為輸出
所以ADC功能disable,且全部設為數位輸出入腳。
banksel TRISA
movlw b'11111111'
movwf TRISA
movlw b'00000000'
movwf TRISB
movlw b'00000000'
movwf TRISC
banksel PORTA
movlw b'00000000'
movwf PORTB
movlw b'00000000'
movwf PORTC

; set ADC all disable
banksel ADCON0
clrf ADCON0
banksel ANSEL
clrf ANSEL
banksel ANSELH
clrf ANSELH

而判斷輸入的程式段為
bottom_state:
btfsc PORTA,1
goto bottom_exit
movlw 0x09
return
bottom_exit:
movlw 0x02

之後有把W的內容輸出給7段,照上面程式,如果PORTA的第1腳為0,則輸出2;如果為1的話輸出9。

從模擬的時候去看暫存器,都有符合我的設定,但不知道為什麼無法做In的判斷。

難道是我的設置有問題嗎?

發表於: 2008/11/4 19:03
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------