老媽邊看連續劇邊燒飯, 每每看的入神, 忘了爐火....
結果是滿屋子煙, 警鈴響個不停...
所以笨鴨偶又派上用場啦 !!! 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
; Configure: Controls the reset pin, code protect, oscillator selection, WDT.
__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF &_IntRC_OSC
;-----[Defines & Variable Assignments]---------------------------------------
cblock 0x08 ; GP0=SW,GP1=SW,GP2=SW,GP3=SW,GP4=O/P and GP5= LED.
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 code) after 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 input, GPIO 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 z= 0.
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