• 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 3 (4) 5 »


Re: Regarding to Timer0
#12
資深會員
資深會員


查看用戶資訊
說到打字數 .. 哎... 累耶.... 還是電話方便 ..哈.. 哈 .
繼續分析程式, 應該是懂啦 !! Happy...

一開始就Call timer , 此時tmr0 應該是 '00000000'.
所以會跳到 _T64us_0 去空轉 , 等第一個bit 變'1'時
把T64us加一, 回來;
此時T64us 第一個bit, 應該是出現 '1' ;所以會把 LED1 ON,
此時T64us 第二個bit 應該是 '0' ,所以會跳到 main...
此時tmr0 應該是 '00000001'.所以會跳到 _T64us_1 ..
等64us到, 再把T64us加一, 回來 ;

此時T64us 第一個bit應該是 '0' ,
此時T64us 第二個bit 應該是 '1' ,
所以會把 LED1- OFF , 把 LED2 - ON ; Right ???

所以.. 主程式長度 ,不可以 超過 64us,,,, 對不對呀 ???

還有呀 ? 前面的程式 有用到 movlw .10*4 指令 ,
是不是... 10 X 4 =40 ... 那為何不直接寫 movlw .40 呢?

3Q lor !!!

發表於: 2007/8/28 0:07
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Regarding to Timer0
#11
資深會員
資深會員


查看用戶資訊
說到升等,就讓我想起那時玩線上遊戲的日子...每天練功升等,練到走火入魔,六親不認....

嗯,你的打字數和程式差不多長...相信你看明白了,等你發表新程式了...^^~

發表於: 2007/8/27 10:06
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Regarding to Timer0
#10
資深會員
資深會員


查看用戶資訊
Good Morning Guys ;

哈里路亞.. 善哉.. 善哉.. 恭喜yiming大鍋您生等啦!!haha..

這麼個程式笨鴨終於看懂90%啦!!!
嗯... T64us 是 define出的一個 Register ,
timer0 prescaler rate 1:64, so...tmr0 每 64us 進位,
btfsc tmr0,0 測試tmr0 的第1個Bit, 1=64us;
btfsc T64us,0 測試T64us 的第1個Bit, 1=64us;
btfsc T64us,1 測試T64us 的第2個Bit, 1=128us;
對不對呀? 其他的我再想一下啦!
已經兩通 ...快三通啦 !!! 哈..哈....
待笨鴨用12F508 組合一個完整程式再post上來囉...
3Q lar , yiming ...



發表於: 2007/8/27 9:18
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Regarding to Timer0
#9
資深會員
資深會員


查看用戶資訊
隨手寫寫,64us的timer
真是不好意思,和你們聊天聊到變成救世主了...^^"

timer0 prescaler rate 1:64
#define LED1    PORTB,0
#define LED2    PORTB,1  

main:
    
call    timer
;LED1 64us on/64us off
    btfsc    T64us
,0
    bsf    LED1
    btfsc    T64us
,0
    bcf    LED1

;LED2 128us on/128us off
    btfsc    T64us
,1
    bsf    LED2
    btfsc    T64us
,1
    bcf    LED2

    
goto    main


;-----------------------------------------
timer:
    
btfsc    tmr0,0
    
goto    _T64us_1

_T64us_0
:
    
btfss    tmr0,0
    
goto    _T64us_0
    
goto    _T64us

_T64us_1
:
    
btfsc    tmr0,0
    
goto    _t64us_1

_T64us
:
    
clrfwdt
    incf    T64us
,f
    retlw    .0
;-----------------------------------------
    
end

發表於: 2007/8/25 12:48
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Regarding to Timer0
#8
資深會員
資深會員


查看用戶資訊
3Q lar ...yiming & Beee
Key in 那麼多字, 辛苦啦! 休息一下, 喝杯飲料, 上網看看漂漂咩咩囉! .. 哈..哈...
有時笨鴨很氣自己, 為什麼生的如此笨. (看來基因不好..哈..哈... )
一點小程式就腦筋打結, 想不出所以然來, 好氣呦!!

yiming大鍋的詳解 ,可以讓笨鴨忙整個週末囉!! 謝謝啦!!

關於FSR.....暫時別提啦 ...好像滿頭痛的.....

那本書嘛? Timer0, 也只提供一點點資料而已;
一個 64ms delay程式, so, so, 幫助不多...
我想是給天才看的, 可以舉一反十的Geek看的書囉. 哈..哈...

笨鴨的假一轉眼就過去啦 !老婆週六回來, 週一就開課了..
又有的忙啦 !!!!
Have a nice weekend and take care lor !

發表於: 2007/8/25 0:50
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Regarding to Timer0
#7
資深會員
資深會員


查看用戶資訊
PIC16F505
執行一個指令的時間,T=4*(1/Fosc)
當使用內部振盪4Mhz時,T=1uS
查16F505 P31 圖5-2

timer0,當使用內部振盪4Mhz時CLK=Fosc/4
如果prescaler rate 1:1,則T=1uS,timer0+1
如果prescaler rate 1:4,則T=4uS,timer0+1
也就是說,prescaler rate的設定可以增加timer0可計數的時間.
查16F505 P33 圖6-1

查16F505 P36 6.2
When assigned to the Timer0 module, all instructions
writing to the TMR0 register (e.g., CLRF 1, MOVWF 1,
BSF 1, x, etc.) will clear the prescaler. When assigned
to WDT, a CLRWDT instruction will clear the prescaler
along with the WDT. The prescaler is neither readable
nor writable. On a Reset, the prescaler contains all ‘0’s.

有任何修改timer0的指令,則clear prescaler.
但我們所設是的是prescaler rate 1:4,不會被改變.
prescaler 不等於 prescaler rate,
prescaler rate 是我們設定的.ex:1:4
prescaler是一個硬體的計數器.

