📄 doorbell.sdi
字号:
,,, LIST p=16F84 ; PIC16F844 is the target processor
,,,
,,, #include "P16F84.INC" ; Include header file
,,, LIST
,,,; P16F84.INC Standard Header File, Version 2.00 Microchip Technology, Inc.
,,, LIST
,,,
,,, CBLOCK 0x10 ; Temporary storage
,,, tempo
,,, tptrl
,,, tptrh
,,, note
,,, length
,,, pitch
,,, temp
,,, dl1
,,, dl2
,,, ENDC
,,,
,,,
,,, ORG 0
0000,2805,entrypoint,entrypoint goto initialise
,,,
,,, ORG 4
0004,2870,intvector,intvector goto toggle
,,,
0005,,initialise,initialise ; Register set up:
0005,0103,, clrw ; Zero.
0006,0085,, movwf PORTA ; Ensure PORTB is zero before we enable it.
0007,0086,, movwf PORTB ; Ensure PORTB is zero before we enable it.
0008,1683,, bsf STATUS,RP0 ; Select Bank 1
0009,0186,, clrf TRISB ; Port B is outputs
,,,
,,, ; Set up timer 0 for tone generation
000A,3002,, movlw 0x02 ; Prescaler on, internal clocking, divide by 4
000B,0081,, movwf OPTION_REG
000C,1283,, bcf STATUS,RP0 ; Back to bank 0
,,,
,,,
,,, ; Poll for a button
000D,0186,wait,wait clrf PORTB
000E,1C05,wloop,wloop btfss PORTA,0
000F,2813,, goto playtune0
0010,1C85,, btfss PORTA,1
0011,281C,, goto playtune1
0012,280E,, goto wloop
,,,
,,,;Routines to play the tunes
0013,3013,playtune0,playtune0 movlw 0x13
0014,0086,, movwf PORTB
0015,3050,, movlw 0x50
0016,0090,, movwf tempo
0017,3000,, movlw tune0 / 0x100
0018,0092,, movwf tptrh
0019,3080,, movlw tune0 % 0x100
001A,0091,, movwf tptrl
001B,2825,, goto playtune
,,,
001C,3023,playtune1,playtune1 movlw 0x23
001D,0086,, movwf PORTB
001E,30A0,, movlw 0xA0
001F,0090,, movwf tempo
0020,3001,, movlw tune1 / 0x100
0021,0092,, movwf tptrh
0022,3042,, movlw tune1 % 0x100
0023,0091,, movwf tptrl
0024,2825,, goto playtune
,,,
,,,;Subroutine to play a tune
0025,2045,playtune,playtune call gettunedata ; Lookup note from tune table
0026,0093,, movwf note ; Store the note code
0027,1B93,, btfsc note,7 ; Bit 7 set => end of tune
0028,280D,, goto wait ; Back to waiting for a button press
0029,0A91,, incf tptrl,F ; Increment the tune pointer
002A,2045,, call gettunedata ; Get the note length
002B,0094,, movwf length ; Store it
,,,
,,,; Play the stored note
,,,; The tune table supports two octaves and 8 note lengths.
002C,1B13,playnote,playnote btfsc note,6 ; Bit 6 set => rest
002D,2836,, goto playwait ; Silence ensues...
002E,0813,, movf note,W ; Retrieve the note
002F,393F,, andlw 0x3F ; Mask off the pitch index
0030,2049,, call pitchtable ; and look it up in the pitchtable
0031,0095,, movwf pitch ; Transfer the value to Timer 0
0032,0081,, movwf TMR0
0033,110B,, bcf INTCON,T0IF ; Clear Timer Interrupt
0034,168B,, bsf INTCON,T0IE ; Enable interrupts for Timer 0
0035,178B,, bsf INTCON,GIE
0036,0814,playwait,playwait movf length,W ; Retrieve the note length
0037,0097,, movwf dl1 ; and store it in delay counter 1
0038,0810,loop1,loop1 movf tempo,W ; This value sets the timing resolution
0039,0098,, movwf dl2
003A,0000,loop2,loop2 nop ; Inner delay loop delay
003B,0000,, nop
003C,0B98,, decfsz dl2,F
003D,283A,, goto loop2
003E,0B97,, decfsz dl1,F ; Outer delay loop
003F,2838,, goto loop1
0040,128B,, bcf INTCON,T0IE ; Timer interrupts off
,,,
,,,;Fetch next note/length pair:
0041,0A91,, incf tptrl,F ; Increment tune ptr
0042,1903,, btfsc STATUS,Z ; Test for low byte rollover
0043,0A92,, incf tptrh,F ; Inc high byte
0044,2825,, goto playtune ; Loop for next note
,,,
,,,; Routine to fetch data from the tune tables
0045,0812,gettunedata,gettunedata movf tptrh,W ; Set up PCLATH for the jump
0046,008A,, movwf PCLATH
0047,0811,, movf tptrl,W ; Get low address of tptr
0048,0082,, movwf PCL ; Jump off to the table entry
,,,
,,,; Pitch lookup function
0049,018A,pitchtable,pitchtable clrf PCLATH ; Clear PCLATH for zero page
004A,0782,, addwf PCL,F
004B,3411,, retlw 0x11 ;C5 // Midi Code 60
004C,341F,, retlw 0x1F ;C#
004D,342B,, retlw 0x2B ;D
004E,3437,, retlw 0x37 ;D#
004F,3442,, retlw 0x42 ;E
0050,344D,, retlw 0x4D ;F
0051,3457,, retlw 0x57 ;F#
0052,3461,, retlw 0x61 ;G
0053,346A,, retlw 0x6A ;G#
0054,3472,, retlw 0x72 ;A (440)
0055,347A,, retlw 0x7A ;Bb
0056,3481,, retlw 0x81 ;B
0057,3489,, retlw 0x89 ;C6 // Midi Code 72
0058,348F,, retlw 0x8F ;Db
0059,3496,, retlw 0x96 ;D
005A,349C,, retlw 0x9C ;Eb
005B,34A1,, retlw 0xA1 ;E
005C,34A7,, retlw 0xA7 ;F
005D,34AC,, retlw 0xAC ;F#
005E,34B0,, retlw 0xB0 ;G
005F,34B5,, retlw 0xB5 ;Ab
0060,34B9,, retlw 0xB9 ;A (880)
0061,34BD,, retlw 0xBD ;Bb
0062,34C1,, retlw 0xC1 ;B
0063,34C4,, retlw 0xC4 ;C7 // Midi Code 84
0064,34C8,, retlw 0xC8 ;Db
0065,34CB,, retlw 0xCB ;D
0066,34CE,, retlw 0xCE ;Eb
0067,34D1,, retlw 0xD1 ;E
0068,34D3,, retlw 0xD3 ;F
0069,34D6,, retlw 0xD6 ;F#
006A,34D8,, retlw 0xD8 ;G
006B,34DA,, retlw 0xDA ;Ab
006C,34DC,, retlw 0xDC ;A (1760)
006D,34DE,, retlw 0xDE ;Bb
006E,34E0,, retlw 0xE0 ;
006F,34E2,, retlw 0xE2 ;C8 // Midi Code 96
,,,
,,,
,,,
,,,
,,,;Interrupt service - toggle the drive polarity to the sounder
,,,;Note that this does not preserve the status bits - be careful,
,,,;and that there is an assumption we are addressing bank 0.
0070,0096,toggle,toggle movwf temp
0071,0815,, movf pitch,W
0072,0081,, movwf TMR0
0073,0806,, movf PORTB,W
0074,3A0F,, xorlw 0x0F
0075,0086,, movwf PORTB
0076,110B,, bcf INTCON,T0IF
0077,0816,, movf temp,w
0078,0009,, retfie
,,,
,,,;Tune Tables
,,,;Must be on even byte boundary
,,,
0080,,, org 0x0080
,,,
,,,; Tune 0 Data
,,,; Bach 'Badinerie' from Suite No 2
0080,3417,tune0,tune0 retlw 0x17 ;B
0081,3478,, retlw 0x78 ;240
0082,341A,, retlw 0x1A ;D
0083,343C,, retlw 0x3C ;120
0084,3417,, retlw 0x17 ;B
0085,343C,, retlw 0x3C ;120
0086,3412,, retlw 0x12 ;F#
0087,3478,, retlw 0x78 ;240
0088,3417,, retlw 0x17 ;B
0089,343C,, retlw 0x3C ;120
008A,3412,, retlw 0x12 ;F#
008B,343C,, retlw 0x3C ;120
008C,340E,, retlw 0x0E ;D
008D,3478,, retlw 0x78 ;240
008E,3412,, retlw 0x12 ;F#
008F,343C,, retlw 0x3C ;120
0090,340E,, retlw 0x0E ;D
0091,343C,, retlw 0x3C ;120
0092,340B,, retlw 0x0B ;B
0093,34F0,, retlw 0xF0 ;480
0094,3406,, retlw 0x06 ;F#
0095,343C,, retlw 0x3C ;120
0096,340B,, retlw 0x0B ;B
0097,343C,, retlw 0x3C ;120
0098,340E,, retlw 0x0E ;D
0099,343C,, retlw 0x3C ;120
009A,340B,, retlw 0x0B ;B
009B,343C,, retlw 0x3C ;120
009C,340D,, retlw 0x0D ;C#
009D,343C,, retlw 0x3C ;120
009E,340B,, retlw 0x0B ;B
009F,343C,, retlw 0x3C ;120
00A0,340D,, retlw 0x0D ;C#
00A1,343C,, retlw 0x3C ;120
00A2,340B,, retlw 0x0B ;B
00A3,343C,, retlw 0x3C ;120
00A4,340A,, retlw 0x0A ;A#
00A5,343C,, retlw 0x3C ;120
00A6,340D,, retlw 0x0D ;C#
00A7,343C,, retlw 0x3C ;120
00A8,3410,, retlw 0x10 ;E
00A9,343C,, retlw 0x3C ;120
00AA,340D,, retlw 0x0D ;C#
00AB,343C,, retlw 0x3C ;120
00AC,340E,, retlw 0x0E ;D
00AD,3478,, retlw 0x78 ;240
00AE,340B,, retlw 0x0B ;B
00AF,3478,, retlw 0x78 ;240
00B0,3417,, retlw 0x17 ;B
00B1,3478,, retlw 0x78 ;240
00B2,341A,, retlw 0x1A ;D
00B3,343C,, retlw 0x3C ;120
00B4,3417,, retlw 0x17 ;B
00B5,343C,, retlw 0x3C ;120
00B6,3412,, retlw 0x12 ;F#
00B7,3478,, retlw 0x78 ;240
00B8,3417,, retlw 0x17 ;B
00B9,343C,, retlw 0x3C ;120
00BA,3412,, retlw 0x12 ;F#
00BB,343C,, retlw 0x3C ;120
00BC,340E,, retlw 0x0E ;D
00BD,3478,, retlw 0x78 ;240
00BE,3412,, retlw 0x12 ;F#
00BF,343C,, retlw 0x3C ;120
00C0,340E,, retlw 0x0E ;D
00C1,343C,, retlw 0x3C ;120
00C2,340B,, retlw 0x0B ;B
00C3,34F0,, retlw 0xF0 ;480
00C4,340E,, retlw 0x0E ;D
00C5,3478,, retlw 0x78 ;240
00C6,340E,, retlw 0x0E ;D
00C7,3478,, retlw 0x78 ;240
00C8,340E,, retlw 0x0E ;D
00C9,3478,, retlw 0x78 ;240
00CA,340E,, retlw 0x0E ;D
00CB,3478,, retlw 0x78 ;240
00CC,3417,, retlw 0x17 ;B
00CD,3478,, retlw 0x78 ;240
00CE,340E,, retlw 0x0E ;D
00CF,3478,, retlw 0x78 ;240
00D0,3410,, retlw 0x10 ;E
00D1,343C,, retlw 0x3C ;60
00D2,340E,, retlw 0x0E ;D
00D3,343C,, retlw 0x3C ;30
00D4,340D,, retlw 0x0D ;C#
00D5,3478,, retlw 0x78 ;240
00D6,3412,, retlw 0x12 ;F#
00D7,3478,, retlw 0x78 ;240
00D8,3412,, retlw 0x12 ;F#
00D9,3478,, retlw 0x78 ;240
00DA,3412,, retlw 0x12 ;F#
00DB,3478,, retlw 0x78 ;240
00DC,3412,, retlw 0x12 ;F#
00DD,3478,, retlw 0x78 ;240
00DE,341A,, retlw 0x1A ;D
00DF,3478,, retlw 0x78 ;240
00E0,3412,, retlw 0x12 ;F#
00E1,3478,, retlw 0x78 ;220
00E2,3412,, retlw 0x12 ;F#
00E3,343C,, retlw 0x3C ;30
00E4,3414,, retlw 0x14 ;G#
00E5,343C,, retlw 0x3C ;65
00E6,3411,, retlw 0x11 ;F
00E7,3478,, retlw 0x78 ;270
00E8,340D,, retlw 0x0D ;C#
00E9,343C,, retlw 0x3C ;120
00EA,3412,, retlw 0x12 ;F#
00EB,343C,, retlw 0x3C ;120
00EC,3415,, retlw 0x15 ;A
00ED,343C,, retlw 0x3C ;120
00EE,3412,, retlw 0x12 ;F#
00EF,343C,, retlw 0x3C ;120
00F0,3414,, retlw 0x14 ;G#
00F1,343C,, retlw 0x3C ;120
00F2,3412,, retlw 0x12 ;F#
00F3,343C,, retlw 0x3C ;120
00F4,3414,, retlw 0x14 ;G#
00F5,343C,, retlw 0x3C ;120
00F6,3412,, retlw 0x12 ;F#
00F7,343C,, retlw 0x3C ;120
00F8,3411,, retlw 0x11 ;F
00F9,343C,, retlw 0x3C ;120
00FA,3414,, retlw 0x14 ;G#
00FB,343C,, retlw 0x3C ;120
00FC,3417,, retlw 0x17 ;B
00FD,343C,, retlw 0x3C ;120
00FE,3414,, retlw 0x14 ;G#
00FF,343C,, retlw 0x3C ;120
0100,3415,, retlw 0x15 ;A
0101,343C,, retlw 0x3C ;120
0102,3414,, retlw 0x14 ;G#
0103,343C,, retlw 0x3C ;120
0104,3415,, retlw 0x15 ;A
0105,343C,, retlw 0x3C ;120
0106,3414,, retlw 0x14 ;G#
0107,343C,, retlw 0x3C ;120
0108,3412,, retlw 0x12 ;F#
0109,343C,, retlw 0x3C ;120
010A,3415,, retlw 0x15 ;A
010B,343C,, retlw 0x3C ;120
010C,3412,, retlw 0x12 ;F#
010D,343C,, retlw 0x3C ;120
010E,3411,, retlw 0x11 ;F
010F,343C,, retlw 0x3C ;120
0110,3412,, retlw 0x12 ;F#
0111,343C,, retlw 0x3C ;120
0112,3417,, retlw 0x17 ;B
0113,343C,, retlw 0x3C ;120
0114,3412,, retlw 0x12 ;F#
0115,343C,, retlw 0x3C ;120
0116,3411,, retlw 0x11 ;F
0117,3439,, retlw 0x39 ;115
0118,3412,, retlw 0x12 ;F#
0119,343C,, retlw 0x3C ;120
011A,3419,, retlw 0x19 ;C#
011B,343E,, retlw 0x3E ;125
011C,3412,, retlw 0x12 ;F#
011D,343C,, retlw 0x3C ;120
011E,3411,, retlw 0x11 ;F
011F,343C,, retlw 0x3C ;120
0120,3412,, retlw 0x12 ;F#
0121,3439,, retlw 0x39 ;115
0122,341A,, retlw 0x1A ;D
0123,343E,, retlw 0x3E ;125
0124,3412,, retlw 0x12 ;F#
0125,343C,, retlw 0x3C ;120
0126,3411,, retlw 0x11 ;F
0127,343C,, retlw 0x3C ;120
0128,3412,, retlw 0x12 ;F#
0129,343C,, retlw 0x3C ;120
012A,341A,, retlw 0x1A ;D
012B,343C,, retlw 0x3C ;120
012C,3419,, retlw 0x19 ;C#
012D,343C,, retlw 0x3C ;120
012E,3417,, retlw 0x17 ;B
012F,343C,, retlw 0x3C ;120
0130,3419,, retlw 0x19 ;C#
0131,343C,, retlw 0x3C ;120
0132,3415,, retlw 0x15 ;A
0133,343C,, retlw 0x3C ;120
0134,3414,, retlw 0x14 ;G#
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -