• slider image 514
  • slider image 516
  • slider image 517
  • slider image 518
  • slider image 519
:::


Browsing this Thread:   2 Anonymous Users






哈.哈.笨鴨的程式可以工作啦!!
#1
資深會員
資深會員


查看用戶資訊
Dear All ...
第一次用有A/D 的12F510 練習寫程式...
居然可以工作啦!! 黑皮, 黑皮, 真是黑皮...
哈.哈...有成就感...來些抱抱(限女性),, 鼓勵一下囉.哈.哈...
當然啦 ! 程式有點笨笨,, 就像笨鴨一樣啦 ...hahaha.
給大家參考一下,,, 也歡迎來修正哦!!!!
嗯 ... 下個程式要練習寫" 查表程式 "...

;PIC12F510 12F510 ADC 05/23/2006
List p=12f510
#include <p12F510.inc> ; processor specific variables
; Configure: Controls the reset pin, code protect, oscillator selection, WDT.
__CONFIG _CP_OFF & _MCLRE_OFF & _IOSCFS_OFF & _WDT_OFF & _IntRC_OSC
;-----[Defines & Variable Assignments]---------------------------------------
cblock 0x0A ;
count ; count buffer
count1 ; count buffer
count2 ; count buffer
count3 ; For A/D RESULT.
endc
;-----[Reset Vector]---------------------------------------------------------
ORG 0x000 ; PIC goes here (Origin of code) after reset.
movwf OSCCAL ; Load the oscillator calibration factor.
movlw b'10001111' ; Disable wake on pin change, Enable pull-up.
OPTION
movlw b'00001100' ; Set GP2=AN2 ,, GP3 to an input GP0,GP1,GP4,GP5=O/P.
TRIS GPIO ; Register 06h
;-----[Main routine]------------------
init
bcf CM1CON0,3 ;Disable COMPARATOR Register bit3 C1ON to low.
bcf GPIO,0 ;
bcf GPIO,1 ;
bcf GPIO,4 ;
bcf GPIO,5 ;
call dly_1s ;
movlw b'01111001' ; GP2 to an A/D input , ADC ON
movwf ADCON0 ;
call dly_25us ; Wait for AN2 to set up .
bsf ADCON0,GO ; start A/D conversion for GP2/AN2.
call dly_25us ; Wait for coversion .
wait
btfsc ADCON0,GO ; Conversion complete yet? GO=0= Done.
goto wait ; No,
movf ADRES,W ; Read A/D result into W.
movwf count3 ; Save W into count3 register.
movlw b'11001100' ; 4V=204=11001100.
subwf count3,w ; RESULT - 4V.
btfsc STATUS,C ; If C=0 then RESULT< 4V
goto LED1 ; If C=1 then RESULT > 4V,.
movlw b'10011001' ; 3V=153=10011001.
subwf count3,w ; RESULT - 3V.
btfsc STATUS,C ; If C=0 then RESULT< 3V.
goto LED2 ; If C=1 then RESULT > 3V,
movlw b'01100110' ; 2V=102=01100110.
subwf count3,w ; RESULT -2V.
btfsc STATUS,C ; If C=0 then RESULT< 2V.
goto LED3 ; If C=1 then RESULT > 2V,
movlw b'00110011' ; 1V=51=00110011.
subwf count3,w ; RESULT - 1V.
btfsc STATUS,C ; If C=0 then RESULT< 1V.
goto LED4 ; If C=1 then RESULT > 1V,
goto LED5 ;
LED1
bsf GPIO,0 ; Turn LED on.
call dly_1s ;
call dly_1s ;
goto init ;
LED2
bsf GPIO,1 ; Turn LED on.
call dly_1s ;
call dly_1s ;
goto init ;
LED3
bsf GPIO,4 ; Turn LED on.
call dly_1s ;
call dly_1s ;
goto init ;
LED4
bsf GPIO,5 ; Turn LED on.
call dly_1s ;
call dly_1s ;
goto init ;
LED5
bsf GPIO,5 ; Turn LED on.
call dly_1s ;
bcf GPIO,5 ; Turn LED on.
call dly_1s ;
bsf GPIO,5 ; Turn LED on.
call dly_1s ;
goto init ;
; ---------------------------[Sub routine]-----------------------------------
dly_25us
movlw d'8' ;
movwf count ;
keep
decfsz count,f ;
goto keep ;
retlw 0 ;
dly_1s
movlw d'255' ;
movwf count1 ;
loop
movlw d'255' ;
movwf count2 ;
loop_1

goto $+1 ;
goto $+1 ;
goto $+1 ;
goto $+1 ;
goto $+1 ;
goto $+1 ;
decfsz count2,f ;
goto loop_1 ;
decfsz count1,f ;
goto loop ;
retlw 0
end


發表於: 2006/6/8 4:24
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... ]

教育訓練中心

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