; パソコンセレクタ制御プログラム ; CPU = PIC16F84 ; CLOCK = 10MHz ; list p=16f84 include __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC ; ; タイマ初期値 ; tm1set equ 100 ; タイマ処理間隔 x100mS 100=10秒 tm2set equ 60 ; CRT自動電源OFF時間 xtm1set 60=10分 tm2set2 equ tm2set-4 ; CRT自動電源OFF予告ブザー時間 ; ; パラレルポート定義 ; comp1 equ 2 ; PORTA(i) comp1 power comp2 equ 3 ; PORTA(i) comp2 power psw equ 4 ; PORTA(i) push sw clock equ 0 ; PORTB(i) PS2 clock CRTpow equ 1 ; PORTB(o) CRT SELECT OUT CRTsel equ 2 ; PORTB(o) CRT POWER CONTLOR test1 equ 4 ; PORTB(o) TEST LED 1 test2 equ 5 ; PORTB(o) TEST LED 2 test3 equ 6 ; PORTB(o) TEST LED 3 & ブザー test4 equ 7 ; PORTB(o) TEST LED 4 ; ; 変数定義 ; org 0ch ; ; 汎用変数 tm1 res 1 ;0.1s タイマ tm2 res 1 ;10s タイマ wait_cn res 1 ;ウエイト用カウンタ1 wait_cn2 res 1 ;ウエイト用カウンタ2 ;============================================================================== ; ; プログラムスタート ; org 0 goto start ; ; 割り込み処理 ; org 4 clrf tm1 ;タイマ初期化 clrf tm2 bsf PORTB,CRTpow ;CRT POWER ON bsf PORTB,test4 ;LED 4 on bcf INTCON,INTF ;RB0/INT 初期化 retfie ;============================================================================== start ; ポート初期化 ; bsf STATUS, RP0 ; Bank 1 を選択する movlw b'11100' ;出力=RA0-1 入力=RA2-4 movwf TRISA movlw b'00000001' ;入力RB0/INT 出力=RB1-7 movwf TRISB bsf OPTION_REG,NOT_RBPU ;pull-up off bcf OPTION_REG,INTEDG ;エッジ割り込み 立ち下がり bcf STATUS, RP0 ; Bank 0 を選択する clrf PORTA movlw b'11110010' movwf PORTB ; all LED on + CRT POWER ON call wait_1s ;wait 1s x 3 = 3S call wait_1s call wait_1s movlw b'10000010' movwf PORTB ; LED 0-4 off + CRT POWER ON ; ; 割り込み初期化 ; call tmset ;タイマ初期化 bsf INTCON,INTE ;RB0/INT 有効 bcf INTCON,INTF ;RB0/INT 初期化 bsf INTCON,GIE ;割り込み 有効 ;-------------------------------------- ; ; 起動PC確認 ; main bcf PORTB,test1 ;LED 1 off bcf PORTB,test2 ;LED 2 off call wait_100ms ;100mS wait btfsc PORTA,comp1 ;PC1が先に起動 goto pc1on btfsc PORTA,comp2 ;PC2が先に起動 goto pc2on goto main ; ; CRT POWER OFF ; pwoff bcf PORTB,CRTpow ;CRT POWER OFF bcf PORTB,test4 ;LED 4 off goto main ; ; PC1 ON 状態 ; pc1on call wait_100ms ;100mS wait btfss PORTA,comp1 ;再確認 goto main bsf PORTB,CRTpow ;CRT POWER ON bsf PORTB,test1 ;LED 1 on bsf PORTB,test4 ;LED 4 on bcf PORTB,CRTsel ;CRT select LOW pc1loop btfsc PORTA,comp1 goto pc1next ;PC1=ON btfss PORTA,comp2 goto pwoff ;PC1=OFF PC2=OFF 起動PC確認へ移行 bcf PORTB,test1 ;LED 1 off goto pc2on ;PC1=OFF PC2=ON PC2 ON 状態へ移行 pc1next call wait_100ms ;100mS wait btfss PORTA,comp2 goto pc1loop ;PC1=ON PC1=OFF ; PC1=ON PC2=ON 相互切替有効 call chenge ;SW確認 btfsc STATUS,Z goto pc1loop ;SW OFF ; 強制切り替え bcf PORTB,test1 ;LED 1 off bsf PORTB,test2 ;LED 2 on bcf PORTB,CRTsel ;CRT select LOW swoff1 call chenge ;SW OFF 待ち btfss STATUS,Z goto swoff1 goto pc2on ; ; PC2 ON 状態 pc2on call wait_100ms ;100mS wait btfss PORTA,comp2 ;再確認 goto main bsf PORTB,CRTpow ;CRT POWER ON bsf PORTB,test2 ;LED 2 on bsf PORTB,test4 ;LED 4 on bsf PORTB,CRTsel ;CRT select HI pc2loop btfsc PORTA,comp2 goto pc2next ;PC2=ON btfss PORTA,comp1 goto pwoff ;PC1=OFF PC2=OFF 起動PC確認へ移行 bcf PORTB,test2 ;LED 2 off goto pc2on ;PC1=ON PC2=OFF PC1 ON 状態へ移行 pc2next call wait_100ms ;100mS wait btfss PORTA,comp1 goto pc2loop ;PC1=OFF PC2=ON ; PC1=ON PC2=ON 相互切替有効 call chenge ;SW確認 btfsc STATUS,Z goto pc2loop ;SW OFF ; 強制切り替え bsf PORTB,test1 ;LED 1 on bcf PORTB,test2 ;LED 2 off bsf PORTB,CRTsel ;CRT select HI swoff2 call chenge ;SW OFF 待ち btfss STATUS,Z goto swoff2 goto pc1on ; ; SW 入力確認 (ON:Z-FLAG=0 OFF:Z-FLAG=1) chenge btfsc PORTA,psw ;SW確認 goto chenge2 ;入力無し call wait_100ms ;100mS wait btfsc PORTA,psw ;SW再確認 goto chenge2 ;入力無し bcf STATUS,Z ;入力あり return chenge2 bsf STATUS,Z ;入力なし return ; ; パワーOFF タイマ初期化 ; tmset clrf tm1 ;タイマ初期化 clrf tm2 return ;-------------------------------------- ; ; 1秒ウエイト ; wait_1s movlw 250 movwf wait_cn call wait_ms movlw 250 movwf wait_cn call wait_ms movlw 250 movwf wait_cn call wait_ms movlw 250 movwf wait_cn call wait_ms return ; ; タイマ処理付き 100ms ウエイト ; wait_100ms btfsc PORTB,CRTpow ;電源OFFならタイマカウントしない goto tm1start clrf tm1 ;タイマ初期化 clrf tm2 goto wait100 ; ; タイマカウント処理 ; ;tm1処理 tm1start incf tm1 ;タイマカウント tm1++ movf tm1,W sublw tm1set ;if tm1 > tm1set 終了 btfss STATUS,Z goto wait100 clrf tm1 ;tm2処理 incf tm2 ;タイマカウント tm2++ movf tm2,W sublw tm2set2 ;if tm2 >= tm2set2 終了 btfsc STATUS,C goto wait100 ; call beep ;beep出力 movf tm2,W sublw tm2set ;if tm2 > tm2set 終了 btfss STATUS,Z return clrf tm2 ;timeup bcf PORTB,CRTpow ;CRT POWER OFF bcf PORTB,test4 ;LED 4 off return ; ; 100mS ウエイト ; wait100 movlw 100 movwf wait_cn call wait_ms return ; ; beep 出力 (100mS間出力) ; beep movlw 100 movwf wait_cn beep1 bsf PORTB,test3 call beep2 bcf PORTB,test3 call beep2 decf wait_cn btfss STATUS,Z goto beep1 return ; ; 0.5mS wait ; beep2 movlw 114 movwf wait_cn2 beep3 nop nop nop nop nop nop nop decf wait_cn2 btfss STATUS,Z goto beep3 return ; ; msオーダーのウェイト ; wait_ms movlw 227 movwf wait_cn2 wait_ms1 nop nop nop nop nop nop nop decf wait_cn2 btfss STATUS,Z goto wait_ms1 decf wait_cn btfss STATUS,Z goto wait_ms return end