• slider image 442
  • slider image 497
  • slider image 498
  • slider image 499
  • slider image 500
  • slider image 502
:::


Browsing this Thread:   1 Anonymous Users






Re: 請教Datasheet - DS33014J上的範例,請問有無高人能說清楚、講明白
#2
版主
版主


查看用戶資訊
不知道你是哪裡看不懂? 這只是ㄧ個延遲程式使用MARCO的方式將延遲的時間載入各個佔存器裏。

發表於: 2006/11/2 11:53
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


請教Datasheet - DS33014J上的範例,請問有無高人能說清楚、講明白
#1
新會員
新會員


查看用戶資訊
這是在Datasheet中看到的範例,看了很久,不知為什麼用這種架構寫,不是不懂如何寫程式,而是不知道為何這麼寫和每個動作的實際作為,有高人能以加以解釋一下嗎,感恩啊。

#include p16F877A.inc

udata 0x20
Dly0 res 1 ;Stores 4 bytes of data for the delay count
Dly1 res 1 ;Dly0 is the least significant byte
Dly2 res 1 ;while Dly3 is the most significant byte
Dly3 res 1

Dly32 MACRO DLY
goto $+1 ;delay 2 cycles
goto $+1 ;delay total of 4 cycles

;Take the delay value argument from the macro, precalculate
;the required 4 RAM values and load the The RAM values Dly3
;though Dly0.

BANKSEL Dly3
movlw (DLY-1) & H'FF'
movwf Dly0
movlw (DLY-1) >>D'08' & H'FF'
movwf Dly1
movlw (DLY-1) >>D'16' & H'FF'

;Bytes are shifted and anded by the assembler to make user
;calculations easier.

movwf Dly2
movlw (DLY-1) >>D'24' & H'FF'
;Call DoDly32 to run the delay loop.
movwf Dly3
call DoDly32
ENDM ;End of Macro definition

RST CODE 0x00 ;Reset Vector
pagesel TestCode
goto TestCode

CODE ;Code starts here
TestCode
Dly32 D'50000' ;Max 4 billion+ (runs Dly32 Macro,
;1 sec in this case).
nop ;ZERO STOPWATCH, put breakpoint here

goto TestCode ;Go back to top of program and
;run the delay again.
;Subroutine, called by the Macro Dly32 (20 Tcy per loop)

DoDly32
movlw H'FF' ;Start with -1 in W
addwf Dly0,F ;LSB decrement
btfsc STATUS,C ;was the carry flag set?
clrw ;If so, 0 is put in W
addwf Dly1,F ;Else, we continue.
btfsc STATUS,C
clrw ;0 in W
addwf Dly2,F
btfsc STATUS,C
clrw ;0 in W
addwf Dly3,F
btfsc STATUS,C
clrw ;0 in W
iorwf Dly0,W ;Inclusive-OR all variables
iorwf Dly1,W ;together to see if we have reached
iorwf Dly2,W ;0 on all of them.
iorwf Dly3,W
btfss STATUS,Z ;Test if result of Inclusive-OR's is 0
goto DoDly32 ;It was NOT zero, so continue counting
retlw 0 ;It WAS zero, so exit this subroutine.

END

發表於: 2006/10/31 22:45
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... ]

教育訓練中心

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