;**********************************************************************
;            < e-orgel.asm >
;            Kuroki Fukuzo                                       2003.03.26
;PIOTEST1
;DEVICE : PIC16F84A
;CLOCK  : 10MHz
;電子オルゴールプロ グラム
;**********************************************************************
         list      p=16F84
         #include <P16F84a.inc>
 
         __CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_OFF & _HS_OSC
 
;**********************************************************************
              CBLOCK         H'0C'              ;ファイルアドレス0Ch番地から変数を割り当てる
              ;
              CNT0,CNT1    ;遅延用カウンタ
              E_ADRS                       ;EEPROMデータ・メモリアドレス
              A_WORK,B_WORK,C_WORK,D_WORK,H_WORK,L_WORK
              ;
              ENDC                                        ;CBLOCK終了
;
;onkai data              x=10000000/40/32/F
FA          EQU              D'89'              ;F  88
FAs        EQU              D'84'              ;F# 93
SO         EQU              D'80'              ;G  98
SOs        EQU              D'75'              ;G# 104
RA         EQU              D'71'              ;A  110
RAs        EQU              D'67'              ;A# 117
SI          EQU              D'63'              ;B  124
DO0       EQU              D'60'              ;C  131Hz
DO0s     EQU              D'56'              ;C# 139
RE0       EQU              D'53'              ;D  147
RE0s      EQU              D'50'              ;D# 155
MI0       EQU              D'47'              ;E  165
FA0        EQU              D'45'              ;F  175
FA0s      EQU              D'42'              ;F# 185
SO0       EQU              D'40'              ;G  196
SO0s      EQU              D'38'              ;G# 208
RA0       EQU              D'36'              ;A  220
RA0s      EQU              D'34'              ;A# 233
SI0        EQU              D'32'              ;B  247
DO1       EQU              D'30'              ;C  262Hz
DO1s     EQU              D'28'              ;C# 277
RE1       EQU              D'27'              ;D  294
RE1s      EQU              D'25'              ;D# 311
MI1       EQU              D'24'              ;E  330
FA1        EQU              D'22'              ;F  349
FA1s      EQU              D'21'              ;F# 370
SO1       EQU              D'20'              ;G  392
SO1s      EQU              D'19'              ;G# 415
RA1       EQU              D'18'              ;A  440
RA1s      EQU              D'17'              ;A# 466
SI1        EQU              D'16'              ;B  494
DO2       EQU              D'15'              ;C  523Hz
DO2s     EQU              D'14'              ;C# 554
;RE2      EQU              D'13'              ;D  587
;RE2s     EQU              D'12'              ;D# 622
;MI2      EQU              D'12'              ;E  659
;FA2       EQU              D'11'              ;F  698
;FA2s     EQU              D'10'              ;F# 740
;SO2      EQU              D'10'              ;G  784
;SO2s     EQU              D'09'              ;G# 831
KYU      EQU              H'FF'              ;休止
SYU       EQU              H'00'              ;終了
;
;ontyou data
ONT0    EQU              H'20'
ONT1    EQU              H'18'
ONT2    EQU              H'10'
ONT3    EQU              H'0C'
ONT4    EQU              H'08'
ONT5    EQU              H'06'
ONT8    EQU              H'04'
ONT16  EQU              H'02'
ONT00  EQU              H'00'
;
              ORG              2100H           ;EEPROMデータ・メモリ、データセット(64Byte)
              DE              SO0,ONT8,FA0,ONT8,FA0,ONT1,RA0,ONT8,SI0,ONT8              ;Yesterday
              DE              DO1s,ONT8,RE1,ONT8,MI1,ONT8,FA0,ONT8,MI1,ONT4
              DE              RE1,ONT8,RE1,ONT1,KYU,ONT4,RE1,ONT8
              DE              RE1,ONT8,DO1,ONT8,RA0s,ONT8,RA0,ONT8,SO0,ONT8
              DE              RA0s,ONT8,RA0,ONT8,RA0,ONT2,KYU,ONT8,SO0,ONT8
              DE              FA0,ONT4,RA0,ONT8,SO0,ONT2,RE0,ONT8,RE0,ONT8,FA0,ONT4
              DE              KYU,ONT4,SYU,ONT00
              ;
              ;DE              SO0,ONT4,SO0,ONT8,RA0,ONT8,SI0,ONT4,SI0,ONT8              ;久しき昔
              ;DE              DO1,ONT8,RE1,ONT4,MI1,ONT8,RE1,ONT8,SI0,ONT4
              ;DE              KYU,ONT8,RE1,ONT4,DO1,ONT8,SI0,ONT8,RA0,ONT4
              ;DE              KYU,ONT8,DO1,ONT4,SI0,ONT8,RA0,ONT8,SO0,ONT4
              ;DE              KYU,ONT8,SO0,ONT4,SO0,ONT8,RA0,ONT8,SI0,ONT4
              ;DE              SI0,ONT8,DO1,ONT8,RE1,ONT4,MI1,ONT8,RE1,ONT8
              ;DE              KYU,ONT4,SYU,ONT00
              ;
