• 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
資深會員
資深會員


查看用戶資訊
老媽邊看連續劇邊燒飯, 每每看的入神, 忘了爐火....
結果是滿屋子煙, 警鈴響個不停...
所以笨鴨偶又派上用場啦 !!! haha.
學以致用, 正好練習寫查表的程式,,,,
於是呀 ! 用12F508 寫了個Timer的程式 ,
結果... 哈哈... 非常滿意... 自認如此.
還有呀 ? 鄰居, 王媽, 劉媽 陳媽,,, 看到笨鴨偶做的Timer都要一個 ;;;
哈.. 哈.. 又非常有成就感囉 !!! 來 給個抱抱囉 !!鼓勵一下子!
哦 ?? 王媽, 劉媽 陳媽, 妳們就免啦! 請妳們女兒代勞囉 ,哈 ,哈,
Timer的程式如下. 線路圖不知如何貼上, Sorry Lar !
SW 是用 4 Bit Binary Code Hexadecimal 16 Position SW.
所以 可以 設定16個不同位置時間
大家參考囉 ! 也希望多指正囉 ! 黑皮... 3Q Lor.

PIC12F508  PIR TIMMER
    
#include    <p12F508.inc>   ; processor specific variables
ConfigureControls the reset pincode protectoscillator selectionWDT.
    
__CONFIG _MCLRE_OFF _CP_OFF _WDT_OFF  &_IntRC_OSC
;-----[Defines Variable Assignments]--------------------------------------- 
    
cblock 0x08    GP0=SW,GP1=SW,GP2=SW,GP3=SW,GP4=O/and GP5LED.
    
count        counter for delay 500us.
    
count1        counter for delay 0.5s
    count2        
counter for delay 0.5s.
    
count3        counter for timmer.
    
count4        counter for timmer.
    
count5        counter for beeper .
    
count6        ; Switch table register.
    switch        ; Switch 
register.
    
endc
             
;****************  [Reset Vector] *******************************************
    
ORG     0x000        PIC goes here (Origin of codeafter reset.
    
movwf   OSCCAL        Load the oscillator calibration factor.
    
movlw   b'00000111'        wake on pion change,pull-ups resister,max pre-scaler
    OPTION                    
;    
    
movlw   b'00001111'        Set GP0,1,2,3,,, to an inputGPIO pins 4 and 5 to outputs.
    
TRIS    GPIO              Register 06h
    
goto    init     

init       
;****************** [Main routine] ****************************************
    
bcf    GPIO,4        Out 0
    call    dly_0.5        
;    
    
call    dly_0.5        ;
    
call    dly_0.5        ;    
    
call    dly_0.5        ;
    
call    dly_0.5        ;    
    
call    dly_0.5        Wait for 3 s.            
    
movf    GPIO,w        Read GPIO read setting sw.
    
iorlw    b'11110000'    Only low 4 bits.
    
movwf    switch,f        Result put into sw register.
    
clrf    count6        SW Table counter to 0.
start
    movf    count6
,w        Table search from first data.
    
call    sw_table        Check sw table and return with w.
    
xorwf    switch,w        Exclusive OR w with switch register.
    
btfsc    status,z        Check Z flag.
    goto     
hold        ; If equal then Z=1.
    incf    count6        
; iF not equal then z0.
    
goto    start        Check next data.
hold
    decf    count6        
;
    
movf    count6,w        Load current sw_table location into w.
    
call    dly_table        Find out the reference  from  delay table.
    
movwf    count3        Reference  for timmer.
    
beeper   ;********************************************************************
    
movlw    d'200'        ;
    
movf    count5        ;
beep_1
    bsf    GPIO
,4        ;
    
call     dly_500us        ;
    
bcf    GPIO,4        ;
    
call    dly_500us        ;
    
decfsz    count5,f        
    goto     
beep_1        ; (500us+500us)x200=0.2s
    call    dly_0.5s        
;
    
decfsc    count3,f        ;
    goto    
beeper        ;
    goto    
init        
dly_500us   ;******************* [Sub routine] **********************************
    
movlw    d'167'        ;
    
movwf    count        ;
keep    
    decfsz     count        
;
    goto    
keep        ;
    
retlw    0        ;
dly_0.5s
    movlw    d
'225'            
    
movwf    count1
loop
    movlw    d
'250'        ;
    
movwf    count2        ;
loop_1
    
goto    $+1        ;
    goto    $+
1        ;
    goto    $+
1        ;    
    
decfsz    count2,f        ;
    goto    
loop_1        ;
    
decfsz    count1,f        ;
    goto    
loop        ;
    
retlw    0

sw_table    
;******************************************************************
    
addwf    pcl,f
    retlw    
b'11111111'        F
    retlw    
b'11111110'        E
    retlw    
b'11111101'        D
    retlw    
b'11111100'        C
    retlw    
b'11111011'        B        
    retlw    
b'11111010'        A
    retlw    
b'11111001'        9
    retlw    
b'11111000'        8
    retlw    
b'11110111'        7
    retlw    
b'11110110'        6
    retlw    
b'11111001'        5
    retlw    
b'11111000'        4
    retlw    
b'11110110'        3
    retlw    
b'11110010'        2
    retlw    
b'11110001'        1
    retlw    
b'11110000'        0
table_1
    addwf    pcl
,f    
    retlw    d
'16'            60
    retlw    d
'15'            55
    retlw    d
'14'            50
    retlw    d
'13'            45
    retlw    d
'12'            40
    retlw    d
'11'            35
    retlw    d
'10'            30
    retlw    d
'9'            25
    retlw    d
'8'            20
    retlw    d
'7'            15
    retlw    d
'6'            10
    retlw    d
'5'            5
    retlw    d
'4'            4
    retlw    d
'3'            1
    retlw    d
'2'            1
    retlw    d
'1'            1 Mimutes.
    
end


發表於: 2006/6/10 0:36
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... ]

教育訓練中心

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