prescaler rate 1:4
他的意思是每1uS prescaler+1,當prescaler=4時,timer0+1.
也就是說我們在clrf timer0時,並不知道prescaler=?,會造成時間有誤差,所以每當我們修改timer0時,prescaler=0,才不會產生誤差.

感謝Beee提出這個問題,我以前發現這個問題了,看data sheet也不小心看到這一段,但是程式上卻一直沒問題,根本不需要重新設定prescaler rate,經你一提起,我再回去仔細的看一下data sheet才發現是我之前誤解了,我特地把它寫出來,希望大家別在誤解data sheet,它是無辜的......^^~

另外,甲鳥
23*4=92us...再加上
btfsc status,c...2uS
clrf fsr...1uS
clrf tmr0..1uS
....差不多就100us了吧
你可以弄一output來看看是不是100US呀...
至於fsr...你目前還沒用到,16F505 data sheet就有了去翻一翻~
再不行,下次再問,再弄個討論專門說明fsr









發表於: 2007/8/23 10:36
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Regarding to Timer0
#6
資深會員
資深會員


查看用戶資訊
基本上 TIMER0 是執行一個指令 就 + 1 , 但如設定 Prescaler ,則會經過 ( Prescaler 個指令 ) 才會+ 1 ; 如 OVER FLOW ( 既 + 1 後 超過 0XFF ) , 會自動變為 0

如要測試有無 OVER FLOW , Prescaler 一定設為 4 以上 才不會 MISS 掉
如用Y大所示 用 SUBWF TMR0 的方式, 比較可以靈活運用 ,Prescaler 也可設為 1
但如動到TMR0 的值( EXP : CLRF TMR0 : INCF TMR0 , F : MOVWF TMR0 ) , Prescaler 的值會被清除掉 , 所以要每次都重設 Prescaler ( DATA SHEET 說的 , 我沒試過 )

發表於: 2007/8/23 4:40
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Regarding to Timer0
#5
資深會員
資深會員


查看用戶資訊
笨鴨有時會用到16F505, 腳比較多嘛...
程式嘛? 笨鴨寫的程式都只有100-200行,(甚至更少)就玩完了..
那1-2K ROM 空間 ,閒在那 ...還真是可惜...haha.
其實有中斷的PIC, 偶有在看;
目前是想好好了解tmr0可以做些啥事而已囉.
笨鴨不是從事此行, 所以慢慢來不急 ;
不趕進度, 沒壓力, 澈底了解比較重要 lor!

Well ...
yiming 的tmr0 程式
prescale set to 1:4 . 了解.
But... tmr0 - 23 for what reason ?
If tmr0 > 23 then C=1 . So ,goto timer again...
但是 goto timer 其間沒有做任何事, 那tmr0 是否會自己減少呢?
再來 if tmr0 < 23, 則 clrf tmr0 ,了解.
But clrf fsr ....就不了 ????
fsr = 0 以後 pic 會做些啥事呢 ? 頭痛啦!!! hahaha...
3Q lor !!!
By the way ,偶會再去翻翻那本PIC單晶片學習秘笈囉!

發表於: 2007/8/22 0:13
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Regarding to Timer0
#4
資深會員
資深會員


查看用戶資訊
時差15個小時哦,那就是說我上班你就要下班了哦~2班制哦~
tmr0的用法和一般的RAM都一樣.
clrf tmr0 ;tmr0=0
movlw .200
movwf tmr0 ;tmr0=200

10F200,16F508/509,其實我都不建議你使用,因為這些是特殊的PIC功能太陽春了,是為了特殊用途的PIC,加上程式空間太小了沒什麼發揮的空間,能做單一功能算是不錯了.
建議使用16F505,16F57,16F630/16F676
16F505 ROM(1024),RAM(72),I/O(11),tmr0...用這個做標準
16F57 ROM(2048),RAM(72),I/O(20),tmr0...多一些ROM,I/O
16F630 ROM(1024),RAM(64),I/O(12),tmr0/tmr1,eeprom(128)...多了tmr1,eeprom,及中斷功能
16F676 ROM(1024),RAM(64),I/O(12),tmr0/tmr1,eeprom(128)...只比630多了一組AD

基本上505/630/676的腳位完全相同,57則是多了些ROM,I/O所以腳位不同了,但功能和505完全一樣,我都是用57來模擬505的.

為什麼建議你用這組PIC來學呢??
1.因為我覺得ROM至少要有1~4K才能稍微玩出一些像樣的東西出來.
2.I/O至少要有10隻,不然要怎麼玩??
3.這些PIC蠻多人用的,價格上不會太貴.
4.505/630/676...腳位完全一樣,功能慢慢增加,進階學習很合適,看資料時只要看新增的部分就OK.

這些都學會了,16FX就只剩下PWM和一些內建的通訊功能(SPI,I2C,UART,PSP)沒用過而已




發表於: 2007/8/21 8:55
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: Regarding to Timer0
#3
資深會員
資深會員


查看用戶資訊
先從Beee 大鍋的Timer0問起(比較簡單嘛)!

Set Prescaler ,是設定 PS0,PS1,PS2...了解
但是何處去 Set tmr0 =0 呢 ????
素不素 CLRF TMR0 指令即可?

do something...... 應該是指主程式吧 !
在這兒主程式有多少時間可用呢?

其他是讀tmr0值 , 測試C_Flag ...
如果overflow, 表示 tmr0 已經 time out;回到主程式..

所以 do something 的時間要越接近tmr0 設定時間越好 Right?
這樣才不用等tmr0 而空轉, Right?


發表於: 2007/8/21 3:38
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... ]

教育訓練中心

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