; ################################################################################ ; # ; # SVX IR KEY (GPLなのである) ; # ; # Assemble by pa-3.0.5s ; # ; ; ################################################################################ ; # ; # ヘッダ ; # include my16f648.h ; include my16f648.h ; .16f84 ; .16f84 ; PIC16F84(仮)に設定 ; GPIO equ 05h ; GPIO equ 05h TRISIO equ 85h ; TRISIO equ 85h EEDATA equ 9ah ; EEDATA equ 9ah EEADR equ 9bh ; EEADR equ 9bh EECON1 equ 9ch ; EECON1 equ 9ch RD equ 0 ; RD equ 0 ANSEL equ 9fh ; ANSEL equ 9fh ; ; ################################################################################ ; # ; # メモリセグメント ; # org 20h ; org 20h ; メモリマップ(16F84:0ch〜, 12F6xx/16F648A:20h〜) signalCnt ds 1 ; signalCnt ds 1 ; 信号持続カウンタ waitCntS ds 1 ; waitCntS ds 1 ; 時間待ち用カウンタ waitCntM ds 1 ; waitCntM ds 1 waitCntL ds 1 ; waitCntL ds 1 ; eeorg 0 ; eeorg 0 ; EEPROM eedata 170, 10 ; eedata 170, 10 ; Svx IR Key Data eedata 10, 30 ; eedata 10, 30 eedata 10, 30 ; eedata 10, 30 eedata 10, 30 ; eedata 10, 30 eedata 10, 30 ; eedata 10, 30 eedata 10, 30 ; eedata 10, 30 eedata 10, 30 ; eedata 10, 30 eedata 10, 30 ; eedata 10, 30 eedata 10, 30 ; eedata 10, 30 eedata 10, 30 ; eedata 10, 30 eedata 10, 30 ; eedata 10, 30 eedata 10, 30 ; eedata 10, 30 eedata 10, 255 ; eedata 10, 255 ; ; ################################################################################ ; # ; # プログラムセグメント ; # org 00h ; org 00h ; リセットベクタ goto START ; JP START ; ; ################################################################################ ; # ; # 割り込み処理 ; # org 04h ; org 04h ; 割り込みベクタ goto START ; JP START ; ; ################################################################################ ; # ; # チップ初期化処理 ; # START ; START bcf STATUS, RP0 ; RES RP0, (STATUS) ; バンク0へ clrf GPIO ; CLR (GPIO) ; ポートを初期化 movlw 07h ; LD A, 07h ; コンパレータOFF movwf CMCON ; LD (CMCON), A PORTSET ; PORTSET bsf STATUS, RP0 ; SET RP0, (STATUS) ; バンク1へ clrf ANSEL ; CLR (ANSEL) ; デジタルI/O movlw 00001000b ; LD A, 00001000b ; ポートの入出力設定(0:出力, 1:入力(初期)) movwf TRISIO ; LD (TRISIO), A bcf STATUS, RP0 ; RES RP0, (STATUS) ; バンク0へ戻す ; ; ;------------------------------------------------------------------------------- ; ; ; ; 赤外線波形を送信 ; ; PLAYBACK ; PLAYBACK bsf STATUS, RP0 ; SET RP0, (STATUS) ; バンク1へ movlw 0 ; LD A, 0 ; 赤外線信号記憶エリアの先頭アドレス movwf EEADR ; LD (EEADR), A ; ; movlw 82 ; LD A, 82 goto PLAYBACK0 ; JP PLAYBACK0 PLAYBACK1 ; PLAYBACK1 movlw 12 ; LD A, 12 ; 05 PLAYBACK0 movwf signalCnt ; PLAYBACK0 LD (signalCnt), A ; 06 bcf STATUS, RP0 ; RES RP0, (STATUS) ; 07 バンク0へ PLAYBACK2 nop ; PLAYBACK2 NOP ; 08 nop ; NOP ; 09 call LED_ON ; CALL LED_ON ; 10,11 nop ; NOP ; 05 nop ; NOP ; 06 nop ; NOP ; 07 nop ; NOP ; 08 nop ; NOP ; 09 call LED_OFF ; CALL LED_OFF ; 10,11 nop ; NOP ; 05 nop ; NOP ; 06 nop ; NOP ; 07 nop ; NOP ; 08 nop ; NOP ; 09 call LED_ON ; CALL LED_ON ; 10,11 nop ; NOP ; 05 nop ; NOP ; 06 nop ; NOP ; 07 nop ; NOP ; 08 nop ; NOP ; 09 call LED_OFF ; CALL LED_OFF ; 10,11 decfsz signalCnt goto PLAYBACK2 ; DJNZ (signalCnt), PLAYBACK2 ; 05,06,(07) ; bsf STATUS, RP0 ; SET RP0, (STATUS) ; 07 バンク1へ bsf EECON1, RD ; SET RD, (EECON1) ; 08 EE Read movf EEDATA, W ; LD A, (EEDATA) ; 09 Move data to W movwf signalCnt ; LD (signalCnt), A ; 10 sublw 0FFh ; SUB A, 0FFh ; 11 btfsc STATUS, Z goto FINISH ; JP Z, FINISH ; 12,13 終了コードなら送信完了(無限ループ) incf EEADR ; INC (EEADR) ; 01 bcf STATUS, RP0 ; RES RP0, (STATUS) ; 02 バンク0へ ; movlw 9 ; LD A, 9 ; 03 9 x 3 + 3 = 30us = 13 x 2 + 4 goto PLAYBACK5 ; JP PLAYBACK5 ; 04,05 PLAYBACK4 nop ; PLAYBACK4 NOP ; 02 nop ; NOP ; 03 PLAYBACK5 call WAITnx3p5us ; PLAYBACK5 CALL WAITnx3p5us ; 04,05 時間待ち movlw 14 ; LD A, 14 ; 06 14 x 3 + 3 = 45us = 13 x 3 + 6 decfsz signalCnt goto PLAYBACK4 ; DJNZ (signalCnt), PLAYBACK4 ; 12,13,(01) ; nop ; NOP ; 01 nop ; NOP ; 02 goto PLAYBACK1 ; JP PLAYBACK1 ; 03,04 ; ; ;-------------------------------------------------------------------------------- ; ; ; ; 赤外線LEDのON/OFF ; ; LED_ON ; LED_ON movlw 11001000b ; LD A, 11001000b ; 12 andwf GPIO ; AND (GPIO), A ; 13 x 2 = 26us = 38.46kHz (IR LED OFF) nop ; NOP ; 01 nop ; NOP ; 02 return ; RET ; 03,04 ; LED_OFF ; LED_OFF movlw 00110111b ; LD A, 00110111b ; 12 iorwf GPIO ; OR (GPIO), A ; 13 x 2 = 26us = 38.46kHz (IR LED ON) nop ; NOP ; 01 nop ; NOP ; 02 return ; RET ; 03,04 ; ; ;-------------------------------------------------------------------------------- ; ; ; ; 終了(無限ループ) ; ; FINISH ; FINISH sleep ; HALT ; ; ################################################################################ ; # ; # 時間待ち(小) ; # ; # LD A, 10 ; 10を指定すると、 ; # CALL WAITnx3p5us ; 2行で 10 x 3 + 5 = 35us 消費 ; # WAITnx3p5us ; WAITnx3p5us movwf waitCntS ; LD (waitCntS), A WAITnx3p5us1 ; WAITnx3p5us1 decfsz waitCntS goto WAITnx3p5us1 ; DJNZ (waitCntS), WAITnx3p5us1 return ; RET