;--------------------------------
              ORG       00H       ; processor reset vector
              GOTO      MAIN      ; go to beginning of program
MAIN
              BSF     STATUS,RP0  ;メモ リーバンクを1にセット
              MOVLW   0FFH        ;WレジスタにFFHをセット
              MOVWF   TRISA       ;TRISAFFHをセットPORT-Aを入力にセット
              MOVLW   0FCH        ;WレジスタにFCHをセット
              MOVWF   TRISB       ;TRISB01111111BをセットPB7を出力PB0~6を入力にセット
              MOVLW   080H        ;Wレジスタに80Hをセット
              MOVWF   OPTION_REG  ;OPTION_REG80Hをセット PORT-B PULL UPな し
              BCF     STATUS,RP0              ;メモリーバンクを0にセット
;***********************************************************************
;
;***********************************************************************
LOOP
              MOVLW         H'00'
              MOVWF              E_ADRS
LOOP1
              CALL              RD_EEPROM
              MOVWF              A_WORK
              ANDWF              A_WORK,W
              BTFSC              STATUS,Z
              GOTO           LOOP
              INCF              E_ADRS,F
              CALL              RD_EEPROM
              MOVWF              C_WORK
              MOVF              A_WORK,W
              MOVWF              B_WORK
              RLF              A_WORK,F
              BTFSC              STATUS,C
              GOTO              LOOP3
LOOP2
              CALL              SOUND
              DECF              C_WORK,F
              BTFSS              STATUS,Z
              GOTO              LOOP2
              INCF              E_ADRS,F
              GOTO              LOOP1
LOOP3
              MOVLW         D'50'
              CALL              DELAY
              INCF              E_ADRS,F
              GOTO              LOOP1
;
;*********************************
; SOUND
;*********************************
SOUND
              MOVLW         H'15'
              MOVWF              H_WORK
S1
              DECF              H_WORK,F
              BTFSC              STATUS,Z
              RETURN
              MOVF              B_WORK,W
              MOVWF              D_WORK
              MOVLW              B'11111101'
              MOVWF              PORTB
S2
              MOVLW         H'20'
              MOVWF              L_WORK
S21
              NOP
              DECFSZ              L_WORK,F
              GOTO           S21
              DECFSZ              D_WORK,F
              GOTO           S2
              ;
              MOVF              B_WORK,W
              MOVWF              D_WORK
              MOVLW              B'11111111'
              MOVWF              PORTB
S3
              MOVLW         H'20'
              MOVWF              L_WORK
S31
              NOP
              DECFSZ              L_WORK,F
              GOTO           S31
              DECFSZ              D_WORK,F
              GOTO           S3
              GOTO           S1
;*********************************
; Read to EEPROM
;*********************************
RD_EEPROM
              BCF              STATUS,RP0 ;Set to page 0
              MOVF              E_ADRS,W     ;データエリアのアドレス指定
              MOVWF              EEADR                       ;Set address register
              BSF              STATUS,RP0 ;Set to page 1
              BSF              EECON1,RD              ;Start read
              BCF              STATUS,RP0              ;Return to page 0
              MOVF              EEDATA,W     ;Wレジスタにデータ取り出し
              RETURN
;*********************************
; TIMER
;*********************************
DELAY                                            ;(Wの内容)x1024サイクル遅延させる
              MOVWF        CNT0              ;Wの内容をCNT0へ入れる
DELAY_0
              CLRF              CNT1              ;CNT1の内容を0にする
DELAY_1
              NOP
              DECFSZ              CNT1,F              ;CNT1から1を引いて、
              GOTO              DELAY_1        ;0以外ならDELAY_1へ跳ぶ
              DECFSZ              CNT0,F              ;CNT0から1を引いて、
              GOTO              DELAY_0        ;0以外ならDELAY_1へ跳ぶ
              RETURN
;--------------------------------
        END
戻る