sentakuitaの日記: てゆーか二元時計?!(19)
日記 by
sentakuita
;========
;
; LED Binary Clock ver1.1
;
;========
;
; . * .
; .* .. .*
; .* *. ..
; *. ** .*
; --------
; 16:39:05
;
; こんな感じで。
;
; ---/---/---/RA4/RA3/RA2/RA1/RA0
; ---/---/---/sw1/sec/min/sw2/hr
;
; RB7/RB6/RB5/RB4/RB3/RB2/RB1/RB0
; 40/ 20/ 10/ 08/ 04/ 02/ 01/---
;
; 4.19MHz 水晶駆動しましょ。
list p=16f84a
#include p16f84a.inc
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC
RADIX HEX
sw1 equ 1
sw2 equ 4
tmp1 equ 0x0c ;temporary
tmp2 equ 0x0d ;temporary
mode equ 0x10 ;mode
hr equ 0x11 ;hour(.00-.23)
min equ 0x12 ;minute(.00-.59)
sec equ 0x13 ;second(.00-.59)
sec_256 equ 0x14 ;1/256sec(0x00-0xff)
adj equ 0x15 ;OSC adjust
w_temp equ 0x18
s_temp equ 0x19
MSD equ 0x0c ; 10位
LSD equ 0x0d ; 01位
tcnt equ 0x0c
waitms equ 0x0d
;
;
;
org 0x000
goto start
;
; interrupt
;
org 0x004
intr movwf w_temp
swapf STATUS,W
movwf s_temp ;W,STATUSの退避
;
; 割り込みタイマの微調整
; 150sec毎に1/256sec遅れさせる。
;
oscadj movf sec_256,W
iorwf adj,W
btfss STATUS,Z ;adjカウントが0では無いときcountへ
goto count ;
movlw .106 ;.256-.150
movwf adj ;adjカウントが0のとき
goto intr2 ;adjリセットしてcount呼ばずに抜ける
;
; 秒刻みカウンタage
;
count incfsz sec_256,F ;sec_256++
goto intr2
incf adj,F ;adj++
incf sec,F ;sec++
movlw .60
subwf sec,W ;secから.60を引く
btfss STATUS,C
goto intr2
clrf sec ;秒を0に
incf min,F ;min++
movlw .60
subwf min,W
btfss STATUS,C
goto intr2
clrf min
incf hr,F ;hr++
movlw .24
subwf hr,W
btfss STATUS,C
goto intr2
clrf hr
intr2
swapf s_temp,W
movwf STATUS
swapf w_temp,F
swapf w_temp,W
bcf INTCON,T0IF
retfie
;
;
;
start bsf STATUS,RP0
movlw 0x12
movwf TRISA ;RA0,2,3を出力、RA1,4を入力
movlw 0x00
movwf TRISB ;RB0-RB7を出力に
movlw 0xc3
movwf OPTION_REG ;TMR0=1/16
bcf STATUS,RP0
movlw 0xff
movwf PORTB
clrf PORTA ;PORTA,PORTBの初期化
;
; 時刻設定
;
movlw .56
movwf sec
movlw .34
movwf min
movlw .12
movwf hr
;
clrf adj
;
bsf INTCON,GIE ;TMR0割り込み開始
goto adjtime
;
;
mainloop
call clrled
call putsec
call wait
call clrled
call putmin
call wait
call clrled
call puthr
call wait
goto chkbtn
clrled movlw 0x00
movwf PORTA
movlw 0xff
movwf PORTB
return
putsec bsf PORTA,3 ;秒だけをHに
movf sec,W
call getled ;LED点灯パタンを得る
movwf PORTB ;PORTBに出力
return
putmin bsf PORTA,2
movf min,W
call getled
movwf PORTB
return
puthr bsf PORTA,0
movf hr,W
call getled
movwf PORTB
return
;
chkbtn btfss PORTA,sw1
goto adjtime
goto mainloop
;
adjtime bcf INTCON,T0IE
movlw .255
movwf waitms
call waitx
adjsec clrf sec_256
clrf sec
adjmin call wait
call clrled
call putmin
btfss PORTA,sw2
goto agemin
btfss PORTA,sw1
goto adjhr
goto adjmin
agemin movlw .255
movwf waitms
call waitx
incf min,F ;min++
movlw .60
subwf min,W
btfsc STATUS,C
clrf min
goto adjmin
adjhr call wait
call clrled
call puthr
btfss PORTA,sw2
goto agehr
btfsc PORTA,sw1
goto adjtime2
goto adjhr
agehr movlw .255
movwf waitms
call waitx
incf hr,F
movlw .24
subwf hr,W
btfsc STATUS,C
clrf hr
goto adjhr
adjtime2 bsf INTCON,T0IE
movlw .255
movwf waitms
call waitx
goto mainloop
getled clrf MSD
movwf LSD
bb10th movlw .10
subwf LSD,W
btfss STATUS,C
goto bbover
movwf LSD
incf MSD,F
goto bb10th
bbover swapf MSD,W
iorwf LSD,F
;
comf LSD,F ; bit反転
rlf LSD,W ; bitシフト
return
; ----
; wait
; ----
; 1024サイクルなwait
wait movlw .204 ;1
movwf tcnt ;1
goto $+1 ;2
nop ;1
tloop decfsz tcnt,F ;1x203+2
goto twait ;2x203
return ;2
twait goto tloop ;2x203
waitx call wait
decfsz waitms,F
goto waitx
return
;
;
;
END
;
; 修正BSDLisenceでよろしく
;
; LED Binary Clock ver1.1
;
;========
;
; . * .
; .* .. .*
; .* *. ..
; *. ** .*
; --------
; 16:39:05
;
; こんな感じで。
;
; ---/---/---/RA4/RA3/RA2/RA1/RA0
; ---/---/---/sw1/sec/min/sw2/hr
;
; RB7/RB6/RB5/RB4/RB3/RB2/RB1/RB0
; 40/ 20/ 10/ 08/ 04/ 02/ 01/---
;
; 4.19MHz 水晶駆動しましょ。
list p=16f84a
#include p16f84a.inc
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC
RADIX HEX
sw1 equ 1
sw2 equ 4
tmp1 equ 0x0c ;temporary
tmp2 equ 0x0d ;temporary
mode equ 0x10 ;mode
hr equ 0x11 ;hour(.00-.23)
min equ 0x12 ;minute(.00-.59)
sec equ 0x13 ;second(.00-.59)
sec_256 equ 0x14 ;1/256sec(0x00-0xff)
adj equ 0x15 ;OSC adjust
w_temp equ 0x18
s_temp equ 0x19
MSD equ 0x0c ; 10位
LSD equ 0x0d ; 01位
tcnt equ 0x0c
waitms equ 0x0d
;
;
;
org 0x000
goto start
;
; interrupt
;
org 0x004
intr movwf w_temp
swapf STATUS,W
movwf s_temp ;W,STATUSの退避
;
; 割り込みタイマの微調整
; 150sec毎に1/256sec遅れさせる。
;
oscadj movf sec_256,W
iorwf adj,W
btfss STATUS,Z ;adjカウントが0では無いときcountへ
goto count ;
movlw .106 ;.256-.150
movwf adj ;adjカウントが0のとき
goto intr2 ;adjリセットしてcount呼ばずに抜ける
;
; 秒刻みカウンタage
;
count incfsz sec_256,F ;sec_256++
goto intr2
incf adj,F ;adj++
incf sec,F ;sec++
movlw .60
subwf sec,W ;secから.60を引く
btfss STATUS,C
goto intr2
clrf sec ;秒を0に
incf min,F ;min++
movlw .60
subwf min,W
btfss STATUS,C
goto intr2
clrf min
incf hr,F ;hr++
movlw .24
subwf hr,W
btfss STATUS,C
goto intr2
clrf hr
intr2
swapf s_temp,W
movwf STATUS
swapf w_temp,F
swapf w_temp,W
bcf INTCON,T0IF
retfie
;
;
;
start bsf STATUS,RP0
movlw 0x12
movwf TRISA ;RA0,2,3を出力、RA1,4を入力
movlw 0x00
movwf TRISB ;RB0-RB7を出力に
movlw 0xc3
movwf OPTION_REG ;TMR0=1/16
bcf STATUS,RP0
movlw 0xff
movwf PORTB
clrf PORTA ;PORTA,PORTBの初期化
;
; 時刻設定
;
movlw .56
movwf sec
movlw .34
movwf min
movlw .12
movwf hr
;
clrf adj
;
bsf INTCON,GIE ;TMR0割り込み開始
goto adjtime
;
;
mainloop
call clrled
call putsec
call wait
call clrled
call putmin
call wait
call clrled
call puthr
call wait
goto chkbtn
clrled movlw 0x00
movwf PORTA
movlw 0xff
movwf PORTB
return
putsec bsf PORTA,3 ;秒だけをHに
movf sec,W
call getled ;LED点灯パタンを得る
movwf PORTB ;PORTBに出力
return
putmin bsf PORTA,2
movf min,W
call getled
movwf PORTB
return
puthr bsf PORTA,0
movf hr,W
call getled
movwf PORTB
return
;
chkbtn btfss PORTA,sw1
goto adjtime
goto mainloop
;
adjtime bcf INTCON,T0IE
movlw .255
movwf waitms
call waitx
adjsec clrf sec_256
clrf sec
adjmin call wait
call clrled
call putmin
btfss PORTA,sw2
goto agemin
btfss PORTA,sw1
goto adjhr
goto adjmin
agemin movlw .255
movwf waitms
call waitx
incf min,F ;min++
movlw .60
subwf min,W
btfsc STATUS,C
clrf min
goto adjmin
adjhr call wait
call clrled
call puthr
btfss PORTA,sw2
goto agehr
btfsc PORTA,sw1
goto adjtime2
goto adjhr
agehr movlw .255
movwf waitms
call waitx
incf hr,F
movlw .24
subwf hr,W
btfsc STATUS,C
clrf hr
goto adjhr
adjtime2 bsf INTCON,T0IE
movlw .255
movwf waitms
call waitx
goto mainloop
getled clrf MSD
movwf LSD
bb10th movlw .10
subwf LSD,W
btfss STATUS,C
goto bbover
movwf LSD
incf MSD,F
goto bb10th
bbover swapf MSD,W
iorwf LSD,F
;
comf LSD,F ; bit反転
rlf LSD,W ; bitシフト
return
; ----
; wait
; ----
; 1024サイクルなwait
wait movlw .204 ;1
movwf tcnt ;1
goto $+1 ;2
nop ;1
tloop decfsz tcnt,F ;1x203+2
goto twait ;2x203
return ;2
twait goto tloop ;2x203
waitx call wait
decfsz waitms,F
goto waitx
return
;
;
;
END
;
; 修正BSDLisenceでよろしく
てゆーか二元時計?!(19) More ログイン