侵入者を見つけて教えてくれるはちゅねミクを作ってみた PICソースコード
まとめ記事に統合していたPICのソースコードですが、あっちの記事の文字数制限に引っかかって文章が消えたりして不便だったので別記事としてこちらに移しました。
以下がソースコード全文です。
PIC16F88を20MHz(セラロック)で動作させています。
LIST p=16F88 ; list directive to define processor #INCLUDE <P16F88.INC> ; processor specific variable definitions __CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF CBLOCK 0x20 ; Sample GPR variable registers allocated contiguously MYVAR1 ; User variable MYVAR2 ; User variable MYVAR3 ; User variable ENDC ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;レジスタ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; tm1 equ 0x20 ;タイマ用レジスタ1 tm2 equ 0x21 ;タイマ用レジスタ2 tm3 equ 0x22 ;タイマ用レジスタ3 sendReg equ 0x23 ;シリアル送信データレジスタ adSubReg equ 0x24 ;AD変換処理用レジスタ adBeforeReg equ 0x25 ;AD変換処理用レジスタ adCount equ 0x26 ;AD変換処理用レジスタ adResultReg equ 0x27 ;AD変換処理用レジスタ adResultTmp equ 0x28 ;AD変換処理用レジスタ sw1beforeReg equ 0x29 ;スイッチ1用前状態レジスタ sw2beforeReg equ 0x2A ;スイッチ2用前状態レジスタ pwmReg equ 0x2B ;PWM用スピードレジスタ sound_simple_tmp equ 0x2C ;音再生用レジスタ sound_eight_tmp equ 0x2D ;音再生用レジスタ sound_four_tmp equ 0x2E ;音再生用レジスタ rest_tmp equ 0x2F ;音再生用レジスタ clearBeepReg equ 0x30 ;解除時ビープ用レジスタ adDoResultReg equ 0x31 ;AD変換結果レジスタ(0x00:検出なし、0x01:検出) sw1reg equ 0x32 ;SW1状態レジスタ sw2reg equ 0x33 ;SW2状態レジスタ rcReceiveReg equ 0x34 ;RCREGの中身 temp equ 0x35 ;汎用一時レジスタ temp2 equ 0x36 ;汎用一時レジスタ receiveFlag equ 0x37 ;シリアル受信フラグ modeReg equ 0x38 ;動作モードレジスタ EEPROM_reg equ 0x70 ;EEPROMから読み出したデータ EEPROM_adress equ 0x71 ;EEPROMアドレス指定 W_TEMP equ 0x7D ; w register for context saving (ACCESS) STATUS_TEMP equ 0x7E ; status used for context saving (ACCESS) PCLATH_TEMP equ 0x7F ; variable used for context saving ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;データ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FLASH_SEC equ d'31' ;点滅秒数+1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;EEPROM保存初期データ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; org 0x2100 de d'0' ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;RESETベクタ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; RESET ORG 0x0000 ; processor reset vector PAGESEL START GOTO START ; go to beginning of program ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;割り込み ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ISR ORG 0x0004 ; interrupt vector location ; Context saving for ISR MOVWF W_TEMP ; save off current W register contents MOVF STATUS,W ; move status register into W register MOVWF STATUS_TEMP ; save off contents of STATUS register MOVF PCLATH,W ; move pclath register into W register MOVWF PCLATH_TEMP ; save off contents of PCLATH register bsf receiveFlag,0 ;受信が終了したか btfss PIR1,RCIF goto $-1 movfw RCREG movwf rcReceiveReg ; Restore context before returning from interrupt MOVF PCLATH_TEMP,W ; retrieve copy of PCLATH register MOVWF PCLATH ; restore pre-isr PCLATH register contents MOVF STATUS_TEMP,W ; retrieve copy of STATUS register MOVWF STATUS ; restore pre-isr STATUS register contents SWAPF W_TEMP,F SWAPF W_TEMP,W ; restore pre-isr W register contents RETFIE ; return from interrupt ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;初期化 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; START ;bank0 bcf STATUS,RP0 bcf STATUS,RP1 movlw b'11000000' ;割り込み許可 movwf INTCON movlw b'00010000' movwf RCSTA movlw b'00001100' movwf CCP1CON clrf TMR2 ;bank1 bsf STATUS,RP0 bcf STATUS,RP1 movlw b'00110001' movwf TRISA movlw b'00000100' movwf TRISB movlw b'00000001' movwf ANSEL movlw b'00100100' movwf TXSTA movlw d'129' movwf SPBRG movlw b'01000000' movwf ADCON1 movlw 0xff movwf PR2 movlw b'00100000' movwf PIE1 ;bank0 bcf STATUS,RP0 bcf STATUS,RP1 clrf PORTA clrf PORTB call clearAllRegs ;goto test ;goto demoModeLoop goto startMainLoop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;test ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; test call serialDataLedFlash nop goto $-1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;startMainLoop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; startMainLoop bsf PORTA,1 ;動作LEDオン call modeLedSet ;動作モードLED点灯 goto mainLoop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;mainLoop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; mainLoop call checkSw1 btfsc sw1reg,0 goto startWatch call checkSw2 btfsc sw2reg,0 goto changeMode call wait_10ms goto mainLoop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;EEPROM読み込み ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EEPROM_read banksel EEADR movfw EEPROM_adress movwf EEADR banksel EECON1 bcf EECON1,EEPGD bsf EECON1,RD banksel EEDATA movfw EEDATA movwf EEPROM_reg banksel PORTA return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;EEPROM書き込み ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EEPROM_write banksel EEADR movfw EEPROM_adress movwf EEADR ;Data Memory Address to write movfw EEPROM_reg movwf EEDATA ;Data Memory Value to write banksel EECON1 bcf EECON1,EEPGD ;Point to DATA memory bsf EECON1,WREN ;Enable writes bcf INTCON,GIE ;Disable INTs. btfsc INTCON,GIE ;SEE AN576 goto $-2 movlw 0x55 movwf EECON2 ;Write 55h movlw 0xAA movwf EECON2 ;Write AAh bsf EECON1,WR ;Set WR bit to begin write bsf INTCON,GIE ;Enable INTs. bcf EECON1,WREN ;Disable writes bcf STATUS,RP0 ;Bank 0 bcf STATUS,RP1 return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;全レジスタクリア ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; clearAllRegs clrf tm1 clrf tm2 clrf tm3 clrf sendReg clrf adSubReg clrf adBeforeReg clrf adCount clrf adResultReg clrf adResultTmp clrf sw1beforeReg clrf sw2beforeReg clrf pwmReg clrf sound_simple_tmp clrf sound_eight_tmp clrf sound_four_tmp clrf rest_tmp clrf clearBeepReg clrf adDoResultReg clrf sw1reg clrf sw2reg clrf rcReceiveReg clrf temp clrf temp2 clrf receiveFlag clrf modeReg clrf EEPROM_reg clrf EEPROM_adress clrf W_TEMP clrf STATUS_TEMP clrf PCLATH_TEMP return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;動作モードLEDセット ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; modeLedSet movlw 0x00 ;EEPROMの0x00にデータがある movwf EEPROM_adress call EEPROM_read movfw EEPROM_reg movwf modeReg goto modeLedSetNoEEPROMread ;ここにmodeLedSetNoEEPROMreadがあった。テーブル分岐のため下に移動 modeLedSet0 bcf PORTB,1 bcf PORTB,3 return modeLedSet1 bsf PORTB,1 bcf PORTB,3 return modeLedSet2 bcf PORTB,1 bsf PORTB,3 return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;SW2オンにより動作モード変更 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;ここにchangeModeがあった。テーブル分岐のため下に移動 changeMode0 movlw d'1' movwf modeReg movwf EEPROM_reg movlw 0x00 movwf EEPROM_adress call EEPROM_write call modeLedSetNoEEPROMread goto mainLoop changeMode1 movlw d'2' movwf modeReg movwf EEPROM_reg movlw 0x00 movwf EEPROM_adress call EEPROM_write call modeLedSetNoEEPROMread goto mainLoop changeMode2 movlw d'0' movwf modeReg movwf EEPROM_reg movlw 0x00 movwf EEPROM_adress call EEPROM_write call modeLedSetNoEEPROMread goto mainLoop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;監視開始 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; startWatch bcf sw1reg,0 call startWatchLedFlash ;解除なしのため監視開始 bsf PORTA,2 ;警戒開始LEDオン call watchStartBeep ;LED点滅で焦電センサ回路にノイズが入るから待機ループ call wait_500ms call wait_500ms ;adBeforeRegに初期値を入れる call adDo ;充電分があるかもしれないから1回余分にする call adWaitLoop call adDo movfw adResultReg movwf adBeforeReg goto watching ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;監視中 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; watching call adMain ;AD変換 btfsc adDoResultReg,0 goto detect ;検出 call checkSw1 btfsc sw1reg,0 goto clearAll call adWaitLoop goto watching ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;ここにdetectがあった。テーブル分岐のため下に移動 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;beep警告開始準備 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; detectBeepStart ;自動起動ありbeep=1を送信 movlw d'1' movwf sendReg call sendData detectBeepStartNoSerialSend movlw d'130' ;beepの時のPWMスピード movwf pwmReg call pwmOn goto normalBeep ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Ievan警告開始準備 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; detectIevanStart ;自動起動ありIevan=2を送信 movlw d'2' movwf sendReg call sendData detectIevanStartNoSerialSend movlw d'100' ;モータ始動用 movwf pwmReg call pwmOn call wait_50ms call pwmOff movlw d'40' ;Ievanの時のPWMスピード movwf pwmReg call pwmOn goto ievanPlay ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;自動起動なし開始準備 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; detectnoneStart ;自動起動なし=0を送信 movlw d'0' movwf sendReg call sendData goto detectWaitLoop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;自動起動なし検出後待機ループ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; detectWaitLoop ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call wait_10ms goto detectWaitLoop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;シリアル受信初期化 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; serialReset movfw RCREG movfw RCREG bcf RCSTA,OERR bcf RCSTA,FERR return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;シリアル受信データチェック ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;ここにreceiveDataがあった。テーブル分岐のため下に移動 receiveData0 call pwmOff bcf PORTB,4 ;SPのポートをLに goto detectWaitLoop receiveData1 call pwmOff bcf PORTB,4 ;SPのポートをLに goto detectBeepStartNoSerialSend receiveData2 call pwmOff bcf PORTB,4 ;SPのポートをLに goto detectIevanStartNoSerialSend receiveData3 call pwmOff bcf PORTB,4 ;SPのポートをLに ;警戒LEDクリア bcf PORTA,2 bcf PORTA,3 goto startWatch receiveData4 goto clearAll ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;完全解除 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; clearAll call clearBeep bcf PORTB,4 ;SPのポートをLに call pwmOff call serialReset call clearAllRegs ;警戒LEDクリア bcf PORTA,2 bcf PORTA,3 bcf RCSTA,SPEN ;シリアル受信不許可 call wait_500ms call wait_500ms goto startMainLoop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;SW1チェック ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; checkSw1 call wait_10ms btfss PORTA,5 goto sw1On goto sw1Off sw1On btfss PORTA,4 ;もう一方のSWが同時押しされたか goto demoMode btfss sw1beforeReg,0 goto sw1NewOn goto sw1StillOn sw1NewOn call selectBeep bsf sw1beforeReg,0 bsf sw1reg,0 return sw1StillOn goto checkSw1 sw1Off bcf sw1beforeReg,0 return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;SW2チェック ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; checkSw2 call wait_10ms btfss PORTA,4 goto sw2On goto sw2Off sw2On btfss sw2beforeReg,0 goto sw2NewOn goto sw2StillOn sw2NewOn call selectBeep bsf sw2beforeReg,0 bsf sw2reg,0 return sw2StillOn goto checkSw2 sw2Off bcf sw2beforeReg,0 return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;PMWオン ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; pwmOn movfw pwmReg ;スピードをpwmRegに入れてから実行 movwf CCPR1L bsf T2CON,TMR2ON return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;PMWオフ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; pwmOff clrf CCPR1L call wait_10ms ;これがないとHのままPWMが止まることがある bcf T2CON,TMR2ON return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;エラー発生 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; anyErrors bsf PORTA,1 bsf PORTA,2 bsf PORTA,3 bsf PORTB,1 bsf PORTB,3 movlw d'5' movwf temp anyErrorsBeepLoop decfsz temp,f goto anyErrorsBeep ;call wait_500ms bcf PORTA,1 bcf PORTA,2 bcf PORTA,3 bcf PORTB,1 bcf PORTB,3 call wait_500ms call checkSw1 btfsc sw1reg,0 goto clearAll goto anyErrors anyErrorsBeep call b5_eight goto anyErrorsBeepLoop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;AD変換処理部 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; adMain clrf adSubReg call adDo call adBeforeCheck ;AD変換値モニタ用シリアル送信部 ;movfw adBeforeReg ;movwf sendReg ;call sendData movfw adResultReg movwf adBeforeReg return adBeforeCheck movfw adBeforeReg subwf adResultReg,w ;adResultReg - adBeforeReg btfss STATUS,C return movwf adSubReg movlw d'20' ;しきい値幅 subwf adSubReg,w ;adSubReg - しきい値幅 btfsc STATUS,C goto adDetected return ;閾値以上=検知時 adDetected bsf adDoResultReg,0 return adDo movlw d'8' ;平滑化8回。ビットシフトとの兼ね合いもあるため回数変更不可 movwf adCount clrf adResultReg clrf adResultTmp adDoMain call adWaitLoop call adOn movfw ADRESH movwf adResultTmp bcf STATUS,C rrf adResultTmp,f bcf STATUS,C rrf adResultTmp,f bcf STATUS,C rrf adResultTmp,w addwf adResultReg,f decfsz adCount,f goto adDoMain return adOn movlw b'10000101' movwf ADCON0 btfsc ADCON0,2 goto $-1 return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;シリアル送信部 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; sendData movfw sendReg movwf TXREG banksel TXSTA btfss TXSTA,TRMT goto $-1 banksel TXREG call serialDataLedFlash return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;データ送受信時LED点滅 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; serialDataLedFlash bcf PORTA,1 call wait_50ms bsf PORTA,1 call wait_50ms bcf PORTA,1 call wait_50ms bsf PORTA,1 call wait_50ms bcf PORTA,1 call wait_50ms bsf PORTA,1 call wait_50ms bcf PORTA,1 call wait_50ms bsf PORTA,1 call wait_50ms bcf PORTA,1 call wait_50ms bsf PORTA,1 return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;監視開始時LED点滅 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; startWatchLedFlash movlw FLASH_SEC movwf temp startWatchLedFlashLoop decfsz temp,f goto startWatchLedFlashMain return startWatchLedFlashMain call wait_500ms bcf PORTA,1 call checkSw1 btfsc sw1reg,0 goto clearAll call wait_500ms bsf PORTA,1 call checkSw1 btfsc sw1reg,0 goto clearAll goto startWatchLedFlashLoop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;検出時LED点滅 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; detectLedFlash movlw FLASH_SEC movwf temp detectLedFlashLoop decfsz temp,f goto detectLedFlashMain return detectLedFlashMain call wait_500ms bcf PORTA,2 call checkSw1 btfsc sw1reg,0 goto clearAll call wait_500ms bsf PORTA,2 call checkSw1 btfsc sw1reg,0 goto clearAll goto detectLedFlashLoop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;ボタン押下時のビープ音 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; selectBeep call b5_eight return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;デモモード開始時のビープ音 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; demoStartBeep call a5_eight call b5_eight return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;監視開始時のビープ音 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; watchStartBeep call b5_eight call wait_10ms call b5_eight return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;解除時のビープ音 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; clearBeep movlw d'5' movwf clearBeepReg clearBeepMain decfsz clearBeepReg,f goto clearBeepOn return clearBeepOn call b5_eight goto clearBeepMain ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;デモモード ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; demoMode call demoStartBeep movlw d'100' ;モータ始動用 movwf pwmReg call pwmOn call wait_50ms call pwmOff movlw d'30' ;ネギ振りスピード movwf pwmReg call pwmOn demoModeLoop call demoLedFlash1 call checkSw1 btfsc sw1reg,0 goto clearAll call demoLedFlash2 call checkSw1 btfsc sw1reg,0 goto clearAll call demoLedFlash3 call checkSw1 btfsc sw1reg,0 goto clearAll call demoLedFlash4 call checkSw1 btfsc sw1reg,0 goto clearAll call demoLedFlash5 call checkSw1 btfsc sw1reg,0 goto clearAll goto demoModeLoop demoLedFlash1 bsf PORTA,1 bcf PORTA,2 bcf PORTA,3 bcf PORTB,1 bcf PORTB,3 call wait_500ms return demoLedFlash2 bcf PORTA,1 bsf PORTA,2 bcf PORTA,3 bcf PORTB,1 bcf PORTB,3 call wait_500ms return demoLedFlash3 bcf PORTA,1 bcf PORTA,2 bsf PORTA,3 bcf PORTB,1 bcf PORTB,3 call wait_500ms return demoLedFlash4 bcf PORTA,1 bcf PORTA,2 bcf PORTA,3 bsf PORTB,1 bcf PORTB,3 call wait_500ms return demoLedFlash5 bcf PORTA,1 bcf PORTA,2 bcf PORTA,3 bcf PORTB,1 bsf PORTB,3 call wait_500ms return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;10ms待機 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; wait_10ms movlw d'70' movwf tm1 wait_10ms_sub decfsz tm1,f goto wait_10ms_loop return wait_10ms_loop movlw d'237' movwf tm2 decfsz tm2,f goto $-1 goto wait_10ms_sub ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;50ms待機 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; wait_50ms movlw d'50' movwf tm1 wait_50ms_A decfsz tm1,f goto wait_50ms_B return wait_50ms_B movlw d'54' movwf tm2 wait_50ms_C decfsz tm2,f goto wait_50ms_D goto wait_50ms_A wait_50ms_D movlw d'30' movwf tm3 decfsz tm3,f goto $-1 goto wait_50ms_C ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;500ms待機 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; wait_500ms movlw d'200' movwf tm1 wait_500ms_A decfsz tm1,f goto wait_500ms_B return wait_500ms_B movlw d'130' movwf tm2 wait_500ms_C decfsz tm2,f goto wait_500ms_D goto wait_500ms_A wait_500ms_D movlw d'30' movwf tm3 decfsz tm3,f goto $-1 goto wait_500ms_C ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;AD変換wait待機 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; adWaitLoop movlw d'66' movwf tm1 adWaitLoopA decfsz tm1,f goto adWaitLoopB return adWaitLoopB movlw d'100' movwf tm2 adWaitLoopC decfsz tm2,f goto adWaitLoopD goto adWaitLoopA adWaitLoopD movlw d'30' movwf tm3 decfsz tm3,f goto $-1 goto adWaitLoopC ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;警告音ビープ音ver ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; normalBeep call gs5_four call cs5_four ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData goto normalBeep ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;警告音Ievanver ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ievanPlay call fs5_eight call cs5_eight call cs5_eight call fs5_eight call fs5r_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call fs5_eight call fs5_eight call fs5_eight call gs5_eight call a5r_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call a5_eight call fs5_eight call fs5r_eight call fs5_eight call fs5r_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call fs5_eight call a5_eight call gs5_eight call gs5_eight call e5_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call e5r_eight call e5_eight call e5r_eight call e5_eight call e5r_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call gs5r_eight call gs5_eight call fs5_eight call fs5r_eight call fs5_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call fs5_eight call fs5r_eight call fs5_eight call cs5_eight call cs5_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call fs5_eight call fs5r_eight call fs5_eight call fs5_eight call fs5r_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call gs5_eight call a5_eight call a5_eight call fs5r_eight call fs5_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call fs5_eight call fs5r_eight call fs5_eight call a5_eight call cs6r_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call cs6r_eight call cs6_eight call b5_eight call a5_eight call a5_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call gs5_eight call gs5_eight call a5_eight call a5_eight call fs5r_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call fs5r_eight call fs5_eight call fs5r_eight call fs5_eight call a5_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call cs6_eight call cs6r_eight call cs6_eight call cs6_eight call b5_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call b5_eight call a5_eight call a5_eight call gs5_eight call gs5_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call e5r_eight call e5r_eight call e5_eight call e5r_eight call e5_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call gs5_eight call b5r_eight call b5r_eight call b5r_eight call b5_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call a5r_eight call a5_eight call gs5r_eight call gs5_eight call a5_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call a5_eight call fs5r_eight call fs5r_eight call fs5_eight call fs5_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call fs5r_eight call fs5_eight call cs6_eight call cs6r_eight call cs6_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call cs6_eight call b5_eight call b5_eight call a5_eight call a5_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call gs5_eight call gs5_eight call e5r_eight call e5r_eight call e5_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call e5r_eight call e5_eight call gs5_eight call b5r_eight call b5r_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call b5r_eight call b5_eight call a5r_eight call a5_eight call gs5r_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call gs5_eight call a5_eight call a5_eight call fs5r_eight call fs5r_eight ;SW1チェック call checkSw1 btfsc sw1reg,0 goto clearAll ;シリアル受信フラグチェック btfsc receiveFlag,0 goto receiveData call fs5_eight call fs5_eight call fs5r_eight goto ievanPlay ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;音モジュール ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;C6モジュール c6_eight movlw d'250' movwf sound_eight_tmp c6_eight_main decfsz sound_eight_tmp,f goto c6_call return c6_call call c6_simple goto c6_eight_main c6_simple bsf PORTB,4 call c6_simple_timer bcf PORTB,4 call c6_simple_timer return c6_simple_timer movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'146' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 return ;F#5モジュール fs5_eight movlw d'185' movwf sound_eight_tmp fs5_eight_main decfsz sound_eight_tmp,f goto fs5_call return fs5_call call fs5_simple goto fs5_eight_main fs5_simple bsf PORTB,4 call fs5_simple_timer bcf PORTB,4 call fs5_simple_timer return fs5_simple_timer movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'60' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 return ;C#5モジュール cs5_eight movlw d'139' movwf sound_eight_tmp cs5_eight_main decfsz sound_eight_tmp,f goto cs5_call return cs5_call call cs5_simple goto cs5_eight_main cs5_simple bsf PORTB,4 call cs5_simple_timer bcf PORTB,4 call cs5_simple_timer return cs5_simple_timer movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'249' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 return ;C#5モジュールshort cs5_four movlw d'83' movwf sound_four_tmp cs5_four_main decfsz sound_four_tmp,f goto cs5_call_short return cs5_call_short call cs5_simple_short goto cs5_four_main cs5_simple_short bsf PORTB,4 call cs5_simple_timer_short bcf PORTB,4 call cs5_simple_timer_short return cs5_simple_timer_short movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'249' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 return ;G#5モジュールshort gs5_four movlw d'125' movwf sound_four_tmp gs5_four_main decfsz sound_four_tmp,f goto gs5_call_short return gs5_call_short call gs5_simple_short goto gs5_four_main gs5_simple_short bsf PORTB,4 call gs5_simple_timer_short bcf PORTB,4 call gs5_simple_timer_short return gs5_simple_timer_short movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'248' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 return ;G#5モジュール gs5_eight movlw d'208' movwf sound_eight_tmp gs5_eight_main decfsz sound_eight_tmp,f goto gs5_call return gs5_call call gs5_simple goto gs5_eight_main gs5_simple bsf PORTB,4 call gs5_simple_timer bcf PORTB,4 call gs5_simple_timer return gs5_simple_timer movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'200' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'48' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 return ;A5モジュール a5_eight movlw d'220' movwf sound_eight_tmp a5_eight_main decfsz sound_eight_tmp,f goto a5_call return a5_call call a5_simple goto a5_eight_main a5_simple bsf PORTB,4 call a5_simple_timer bcf PORTB,4 call a5_simple_timer return a5_simple_timer movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'200' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'20' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 return ;E5モジュール e5_eight movlw d'165' movwf sound_eight_tmp e5_eight_main decfsz sound_eight_tmp,f goto e5_call return e5_call call e5_simple goto e5_eight_main e5_simple bsf PORTB,4 call e5_simple_timer bcf PORTB,4 call e5_simple_timer return e5_simple_timer movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'128' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 return ;C#6モジュール ;短い cs6_eight movlw d'255' movwf sound_eight_tmp cs6_eight_main decfsz sound_eight_tmp,f goto cs6_call return cs6_call call cs6_simple goto cs6_eight_main cs6_simple bsf PORTB,4 call cs6_simple_timer bcf PORTB,4 call cs6_simple_timer return cs6_simple_timer movlw d'150' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'150' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'72' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 return ;B5モジュール b5_eight movlw d'247' movwf sound_eight_tmp b5_eight_main decfsz sound_eight_tmp,f goto b5_call return b5_call call b5_simple goto b5_eight_main b5_simple bsf PORTB,4 call b5_simple_timer bcf PORTB,4 call b5_simple_timer return b5_simple_timer movlw d'150' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'150' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'118' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 return ;F#5休符付きモジュール fs5r_eight movlw d'180' movwf sound_eight_tmp fs5r_eight_main decfsz sound_eight_tmp,f goto fs5r_call movlw d'250' movwf rest_tmp decfsz rest_tmp,f goto $-1 return fs5r_call call fs5r_simple goto fs5r_eight_main fs5r_simple bsf PORTB,4 call fs5r_simple_timer bcf PORTB,4 call fs5r_simple_timer return fs5r_simple_timer movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'60' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 return ;A5休符付きモジュール a5r_eight movlw d'215' movwf sound_eight_tmp a5r_eight_main decfsz sound_eight_tmp,f goto a5r_call movlw d'250' movwf rest_tmp decfsz rest_tmp,f goto $-1 return a5r_call call a5r_simple goto a5r_eight_main a5r_simple bsf PORTB,4 call a5r_simple_timer bcf PORTB,4 call a5r_simple_timer return a5r_simple_timer movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'200' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'20' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 return ;E5休符付きモジュール e5r_eight movlw d'160' movwf sound_eight_tmp e5r_eight_main decfsz sound_eight_tmp,f goto e5r_call movlw d'250' movwf rest_tmp decfsz rest_tmp,f goto $-1 return e5r_call call e5r_simple goto e5r_eight_main e5r_simple bsf PORTB,4 call e5r_simple_timer bcf PORTB,4 call e5r_simple_timer return e5r_simple_timer movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'128' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 return ;G#5休符付きモジュール gs5r_eight movlw d'203' movwf sound_eight_tmp gs5r_eight_main decfsz sound_eight_tmp,f goto gs5r_call movlw d'250' movwf rest_tmp decfsz rest_tmp,f goto $-1 return gs5r_call call gs5r_simple goto gs5r_eight_main gs5r_simple bsf PORTB,4 call gs5r_simple_timer bcf PORTB,4 call gs5r_simple_timer return gs5r_simple_timer movlw d'250' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'200' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'48' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 return ;C#6休符付きモジュール cs6r_eight movlw d'255' movwf sound_eight_tmp cs6r_eight_main decfsz sound_eight_tmp,f goto cs6r_call movlw d'250' movwf rest_tmp decfsz rest_tmp,f goto $-1 return cs6r_call call cs6r_simple goto cs6r_eight_main cs6r_simple bsf PORTB,4 call cs6r_simple_timer bcf PORTB,4 call cs6r_simple_timer return cs6r_simple_timer movlw d'150' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'150' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'72' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 return ;B5休符付きモジュール b5r_eight movlw d'242' movwf sound_eight_tmp b5r_eight_main decfsz sound_eight_tmp,f goto b5r_call movlw d'250' movwf rest_tmp decfsz rest_tmp,f goto $-1 return b5r_call call b5r_simple goto b5r_eight_main b5r_simple bsf PORTB,4 call b5r_simple_timer bcf PORTB,4 call b5r_simple_timer return b5r_simple_timer movlw d'150' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'150' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 movlw d'118' movwf sound_simple_tmp decfsz sound_simple_tmp,f goto $-1 return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; org 0x600 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;テーブル分岐:動作モードLEDセット ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; modeLedSetNoEEPROMread ;動作モードにより分岐 movlw high(modeLedSetNoEEPROMread) movwf PCLATH movfw modeReg addwf PCL,f goto modeLedSet0 ;0 goto modeLedSet1 ;1 goto modeLedSet2 ;2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;テーブル分岐:SW2オンにより動作モード変更 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; changeMode bcf sw2reg,0 movlw high(changeMode) movwf PCLATH movfw modeReg addwf PCL,f goto changeMode0 ;0 goto changeMode1 ;1 goto changeMode2 ;2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;テーブル分岐:検出 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; detect bcf adDoResultReg,0 call detectLedFlash ;以下解除されなかった場合 bsf PORTA,3 ;検知LED点灯 call serialReset bsf RCSTA,SPEN ;シリアル受信許可 ;動作モードにより分岐 movlw high(detect) movwf PCLATH movfw modeReg addwf PCL,f goto detectnoneStart ;0 goto detectBeepStart ;1 goto detectIevanStart ;2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;テーブル分岐:シリアル受信データチェック ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; receiveData bcf receiveFlag,0 call serialDataLedFlash ;受信データのエラーチェック btfsc RCSTA,OERR goto anyErrors btfsc RCSTA,FERR goto anyErrors movlw high(receiveData) movwf PCLATH movfw rcReceiveReg addwf PCL,f goto receiveData0 ;0:警報none goto receiveData1 ;1:警報beep goto receiveData2 ;2:警報Ievan goto receiveData3 ;3:検知前警戒状態へ goto receiveData4 ;4:完全解除 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; END