sentakuitaの日記: てゆーか二元時計?!(11)
日記 by
sentakuita
; 動作確認用に書いた bottum.asm
; 写真撮影時に12時34分56秒となっているのはこれ
;
; 時を刻むことも無いが、SW1を押すと猛烈な勢いでsec++
; ま、動作確認ということで。
;
; ==========
;
; ---/---/---/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 4
sw2 equ 1
tmp1 equ 0x0c ;temporary
tmp2 equ 0x0d ;temporary
mode equ 0x10 ;mode
;b01 -- sec
;b10 -- min
;b11 -- hr
;b00 -- none
hr equ 0x11 ;hour(.00-.23)
min equ 0x12 ;minute(.00-.59)
sec equ 0x13 ;second(.00-.59)
;
;
;
org 0x000
goto init
;
;
;
init
;
bsf STATUS,RP0
movlw 0x12
movwf TRISA ;RA1,4を入力、RA0,2,3を出力
movlw 0x00
movwf TRISB ;RB0-RB7を出力に
bcf STATUS,RP0
movlw 0xff
movwf PORTB
clrf PORTA ;PORTA,PORTBの初期化
;
; 時刻設定
;
movlw .56
movwf sec
movlw .34
movwf min
movlw .12
movwf hr
;
clrf mode
;
;
main_loop
;
putled
btfsc mode,0 ;
goto putled2 ;
btfsc mode,1 ;
goto put_min ;mode 10
goto put_hr ;mode 11
putled2 btfsc mode,1
goto chk_btm ;mode 00
;mode 01
;
put_sec
bcf PORTA,2
bcf PORTA,0
bsf PORTA,3 ;秒だけをHに
movf sec,W
call getled ;LED点灯パタンを得る
movwf PORTB ;PORTBに出力
goto chk_btm
put_min
bcf PORTA,0
bcf PORTA,3
bsf PORTA,2
movf min,W
call getled
movwf PORTB
goto chk_btm
put_hr
bcf PORTA,3
bcf PORTA,2
bsf PORTA,0
movf hr,W
call getled
movwf PORTB
;
chk_btm
call wait
incf mode,F
btfss PORTA,sw1
goto sec_up
btfss PORTA,sw2
goto min_up
goto main_loop
;
sec_up
incf sec,F ;sec++
movlw .60
subwf sec,W ;secから.60を引く
btfss STATUS,C
goto int_end ;桁下がりした(C=0)ら抜ける
clrf sec ;秒を0に
min_up
incf min,F ;min++
movlw .60
subwf min,W
btfss STATUS,C
goto int_end
clrf min
incf hr,F ;hr++
movlw .24
subwf hr,W
btfss STATUS,C
goto int_end
clrf hr
int_end
goto main_loop
;
; ----
; getled
; ----
; WにあるバイナリをBCD変換してWに出力。
; 上位4bitに10位、下位4ビットに01位を出力。
; 入力は0x8f(.159)以下にすること。
;
; PORTB出力の為、最後に
; ビット反転とビットシフトなおまけ付。
;
getled
MSD equ tmp1 ; 10位
LSD equ tmp2 ; 01位
;
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
rlf LSD,W
return
; ----
; wait
; ----
; 1024サイクルなwait
wait
tcnt equ tmp1
;
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
;
;
;
END
; 写真撮影時に12時34分56秒となっているのはこれ
;
; 時を刻むことも無いが、SW1を押すと猛烈な勢いでsec++
; ま、動作確認ということで。
;
; ==========
;
; ---/---/---/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 4
sw2 equ 1
tmp1 equ 0x0c ;temporary
tmp2 equ 0x0d ;temporary
mode equ 0x10 ;mode
;b01 -- sec
;b10 -- min
;b11 -- hr
;b00 -- none
hr equ 0x11 ;hour(.00-.23)
min equ 0x12 ;minute(.00-.59)
sec equ 0x13 ;second(.00-.59)
;
;
;
org 0x000
goto init
;
;
;
init
;
bsf STATUS,RP0
movlw 0x12
movwf TRISA ;RA1,4を入力、RA0,2,3を出力
movlw 0x00
movwf TRISB ;RB0-RB7を出力に
bcf STATUS,RP0
movlw 0xff
movwf PORTB
clrf PORTA ;PORTA,PORTBの初期化
;
; 時刻設定
;
movlw .56
movwf sec
movlw .34
movwf min
movlw .12
movwf hr
;
clrf mode
;
;
main_loop
;
putled
btfsc mode,0 ;
goto putled2 ;
btfsc mode,1 ;
goto put_min ;mode 10
goto put_hr ;mode 11
putled2 btfsc mode,1
goto chk_btm ;mode 00
;mode 01
;
put_sec
bcf PORTA,2
bcf PORTA,0
bsf PORTA,3 ;秒だけをHに
movf sec,W
call getled ;LED点灯パタンを得る
movwf PORTB ;PORTBに出力
goto chk_btm
put_min
bcf PORTA,0
bcf PORTA,3
bsf PORTA,2
movf min,W
call getled
movwf PORTB
goto chk_btm
put_hr
bcf PORTA,3
bcf PORTA,2
bsf PORTA,0
movf hr,W
call getled
movwf PORTB
;
chk_btm
call wait
incf mode,F
btfss PORTA,sw1
goto sec_up
btfss PORTA,sw2
goto min_up
goto main_loop
;
sec_up
incf sec,F ;sec++
movlw .60
subwf sec,W ;secから.60を引く
btfss STATUS,C
goto int_end ;桁下がりした(C=0)ら抜ける
clrf sec ;秒を0に
min_up
incf min,F ;min++
movlw .60
subwf min,W
btfss STATUS,C
goto int_end
clrf min
incf hr,F ;hr++
movlw .24
subwf hr,W
btfss STATUS,C
goto int_end
clrf hr
int_end
goto main_loop
;
; ----
; getled
; ----
; WにあるバイナリをBCD変換してWに出力。
; 上位4bitに10位、下位4ビットに01位を出力。
; 入力は0x8f(.159)以下にすること。
;
; PORTB出力の為、最後に
; ビット反転とビットシフトなおまけ付。
;
getled
MSD equ tmp1 ; 10位
LSD equ tmp2 ; 01位
;
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
rlf LSD,W
return
; ----
; wait
; ----
; 1024サイクルなwait
wait
tcnt equ tmp1
;
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
;
;
;
END
てゆーか二元時計?!(11) More ログイン