No changes between revisions
/Designs/MB01B/SW/1_00/16f819.h
0,0 → 1,206
//////// Standard Header file for the PIC16F628 device ////////////////
#device PIC16F819
#nolist
//////// Program memory: 2048x14 Data RAM: 224 Stack: 8
//////// I/O: 16 Analog Pins: 0
//////// Data EEPROM: 112
//////// C Scratch area: 20 ID Location: 2000
//////// Fuses: LP,XT,HS,EC,NOWDT,WDT,NOPUT,PUT,PROTECT,PROTECT_50%
//////// Fuses: PROTECT_75%,NOPROTECT,NOBROWNOUT,BROWNOUT,MCLR,NOMCLR,LVP
//////// Fuses: NOLVP,ER_IO,INTRC_IO,ER,INTRC,CPD,NOCPD
////////
////////////////////////////////////////////////////////////////// I/O
// Discrete I/O Functions: SET_TRIS_x(), OUTPUT_x(), INPUT_x(),
// PORT_B_PULLUPS(), INPUT(),
// OUTPUT_LOW(), OUTPUT_HIGH(),
// OUTPUT_FLOAT(), OUTPUT_BIT()
// Constants used to identify pins in the above are:
 
#define PIN_A0 40
#define PIN_A1 41
#define PIN_A2 42
#define PIN_A3 43
#define PIN_A4 44
#define PIN_A5 45
#define PIN_A6 46
#define PIN_A7 47
 
#define PIN_B0 48
#define PIN_B1 49
#define PIN_B2 50
#define PIN_B3 51
#define PIN_B4 52
#define PIN_B5 53
#define PIN_B6 54
#define PIN_B7 55
 
////////////////////////////////////////////////////////////////// Useful defines
#define FALSE 0
#define TRUE 1
 
#define BYTE int
#define BOOLEAN short int
 
#define getc getch
#define fgetc getch
#define getchar getch
#define putc putchar
#define fputc putchar
#define fgets gets
#define fputs puts
 
////////////////////////////////////////////////////////////////// Control
// Control Functions: RESET_CPU(), SLEEP(), RESTART_CAUSE()
// Constants returned from RESTART_CAUSE() are:
#define WDT_FROM_SLEEP 0
#define WDT_TIMEOUT 8
#define MCLR_FROM_SLEEP 16
#define NORMAL_POWER_UP 24
 
 
////////////////////////////////////////////////////////////////// Timer 0
// Timer 0 (AKA RTCC)Functions: SETUP_COUNTERS() or SETUP_TIMER0(),
// SET_TIMER0() or SET_RTCC(),
// GET_TIMER0() or GET_RTCC()
// Constants used for SETUP_TIMER0() are:
#define RTCC_INTERNAL 0
#define RTCC_EXT_L_TO_H 32
#define RTCC_EXT_H_TO_L 48
 
#define RTCC_DIV_1 8
#define RTCC_DIV_2 0
#define RTCC_DIV_4 1
#define RTCC_DIV_8 2
#define RTCC_DIV_16 3
#define RTCC_DIV_32 4
#define RTCC_DIV_64 5
#define RTCC_DIV_128 6
#define RTCC_DIV_256 7
 
 
#define RTCC_8_BIT 0
 
// Constants used for SETUP_COUNTERS() are the above
// constants for the 1st param and the following for
// the 2nd param:
 
////////////////////////////////////////////////////////////////// WDT
// Watch Dog Timer Functions: SETUP_WDT() or SETUP_COUNTERS() (see above)
// RESTART_WDT()
//
#define WDT_18MS 8
#define WDT_36MS 9
#define WDT_72MS 10
#define WDT_144MS 11
#define WDT_288MS 12
#define WDT_576MS 13
#define WDT_1152MS 14
#define WDT_2304MS 15
 
////////////////////////////////////////////////////////////////// Timer 1
// Timer 1 Functions: SETUP_TIMER_1, GET_TIMER1, SET_TIMER1
// Constants used for SETUP_TIMER_1() are:
// (or (via |) together constants from each group)
#define T1_DISABLED 0
#define T1_INTERNAL 0x85
#define T1_EXTERNAL 0x87
#define T1_EXTERNAL_SYNC 0x83
 
#define T1_CLK_OUT 8
 
#define T1_DIV_BY_1 0
#define T1_DIV_BY_2 0x10
#define T1_DIV_BY_4 0x20
#define T1_DIV_BY_8 0x30
 
////////////////////////////////////////////////////////////////// Timer 2
// Timer 2 Functions: SETUP_TIMER_2, GET_TIMER2, SET_TIMER2
// Constants used for SETUP_TIMER_2() are:
#define T2_DISABLED 0
#define T2_DIV_BY_1 4
#define T2_DIV_BY_4 5
#define T2_DIV_BY_16 6
 
////////////////////////////////////////////////////////////////// CCP
// CCP Functions: SETUP_CCPx, SET_PWMx_DUTY
// CCP Variables: CCP_x, CCP_x_LOW, CCP_x_HIGH
// Constants used for SETUP_CCPx() are:
#define CCP_OFF 0
#define CCP_CAPTURE_FE 4
#define CCP_CAPTURE_RE 5
#define CCP_CAPTURE_DIV_4 6
#define CCP_CAPTURE_DIV_16 7
#define CCP_COMPARE_SET_ON_MATCH 8
#define CCP_COMPARE_CLR_ON_MATCH 9
#define CCP_COMPARE_INT 0xA
#define CCP_COMPARE_RESET_TIMER 0xB
#define CCP_PWM 0xC
#define CCP_PWM_PLUS_1 0x1c
#define CCP_PWM_PLUS_2 0x2c
#define CCP_PWM_PLUS_3 0x3c
long CCP_1;
#byte CCP_1 = 0x15
#byte CCP_1_LOW= 0x15
#byte CCP_1_HIGH= 0x16
////////////////////////////////////////////////////////////////// COMP
// Comparator Variables: C1OUT, C2OUT
// Constants used in setup_comparators() are:
#define A0_A3_A1_A2 4
#define A0_A2_A1_A2 3
#define NC_NC_A1_A2 5
#define NC_NC_NC_NC 7
#define A0_VR_A1_VR 2
#define A3_VR_A2_VR 10
#define A0_A2_A1_A2_OUT_ON_A3_A4 6
#define A3_A2_A1_A2 9
 
#bit C1OUT = 0x1f.6
#bit C2OUT = 0x1f.7
 
////////////////////////////////////////////////////////////////// VREF
// Constants used in setup_vref() are:
#define VREF_LOW 0xa0
#define VREF_HIGH 0x80
#define VREF_A2 0x40
 
////////////////////////////////////////////////////////////////// INT
// Interrupt Functions: ENABLE_INTERRUPTS(), DISABLE_INTERRUPTS(),
// EXT_INT_EDGE()
//
// Constants used in EXT_INT_EDGE() are:
#define L_TO_H 0x40
#define H_TO_L 0
// Constants used in ENABLE/DISABLE_INTERRUPTS() are:
#define GLOBAL 0x0BC0
#define INT_RTCC 0x0B20
#define INT_RB 0x0B08
#define INT_EXT 0x0B10
#define INT_TBE 0x8C10
#define INT_RDA 0x8C20
#define INT_TIMER1 0x8C01
#define INT_TIMER2 0x8C02
#define INT_CCP1 0x8C04
#define INT_LCD 0x8C80
#define INT_COMP 0x8C40
#define INT_EEPROM 0x0B40
#define INT_TIMER0 0x0B20
 
// Definice reistru pro pristup k EEPROM
#define EEDATA 0x010C
#define EEADR 0x010D
#define EEDATAH 0x010E
#define EEADRH 0x010F
#define EECON1 0x018C
#define EECON1_RD 0
#define EECON1_WR 1
#define EECON1_WREN 2
#define EECON1_WRERR 3
#define EECON1_FREE 4
#define EECON1_EEPGD 7
#define EECON2 0x018D
#define PIR2 0x000D
#define PIR2_EEIF 4
#define PIE2 0x008D
#define PIR2_EEIE 4
 
#list
/Designs/MB01B/SW/1_00/MB01A.HEX
0,0 → 1,238
:1000000000308A00902D0000FF00030E8301A10044
:100010007F08A0000A08A8008A01A00E0408A20018
:100020007708A3007808A4007908A5007A08A6003C
:100030007B08A700831383128C308400001D2228C4
:100040000C19CB28220884002308F7002408F800A4
:100050002508F9002608FA002708FB0028088A006E
:10006000210E8300FF0E7F0E09000A108A100A116C
:1000700082074E349534ED348C34043485348D3419
:100080007D3481347634DB346F3493346934A63470
:1000900063340E345E34C7345834CB34533417349D
:1000A0004F340A108A100A11820750344C344134FC
:1000B0005934003450344534523441345334453487
:1000C00000344534543445344D3450344F340034C6
:1000D000743450344134553453344534003470341E
:1000E00042344534473449344E3400344234543475
:1000F0004534533454340034623445344E3444343B
:1001000000345A34433400340034433449345334D3
:100110000034013444340034023444344934533418
:100120000034033445340034043446340034053498
:1001300046344934533400340634473400340734E9
:1001400047344934533400340834413400340934DA
:1001500041344934533400340A34483400340B34C5
:100160005334503441344334453400340C340A1091
:100170008A100A1182070034013402340534033432
:10018000063408340B340434073409340C340A348C
:100190000D340E340F347218CF288611D0288615EE
:1001A00083168611721CD82883120611DA2883164A
:1001B00083120615831606110130F20683120C1104
:1001C0008A11222869080C3C031909290B30970071
:1001D0008F018E010310690DF700EF006F0A3520C3
:1001E000FA006F083520F0007A08F10096007008D8
:1001F00095006A08F700031902290310960C950C64
:10020000F70BFD289530900083160C15C030831233
:100210008B04EE01ED0183160108C0390838810016
:1002200083126B086C04031932290B1D1C290B1156
:100230006930ED070318EE0AFA016E0CF900F90CAB
:10024000F90C1F30F90579087A04031931290030B7
:10025000ED020830031C0930EE026B080319EC03B1
:10026000EB03112983160C1183120B138B138B1BB9
:1002700036290034AD1C3E290530B3000230E100C0
:10028000B308031950296108E10AE2000930E900C6
:100290006208EA00EC013230EB00E220B3034029AF
:1002A000AD1000340830F700831686148312861CC4
:1002B0005729E101F7176A29F7136A290310861CE9
:1002C0000314E10C77176A297713F70B5E2961088D
:1002D000F8007629A730F71B2D30F800F80B6E29AF
:1002E0000000F71B5C29771B64295E29003410305D
:1002F000F700FA01EC01E90CE80C031C85296A08F7
:10030000FA070318EC0A6B08EC07EC0CFA0CF90C72
:10031000F80CF70B7B2900346208840061080007A1
:1003200084000008203C03199729003098290130E7
:10033000E9006208840063080002031CA129003060
:10034000A22901306905003A0319AA29620884002C
:10035000800A8C29E501E401620884006308000238
:10036000031CB7296408F8006508F900EA29620847
:1003700084006108000784000008E60066082F3C3E
:100380000318C4290030C5290130E7006608393C4C
:10039000031CCC290030CD2901306704003A031931
:1003A000D6296408F8006508F900EA296508E9001B
:1003B0006408E800EB010A30EA0077213030660279
:1003C0007807E4007908E5000318E50A620884006C
:1003D000800AAC290034290803178D0003132A086A
:1003E00003178F0083168C170C1400000000831273
:1003F0000C080313E10003170E080313E200620860
:10040000AC006108AB0000340530AA00FF30A90041
:10041000A90A0319AA0AEB212B0F152A2C083F3C25
:10042000031D152A0130F800322AA908031D1F2ACE
:100430002A08083C031D1F2A0130F800322A2B0825
:100440000039E1002C083839E200E108031D312AA7
:100450006208203C031D312AB40B312A0030F80019
:10046000322A082A00342B080F39E1002B0EF7003E
:100470000F30F705770807393207E3002C0CE50049
:100480002B0CE400E50CE40CE50CE40CE50CE40CAE
:10049000E50CE40CE50CE40CE50CE40C0130E5059E
:1004A00064083F39F70065080039FA007708E6006C
:1004B0007A08E7002F08E9002E08E8007A08EB0028
:1004C0007708EA0077217908E8007808E7006108F2
:1004D000E9006308EA007908EC007808EB00E22004
:1004E0000C30E900EA013108EC003008EB00E220B2
:1004F00000340422F80803197E2ADB2AAF01643095
:10050000AE00B101B0002B08B200A90A0319AA0A73
:10051000A908031D902A2A08083C031D902ADB2AFB
:10052000EB21A90A0319AA0A2B0F9B2A2C083F3C8E
:10053000031D9B2ADB2A2B080039E1002C083839DF
:10054000E200E108031DA92A6208203C031DA92A34
:10055000DB2A2B080039E1002C083839E200E108D9
:10056000031DBB2A6208283C031DBB2A2B08AE00D2
:100570002C08D739AF002B080039E1002C08383996
:10058000E200E108031DCD2A6208303C031DCD2A9C
:100590002B08B0002C08CF39B1002B080039E1003E
:1005A0002C082039E200E108031DDA2AE208031DC5
:1005B000DA2A3322882A00342D18DF2A462B2A080B
:1005C000053C031CE52A0030E62A0130E1002A0838
:1005D000073C0318ED2A0030EE2A01306105E200E5
:1005E000831685150030831285190130003A0319EE
:1005F000FB2A0030FC2A01306205003A0319452B22
:10060000831603178C170C15831203132908FC3962
:1006100003178D0003132A0803178F000313E1014A
:100620006108033C031C3B2B29080339E2002A081C
:100630000039E30061086202031D2A2BE308031D51
:100640002A2B2B0803178C0003132C0803178E008A
:100650002E2B0313FF3003178C008E0055308316AA
:100660008D00AA308D008C140000000083128D0ACA
:100670000313E10A102B831603170C118C1383123A
:100680000313A90A0319AA0A462BAD1400348316D2
:100690000512831205120C30E9000330EA00EC0168
:1006A0000A30EB00E2200330B300AD103A21AF0175
:1006B0006430AE00B101B000B2012D10E001DE01E6
:1006C000831685150030831285190130003A031D09
:1006D0008F2D52217808DD005D087F3C0318712BB7
:1006E000692B5D085F3C0318772B2030DD025D0825
:1006F0000D3C03197D2B00307E2B0130E1005D089D
:100700002F3C0319852B0030862B01306104003A01
:1007100003195B2D5D080D3C0319922B52217808BB
:10072000DD008A2B5E08DF00DE010130B3005F08C8
:100730005E020318582D3530E1005E30E2005F089C
:10074000E300620884006108000784000008203C80
:100750000319AC2B0030AD2B0130E8006208840097
:1007600063080002031CB62B0030B72B013068056C
:10077000003A0319BF2B62088400800AA12BE40110
:100780006408613C031C2B2C620884000008E5000F
:1007900063086502031CCE2B0030CF2B0130E6002E
:1007A00064085120003A031DD72B0030D82B0130AC
:1007B0006605E80064085120E900610865078400C7
:1007C000000869020319E62B0030E72B01306805A9
:1007D000003A0319EF2B6408E40AE50AC82B640801
:1007E0005120003A0319F62B0030F72B0130E700B7
:1007F0006108650784000008203C0319012C0030C3
:10080000022C0130E900630865020319092C00304D
:100810000A2C013069046705003A0319212C63088A
:100820006502031C162C01306302E5006208840097
:10083000013065078000013064075120F800F8009E
:100840002D2C64085120003A0319282CE40A212C8D
:10085000E40AE40AC02BFF30F8007808DD005D08E8
:10086000FF3C031D662C5F085E020318652C3530C3
:100870005E07840000082F3C031C402C0030412CF4
:100880000130E20035305E0784000008393C03186F
:100890004B2C00304C2C01306205003A03195C2CC3
:1008A0003530E1005E30E2005F08E3008C2178081B
:1008B000E0000730E005652C35305E078400000855
:1008C000203C0319642CAD14DE0A572D5D08503C02
:1008D000031D782C3530E1005E30E2005F08E30054
:1008E0008C217808B4002D1079220330B300572DE5
:1008F0005D08453C031DB62C2D100630AA00A90149
:100900002A08073C031CB32CEB212B0F8B2C2C0843
:100910003F3C0319AF2C83168515003083128519CF
:100920000130003A0319952CB32C290803178D00C8
:1009300003132A0803178F0083168C170C150C1647
:1009400055308D00AA308D008C14000000000C1171
:100950000C128C13023083120313B3003A21A90A3C
:100960000319AA0A802C0330B300572D5D08743C8C
:10097000031DD62C3530E1005E30E2005F08E30055
:100980008C217808AE007908C739AF00AE08031D86
:10099000CF2CAF08031DCF2CAF016430AE002E0862
:1009A000AB002F082838AC00DC22572D5D08703CC6
:1009B000031DF62C3530E1005E30E2005F08E300F5
:1009C0008C217808B0007908C739B100B008031D40
:1009D000EF2CB108031DEF2CB1016430B0003008DA
:1009E000AB0031083038AC00DC22572D5D08423CAA
:1009F000031D0D2DFF30B40004223530E1005E30C0
:100A0000E2005F08E3008C217808B2003208AB00F6
:100A10002030AC002D14DC22572D5D08623C031DF4
:100A20001C2D3530E1005E30E2005F08E3008C21D0
:100A30007808B2002D10572D5D085A3C031D222D59
:100A40002D10572D3530E1005E30E2005F08E300E5
:100A50008C217908AC007808AB003F30AB05003042
:100A6000AC05AB08031D3A2DAC08031D3A2DAB0AAB
:100A70000319AC0AAB0DAC0DAB0DAC0DAB0DAC0D51
:100A8000AB0DAC0DAB0DAC0DAB0DAC0DAB0DAC0DA2
:100A90008030AB055D08AB04600EF700F030F70561
:100AA0007708AB04DC222D18572D3322B301972B86
:100AB000DE013A21692B5D08083C0319612D0030E5
:100AC000622D0130E100DE08031D682D0030692D24
:100AD00001306105003A03196F2DDE03692B5D08B3
:100AE0002C3C0319752D0030762D0130E1005D0896
:100AF000203C03187D2D00307E2D01306104003A2A
:100B00000319842D2030DD005E08273C031C8E2D48
:100B10005E08DE0A353E84005D088000602BBE2D35
:100B200084011F308305073083169F000510831250
:100B300005108316811308308500F03086000630DA
:100B40009F0085150030831285190130003A031982
:100B5000AB2D0030AC2D0130B6008316861400306A
:100B6000831286180130003A0319B82D0030B92DD0
:100B700001303605003A0319BE2D472B8316851127
:100B8000831285110C30E9000330EA00EC010A30D1
:100B9000EB00E22083160512831205120C30E900E7
:100BA0000330EA00EC016430EB00E220060EF700AF
:100BB0000F30F70577080F3AB4003408B720F80073
:100BC000B40079220608003A0319E62D0B108B15A4
:100BD000831605128312051683168515630083128A
:060BE0008B11992D63004A
:100C000003206428643099009700190212020C0135
:100C10009A0099001A01190117020C019A00990013
:100C20001A0212020C019700950017011501140118
:100C3000170115020C019400950017020C01950094
:100C40009700190117011501140112021A02190265
:100C50000C0199009A009900970019020C010220DA
:100C6000642864301901200124012901270224018C
:100C70002401290127012401220124020C02190167
:100C80002001240129012701270124012401190140
:100C900024011B01240119020C0219012001240165
:100CA000290127012701240229012701240122010A
:100CB00024020C012401190120012401290127012A
:100CC000240224012901290128012B0129020C04F5
:100CD00024012901290129012801260129022901CC
:100CE0002B012B0129012B013101290224012901AA
:100CF00029012901280126012901290129012B01A6
:100D00002B012901280129020C01240129012901B3
:100D1000290128012601290229012B012B01290182
:100D20002B0131012902240129012901290128016E
:100D3000260129010C0129012B012B012901280180
:100D40002904270129042701290402209628643058
:100D50009900A000A400A200A0009B002001A20016
:100D60002401A200A700A700A700A700A900240152
:100D70000C02A200A500A900A700A500A400A400E1
:100D8000A500A400A000190198009B00A400A200E7
:100D90009B00A00019010C011B0120010C01220184
:100DA000A400A400A400A2009B00A000190101203F
:100DB0009628643090009000900094009200870084
:100DC00090010C029400940094009400920097000B
:100DD00014010C0297009700990097009500940069
:100DE00095009900970095009400920090008B0068
:100DF000900094009200870090010C0299009900E5
:100E0000990099009B00A20020020C01A400A400FC
:100E1000A400A400A200A70024020C01A700A700C0
:100E2000A900A700A500A400A500A900A700A5008F
:100E3000A400A200A0009B00A000A400A2009700B4
:100E400020020C011003070192018C01970097000A
:100E5000960097009900960017010C0297009700E2
:100E600099009700950094009500990097009500CF
:100E7000940092001003140192018C0110030701E9
:100E800092018C01970097009600970099009600B8
:100E900017010C02970097009900970095009400A5
:100EA00095009900970095009400920090008B00A7
:0E0EB000900094009200870010010C02FF3F9A
:02400E00223955
:00000001FF
;PIC16F819
/Designs/MB01B/SW/1_00/MB01A.LST
0,0 → 1,2735
CCS PCW C Compiler, Version 3.110, 15448
 
Filename: c:\krouzek\test\mb01a.LST
 
ROM used: 1523 (74%)
Largest free fragment is 512
RAM used: 29 (17%) at main() level
88 (50%) worst case
Stack: 6 worst case (5 in main + 1 for interrupts)
 
*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 590
0003: NOP
0004: MOVWF 7F
0005: SWAPF 03,W
0006: CLRF 03
0007: MOVWF 21
0008: MOVF 7F,W
0009: MOVWF 20
000A: MOVF 0A,W
000B: MOVWF 28
000C: CLRF 0A
000D: SWAPF 20,F
000E: MOVF 04,W
000F: MOVWF 22
0010: MOVF 77,W
0011: MOVWF 23
0012: MOVF 78,W
0013: MOVWF 24
0014: MOVF 79,W
0015: MOVWF 25
0016: MOVF 7A,W
0017: MOVWF 26
0018: MOVF 7B,W
0019: MOVWF 27
001A: BCF 03.7
001B: BCF 03.5
001C: MOVLW 8C
001D: MOVWF 04
001E: BTFSS 00.2
001F: GOTO 022
0020: BTFSC 0C.2
0021: GOTO 0CB
0022: MOVF 22,W
0023: MOVWF 04
0024: MOVF 23,W
0025: MOVWF 77
0026: MOVF 24,W
0027: MOVWF 78
0028: MOVF 25,W
0029: MOVWF 79
002A: MOVF 26,W
002B: MOVWF 7A
002C: MOVF 27,W
002D: MOVWF 7B
002E: MOVF 28,W
002F: MOVWF 0A
0030: SWAPF 21,W
0031: MOVWF 03
0032: SWAPF 7F,F
0033: SWAPF 7F,W
0034: RETFIE
.................... // Melodicky zvonek MB01A_1_00
.................... //
.................... // Prohram pro melodicky zvonek s pouzitim knihovny Sound_t1.C
.................... //
.................... // (c)miho 2004
.................... //
.................... // Historie:
.................... // 1.00 Uvodni verze
....................
.................... #include <16F819.h> // Definice procesoru
.................... //////// Standard Header file for the PIC16F628 device ////////////////
.................... #device PIC16F819
.................... #list
....................
.................... #fuses HS,NOPROTECT,NOWDT,PUT,NOLVP,NOBROWNOUT,WRT // Definice konfiguracniho slova
....................
.................... #define POWER_386 PIN_A4 // L zapne napajeni pro zesilovac LM386
.................... #define POWER_PIC PIN_A3 // L pripoji GND pro procesor PIC
....................
.................... #define SOUND_HI PIN_B3 // Akusticky vystup
.................... #define SOUND_LO PIN_B2 // Akusticky vystup
.................... #define SOUND_CLOCK 20000000 // Frekvence hodin
.................... #define SOUND_LowOctave 1 // O oktavu vys protoze mame moc rychly krystal
.................... #include "Sound_T1.c" // Hudebni knihovna
.................... // Knihovna pro generovani hudebnich zvuku dane frekvence a delky nebo
.................... // dane noty temperovaneho ladeni a delky.
.................... //
.................... // Pro gnerovani pouziva casovac T0, T1 a jednotku CCP1.
.................... //
.................... // POZOR -- POZOR -- POZOR
.................... // Pri nizsi frekvenci XTALu (nez asi 5MHz) je rezie preruseni tak velka, ze spotrebuje
.................... // veskery strojovy cas a uz nedojde k ukonceni rozehraneho tonu vyssi frekvence (z oktavy 7
.................... // nebo nad cca 8KHz). Resenim je pouzit vlastni INT proceduru s minimalni rezii.
.................... //
.................... // (c)miho 2004
.................... //
.................... // Historie
.................... // 1.00 Uvodni verze
....................
....................
.................... // Konfiguracni parametry
.................... //#define SOUND_HI PIN_xx // Pozitivni vystup
.................... //#define SOUND_LO PIN_xx // Komplementarni vystup
.................... #ifndef SOUND_CLOCK
.................... #define SOUND_CLOCK 4000000 // Frelvence krystalu v Hz
.................... #endif
....................
....................
.................... // Definice hudebnich tonu (not) pro proceduru SoundNote()
.................... #define SOUND_C 0
.................... #define SOUND_Cis 1
.................... #define SOUND_D 2
.................... #define SOUND_Dis 3
.................... #define SOUND_E 4
.................... #define SOUND_F 5
.................... #define SOUND_Fis 6
.................... #define SOUND_G 7
.................... #define SOUND_Gis 8
.................... #define SOUND_A 9
.................... #define SOUND_Ais 10
.................... #define SOUND_H 11
.................... #define SOUND_Space 12 // Pomlka
....................
....................
.................... // Prototypy verejnych procedur
....................
.................... void SoundBeep(unsigned int16 Frequency, unsigned int16 Duration);
.................... // Predava se frekvence v Hz a doba trvani v ms (0 znamena ticho)
....................
.................... void SoundNote(unsigned int8 Note, Octave, unsigned int16 Duration);
.................... // Predava se cislo noty (0 je C), posunuti v oktavach (0 nejnizsi ton,
.................... // SOUND_Space je ticho), doba trvani v ms
....................
.................... // Alternativni makra pro generovani konstatnich tonu
.................... // SoundBeepMacro(Frequency, Duration) - frekvence nesmi byt 0
.................... // SoundNoteMacro(Note, Octave, Duration) - nepodporuje SOUND_Space
.................... // SoundSpaceMacro(Duration) - hraje ticho
....................
.................... // Privatni cast
....................
....................
.................... #int_ccp1
.................... void IntCCP1()
.................... // Preruseni od jednotky CCP1 generuje vystup
.................... {
.................... volatile int1 Data; // Posledni stav vystupu
.................... output_bit(SOUND_HI,Data); // Nastav vystup
*
00CB: BTFSC 72.0
00CC: GOTO 0CF
00CD: BCF 06.3
00CE: GOTO 0D0
00CF: BSF 06.3
00D0: BSF 03.5
00D1: BCF 06.3
.................... output_bit(SOUND_LO,~Data);
00D2: BTFSS 72.0
00D3: GOTO 0D8
00D4: BCF 03.5
00D5: BCF 06.2
00D6: GOTO 0DA
00D7: BSF 03.5
00D8: BCF 03.5
00D9: BSF 06.2
00DA: BSF 03.5
00DB: BCF 06.2
.................... Data=~Data; // Otoc stav vystupu
00DC: MOVLW 01
00DD: XORWF 72,F
.................... }
....................
....................
.................... #if SOUND_CLOCK < (65535*32*4*2) // < 16.7 MHz
.................... #define SOUND_PRESCALE 1
.................... #elif SOUND_CLOCK < (65535*32*4*2*2) // < 33.6 MHz
.................... #define SOUND_PRESCALE 2
.................... #elif SOUND_CLOCK < (65535*32*4*2*4) // < 67.1 MHz
.................... #define SOUND_PRESCALE 4
.................... #elif SOUND_CLOCK < (65535*32*4*2*8) // < 134 MHz
.................... #define SOUND_PRESCALE 8
.................... #else
.................... #error SOUND_CLOCK Frequency too high
.................... #endif
00DE: BCF 03.5
00DF: BCF 0C.2
00E0: BCF 0A.3
00E1: GOTO 022
.................... #bit T0IF=0x0B.2
.................... void SoundBeep(unsigned int16 Frequency, unsigned int16 Duration)
.................... // Predava se frekvence v Hz a doba trvani v ms (0 znamena ticho)
.................... // Rozumne frekvence jsou od 32Hz
.................... {
.................... unsigned int16 Time; // Pocitadlo zlomkoveho casu
....................
.................... // Inicializace casovace
.................... if (Frequency!=0) // Frekvence 0 znamena ticho
.................... {
.................... setup_ccp1(CCP_COMPARE_RESET_TIMER);
.................... set_timer1(0);
.................... (int16)CCP_1=SOUND_CLOCK/SOUND_PRESCALE/4/2/Frequency;
.................... #if SOUND_PRESCALE==1
.................... setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
.................... #elif SOUND_PRESCALE==2
.................... setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
.................... #elif SOUND_PRESCALE==4
.................... setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
.................... #elif SOUND_PRESCALE==8
.................... setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
.................... #endif
.................... enable_interrupts(int_ccp1);
.................... enable_interrupts(global);
.................... }
....................
.................... // Delka tonu merena casovacem T0 (bez preruseni)
.................... Time=0;
.................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
.................... while (Duration)
.................... {
.................... if (T0IF) // Preteceni T0 - kazdych (1/CLK)*4*256
.................... {
.................... T0IF = 0;
.................... Time += (256*4*1000*2048+SOUND_CLOCK/2)/SOUND_CLOCK;
.................... }
.................... if (Time>>11)
.................... {
.................... Time -= 2048;
.................... Duration--;
.................... }
.................... }
....................
.................... // Konec casovace
.................... disable_interrupts(int_ccp1);
.................... disable_interrupts(global);
.................... }
....................
....................
.................... // Definice casu pulperody pro nejnizsi oktavu, v kvantech casovace T1
.................... // Pulperiody tonu v dalsich oktavach se ziskavaji rotaci vpravo
.................... #define SOUND_Peri_C ((30578*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 30578us
.................... #define SOUND_Peri_Cis ((28862*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 28862us
.................... #define SOUND_Peri_D ((27242*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 27242us
.................... #define SOUND_Peri_Dis ((25713*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 25713us
.................... #define SOUND_Peri_E ((24270*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 24270us
.................... #define SOUND_Peri_F ((22908*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 22908us
.................... #define SOUND_Peri_Fis ((21622*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 21622us
.................... #define SOUND_Peri_G ((20408*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 20408us
.................... #define SOUND_Peri_Gis ((19263*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 19263us
.................... #define SOUND_Peri_A ((18182*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 18182us
.................... #define SOUND_Peri_Ais ((17161*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 17161us
.................... #define SOUND_Peri_H ((16198*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 16198us
....................
.................... // Kontrola na delku konstanty (musi byt mensi nez delka citace)
.................... #if SOUND_Peri_C > 65535
.................... #error "SOUND_Peri_C too long (Note C requires delay > 65535 cycles)"
.................... #endif
....................
.................... // Casove konstanty pro noty nejnizsi oktavy
.................... const unsigned int16 Table[12] =
.................... SOUND_Peri_C, SOUND_Peri_Cis, SOUND_Peri_D, SOUND_Peri_Dis,
.................... SOUND_Peri_E, SOUND_Peri_F, SOUND_Peri_Fis, SOUND_Peri_G,
.................... SOUND_Peri_Gis, SOUND_Peri_A, SOUND_Peri_Ais, SOUND_Peri_H;
*
0035: BCF 0A.0
0036: BCF 0A.1
0037: BCF 0A.2
0038: ADDWF 02,F
0039: RETLW 4E
003A: RETLW 95
003B: RETLW ED
003C: RETLW 8C
003D: RETLW 04
003E: RETLW 85
003F: RETLW 8D
0040: RETLW 7D
0041: RETLW 81
0042: RETLW 76
0043: RETLW DB
0044: RETLW 6F
0045: RETLW 93
0046: RETLW 69
0047: RETLW A6
0048: RETLW 63
0049: RETLW 0E
004A: RETLW 5E
004B: RETLW C7
004C: RETLW 58
004D: RETLW CB
004E: RETLW 53
004F: RETLW 17
0050: RETLW 4F
....................
....................
.................... void SoundNote(unsigned int8 Note, Octave, unsigned int16 Duration)
.................... // Predava se cislo noty (0 je C), posunuti v oktavach (0 nejnizsi ton)
.................... // doba trvani v ms (0 znamena ticho)
.................... // Zahraje zadanou notu v zadane oktave dane delky
.................... {
.................... unsigned int16 Time; // Pocitadlo zlomkoveho casu
....................
.................... // Inicializace casovace
.................... if (Note!=SOUND_Space) // Pokud se ma hrat spust hrani
*
00E2: MOVF 69,W
00E3: SUBLW 0C
00E4: BTFSC 03.2
00E5: GOTO 109
.................... {
.................... setup_ccp1(CCP_COMPARE_RESET_TIMER);
00E6: MOVLW 0B
00E7: MOVWF 17
.................... set_timer1(0);
00E8: CLRF 0F
00E9: CLRF 0E
.................... (int16)CCP_1=Table[Note]>>Octave;
00EA: BCF 03.0
00EB: RLF 69,W
00EC: MOVWF 77
00ED: MOVWF 6F
00EE: INCF 6F,W
00EF: CALL 035
00F0: MOVWF 7A
00F1: MOVF 6F,W
00F2: CALL 035
00F3: MOVWF 70
00F4: MOVF 7A,W
00F5: MOVWF 71
00F6: MOVWF 16
00F7: MOVF 70,W
00F8: MOVWF 15
00F9: MOVF 6A,W
00FA: MOVWF 77
00FB: BTFSC 03.2
00FC: GOTO 102
00FD: BCF 03.0
00FE: RRF 16,F
00FF: RRF 15,F
0100: DECFSZ 77,F
0101: GOTO 0FD
.................... #if SOUND_PRESCALE==1
.................... setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
.................... #elif SOUND_PRESCALE==2
.................... setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
0102: MOVLW 95
0103: MOVWF 10
.................... #elif SOUND_PRESCALE==4
.................... setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
.................... #elif SOUND_PRESCALE==8
.................... setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
.................... #endif
.................... enable_interrupts(int_ccp1);
0104: BSF 03.5
0105: BSF 0C.2
.................... enable_interrupts(global);
0106: MOVLW C0
0107: BCF 03.5
0108: IORWF 0B,F
.................... }
....................
.................... // Delka tonu merena casovacem T0 (bez preruseni)
.................... Time=0;
0109: CLRF 6E
010A: CLRF 6D
.................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
010B: BSF 03.5
010C: MOVF 01,W
010D: ANDLW C0
010E: IORLW 08
010F: MOVWF 01
.................... while (Duration)
0110: BCF 03.5
0111: MOVF 6B,W
0112: IORWF 6C,W
0113: BTFSC 03.2
0114: GOTO 132
.................... {
.................... if (T0IF) // Preteceni T0 - kazdych (1/CLK)*4*256
0115: BTFSS 0B.2
0116: GOTO 11C
.................... {
.................... T0IF = 0;
0117: BCF 0B.2
.................... Time += (256*4*1000*2048+SOUND_CLOCK/2)/SOUND_CLOCK;
0118: MOVLW 69
0119: ADDWF 6D,F
011A: BTFSC 03.0
011B: INCF 6E,F
.................... }
.................... if (Time>>11)
011C: CLRF 7A
011D: RRF 6E,W
011E: MOVWF 79
011F: RRF 79,F
0120: RRF 79,F
0121: MOVLW 1F
0122: ANDWF 79,F
0123: MOVF 79,W
0124: IORWF 7A,W
0125: BTFSC 03.2
0126: GOTO 131
.................... {
.................... Time -= 2048;
0127: MOVLW 00
0128: SUBWF 6D,F
0129: MOVLW 08
012A: BTFSS 03.0
012B: MOVLW 09
012C: SUBWF 6E,F
.................... Duration--;
012D: MOVF 6B,W
012E: BTFSC 03.2
012F: DECF 6C,F
0130: DECF 6B,F
.................... }
.................... }
0131: GOTO 111
....................
.................... // Konec casovace
.................... disable_interrupts(int_ccp1);
0132: BSF 03.5
0133: BCF 0C.2
.................... disable_interrupts(global);
0134: BCF 03.5
0135: BCF 0B.6
0136: BCF 0B.7
0137: BTFSC 0B.7
0138: GOTO 136
0139: RETLW 00
.................... }
....................
....................
.................... #include "Data.c" // Datovy blok pro predpripravene skladby
.................... // Tento soubor definuje vse potrebne pro ulozeni skladeb do pameti programu.
.................... // Dale definuje pislusna makra pro snadne definice. Tyto definice jsou voleny
.................... // zamerne tak, aby mohl byt pouzit stejny soubor s definici skladby jak
.................... // pro vlozeni primo do firmwaru v dobe prekladu tak i k dodatecnemu nahrani
.................... // skladby pres seriovou linku.
....................
.................... // Definice hranic pameti pro ulozeni pisnicek
.................... #define STARTMEM 0x600 // Zde zacina pametoa oblast pro pisnicky
.................... #define ENDMEM 0x7ff // Zde konci pametova oblast pro pisnicky
....................
.................... // Definice konstant pro kodovani dat
.................... #define ENDOFDATA 0x3FFF // Priznak konce pisnicek (prazdna pamet)
.................... #define DATABEGIN 0x2000 // Kod zacatku skladby
.................... #define MASKBEGIN 0x3800
.................... #define DATATEMPO 0x2800 // Kod pro nastaveni tempa
.................... #define MASKTEMPO 0x3800
.................... #define DATAPAUSE 0x3000 // Kod pro nastaveni mezery mezi notami
.................... #define MASKPAUSE 0x3800
.................... #define MASKNOTE 0x2000 // Nejvissi bit 0 urcuje, ze jde o notu
....................
.................... // Pseudomakra pro jednoduchy zapis skladeb do zdrojaku jazyka C
.................... #define BEGIN DATABEGIN+ // Zacatek pisnicky + posunuti oktav
.................... #define TEMPO DATATEMPO+ // Delka nejskratsi noty v ms
.................... #define PAUSE DATAPAUSE+ // Delka mezery mezi notami
.................... #define END // Konec skladby, zde nic neznamena
....................
.................... // Pseudomakra pro zapis not, zapisuje se cislo oktavy, nota, delka noty
.................... #define C *16 + SOUND_C + 128 *
.................... #define Cis *16 + SOUND_Cis + 128 *
.................... #define D *16 + SOUND_D + 128 *
.................... #define Dis *16 + SOUND_Dis + 128 *
.................... #define E *16 + SOUND_E + 128 *
.................... #define F *16 + SOUND_F + 128 *
.................... #define Fis *16 + SOUND_Fis + 128 *
.................... #define G *16 + SOUND_G + 128 *
.................... #define Gis *16 + SOUND_Gis + 128 *
.................... #define A *16 + SOUND_A + 128 *
.................... #define Ais *16 + SOUND_Ais + 128 *
.................... #define H *16 + SOUND_H + 128 *
.................... #define Space SOUND_Space + 128 *
....................
.................... // Pametova oblast
.................... #ORG 0x600,0x7FF {} // Vyhrazeni oblasti pameti pro ulozeni pisnicek
.................... #ROM 0x600 = { // Naplneni oblasti pameti daty
....................
.................... // Pisnicky jako soucast firwaru se vkladaji sem
.................... // Museji mit stejny format jako uvedene priklady aby zafungovaly makra
.................... #include "Skladby\TheFinalSoundDown.txt"
.................... // Pisnicka "The Final Sound Down"
.................... //
.................... // Tato pisnicka je napsana ve formatu, ktery se da pouzit jak pro primy
.................... // preklad do firmwaru melodickeho zvonku tak i pro dodatecne nahrani
....................
.................... BEGIN 3, // Zacatek skladby
.................... TEMPO 100, // Delka nejkratsi noty v ms
.................... PAUSE 100, // Delka mezery mezi notami
....................
.................... 1 A 1,
.................... 1 G 1,
.................... 1 A 4,
.................... 1 D 4,
.................... Space 2,
....................
.................... 1 Ais 1,
.................... 1 A 1,
.................... 1 Ais 2,
.................... 1 A 2,
.................... 1 G 4,
.................... Space 2,
....................
.................... 1 Ais 1,
.................... 1 A 1,
.................... 1 Ais 4,
.................... 1 D 4,
.................... Space 2,
....................
.................... 1 G 1,
.................... 1 F 1,
.................... 1 G 2,
.................... 1 F 2,
.................... 1 E 2,
.................... 1 G 2,
.................... 1 F 4,
.................... Space 2,
....................
.................... 1 E 1,
.................... 1 F 1,
.................... 1 G 4,
.................... Space 2,
....................
.................... 1 F 1,
.................... 1 G 1,
.................... 1 A 2,
.................... 1 G 2,
.................... 1 F 2,
.................... 1 E 2,
.................... 1 D 4,
.................... 1 Ais 4,
.................... 1 A 4,
.................... Space 2,
....................
.................... 1 A 1,
.................... 1 Ais 1,
.................... 1 A 1,
.................... 1 G 1,
.................... 1 A 4,
.................... Space 2,
....................
.................... END
....................
.................... #include "Skladby\BednaOdWhisky.txt"
.................... // Pisnicka "Bedna od Whisky"
.................... //
.................... // Tato pisnicka je napsana ve formatu, ktery se da pouzit jak pro primy
.................... // preklad do firmwaru melodickeho zvonku tak i pro dodatecne nahrani
....................
.................... BEGIN 2, // Zacatek skladby
.................... TEMPO 100, // Delka nejkratsi noty v ms
.................... PAUSE 100, // Delka mezery mezi notami
....................
.................... 1 A 2,
.................... 2 C 2,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 G 4,
.................... 2 E 2,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 G 2,
.................... 2 E 2,
.................... 2 D 2,
.................... 2 E 4,
.................... Space 4,
.................... 1 A 2,
.................... 2 C 2,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 G 2,
.................... 2 G 2,
.................... 2 E 2,
.................... 2 E 2,
.................... 1 A 2,
.................... 2 E 2,
.................... 1 H 2,
.................... 2 E 2,
.................... 1 A 4,
.................... Space 4,
.................... 1 A 2,
.................... 2 C 2,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 G 2,
.................... 2 G 2,
.................... 2 E 4,
.................... 2 A 2,
.................... 2 G 2,
.................... 2 E 2,
.................... 2 D 2,
.................... 2 E 4,
.................... Space 2,
.................... 2 E 2,
.................... 1 A 2,
.................... 2 C 2,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 G 2,
.................... 2 E 4,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 GIS 2,
.................... 2 H 2,
.................... 2 A 4,
.................... Space 8,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 GIS 2,
.................... 2 FIS 2,
.................... 2 A 4,
.................... 2 A 2,
.................... 2 H 2,
.................... 2 H 2,
.................... 2 A 2,
.................... 2 H 2,
.................... 3 CIS 2,
.................... 2 A 4,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 GIS 2,
.................... 2 FIS 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 H 2,
.................... 2 H 2,
.................... 2 A 2,
.................... 2 GIS 2,
.................... 2 A 4,
.................... Space 2,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 GIS 2,
.................... 2 FIS 2,
.................... 2 A 4,
.................... 2 A 2,
.................... 2 H 2,
.................... 2 H 2,
.................... 2 A 2,
.................... 2 H 2,
.................... 3 CIS 2,
.................... 2 A 4,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 GIS 2,
.................... 2 FIS 2,
.................... 2 A 2,
.................... Space 2,
.................... 2 A 2,
.................... 2 H 2,
.................... 2 H 2,
.................... 2 A 2,
.................... 2 GIS 2,
.................... 2 A 8,
.................... 2 G 2,
.................... 2 A 8,
.................... 2 G 2,
.................... 2 A 8,
....................
.................... END
....................
.................... #include "Skladby\KdyzMeBaliZaVojacka.txt"
.................... // Pisnicka "Kdyz me brali za vojacka"
.................... //
.................... // Tato pisnicka je napsana ve formatu, ktery se da pouzit jak pro primy
.................... // preklad do firmwaru melodickeho zvonku tak i pro dodatecne nahrani
....................
.................... BEGIN 2, // Zacatek skladby
.................... TEMPO 150, // Delka nejkratsi noty v ms
.................... PAUSE 100, // Delka mezery mezi notami
....................
.................... 1 A 1,
.................... 2 C 1,
.................... 2 E 1,
.................... 2 D 1,
.................... 2 C 1,
.................... 1 H 1,
.................... 2 C 2,
.................... 2 D 1,
.................... 2 E 2,
.................... 2 D 1,
.................... 2 G 1,
.................... 2 G 1,
.................... 2 G 1,
.................... 2 G 1,
.................... 2 A 1,
.................... 2 E 2,
.................... Space 4,
.................... 2 D 1,
.................... 2 F 1,
.................... 2 A 1,
.................... 2 G 1,
.................... 2 F 1,
.................... 2 E 1,
.................... 2 E 1,
.................... 2 F 1,
.................... 2 E 1,
.................... 2 C 1,
.................... 1 A 2,
.................... 1 GIS 1,
.................... 1 H 1,
.................... 2 E 1,
.................... 2 D 1,
.................... 1 H 1,
.................... 2 C 1,
.................... 1 A 2,
.................... Space 2,
.................... 1 H 2,
.................... 2 C 2,
.................... Space 2,
.................... 2 D 2,
.................... 2 E 1,
.................... 2 E 1,
.................... 2 E 1,
.................... 2 D 1,
.................... 1 H 1,
.................... 2 C 1,
.................... 1 A 2,
....................
.................... END
....................
.................... #include "Skladby\Medvedi.txt"
.................... // Pisnicka "Medvedi"
.................... //
.................... // Tato pisnicka je napsana ve formatu, ktery se da pouzit jak pro primy
.................... // preklad do firmwaru melodickeho zvonku tak i pro dodatecne nahrani
....................
.................... BEGIN 1, // Zacatek skladby
.................... TEMPO 150, // Delka nejkratsi noty v ms
.................... PAUSE 100, // Delka mezery mezi notami
....................
.................... 1 C 1, // 1
.................... 1 C 1,
.................... 1 C 1,
.................... 1 E 1,
.................... 1 D 1,
.................... 0 G 1,
....................
.................... 1 C 3, // 2
.................... Space 4,
....................
.................... 1 E 1, // 3
.................... 1 E 1,
.................... 1 E 1,
.................... 1 E 1,
.................... 1 D 1,
.................... 1 G 1,
....................
.................... 1 E 2, // 4
.................... Space 4,
....................
.................... 1 G 1, // 5
.................... 1 G 1,
.................... 1 A 1,
.................... 1 G 1,
.................... 1 F 1,
.................... 1 E 1,
....................
.................... 1 F 1, // 6
.................... 1 A 1,
.................... 1 G 1,
.................... 1 F 1,
.................... 1 E 1,
.................... 1 D 1,
....................
.................... 1 C 1, // 7
.................... 0 H 1,
.................... 1 C 1,
.................... 1 E 1,
.................... 1 D 1,
.................... 0 G 1,
....................
.................... 1 C 3, // 8
.................... Space 4,
.................... 1 A 1, // 9
.................... 1 A 1,
.................... 1 A 1,
.................... 1 A 1,
.................... 1 H 1,
.................... 2 D 1,
....................
.................... 2 C 4, // 10
.................... Space 2,
....................
.................... 2 E 1, // 11
.................... 2 E 1,
.................... 2 E 1,
.................... 2 E 1,
.................... 2 D 1,
.................... 2 G 1,
....................
.................... 2 E 4, // 12
.................... Space 2,
....................
.................... 2 G 1, // 13
.................... 2 G 1,
.................... 2 A 1,
.................... 2 G 1,
.................... 2 F 1,
.................... 2 E 1,
....................
.................... 2 F 1, // 14
.................... 2 A 1,
.................... 2 G 1,
.................... 2 F 1,
.................... 2 E 1,
.................... 2 D 1,
....................
.................... 2 C 1, // 15
.................... 1 H 1,
.................... 2 C 1,
.................... 2 E 1,
.................... 2 D 1,
.................... 1 G 1,
....................
.................... 2 C 4, // 16
.................... Space 2,
....................
.................... 1 C 6, // 1
.................... 0 G 2,
....................
.................... 1 D 3, // 2
.................... Space 3,
....................
.................... 1 G 1, // 3
.................... 1 G 1,
.................... 1 Fis 1,
.................... 1 G 1,
.................... 1 A 1,
.................... 1 Fis 1,
....................
.................... 1 G 2, // 4
.................... Space 4,
....................
.................... 1 G 1, // 5
.................... 1 G 1,
.................... 1 A 1,
.................... 1 G 1,
.................... 1 F 1,
.................... 1 E 1,
....................
.................... 1 F 1, // 6
.................... 1 A 1,
.................... 1 G 1,
.................... 1 F 1,
.................... 1 E 1,
.................... 1 D 1,
....................
.................... 1 C 6, // 7
.................... 1 E 2,
....................
.................... 1 D 3, // 8
.................... Space 3,
....................
.................... 1 C 6, // 9
.................... 0 G 2,
....................
.................... 1 D 3, // 10
.................... Space 3,
....................
.................... 1 G 1, // 11
.................... 1 G 1,
.................... 1 Fis 1,
.................... 1 G 1,
.................... 1 A 1,
.................... 1 Fis 1,
....................
.................... 1 G 2, // 12
.................... Space 4,
....................
.................... 1 G 1, // 13
.................... 1 G 1,
.................... 1 A 1,
.................... 1 G 1,
.................... 1 F 1,
.................... 1 E 1,
....................
.................... 1 F 1, // 14
.................... 1 A 1,
.................... 1 G 1,
.................... 1 F 1,
.................... 1 E 1,
.................... 1 D 1,
....................
.................... 1 C 1, // 15
.................... 0 H 1,
.................... 1 C 1,
.................... 1 E 1,
.................... 1 D 1,
.................... 0 G 1,
....................
.................... 1 C 2, // 16
.................... Space 4,
....................
.................... END
....................
....................
.................... // Koncova znacka a konec oblasti pro skladby
.................... ENDOFDATA
.................... }
....................
.................... // Zruseni definic maker pro definici skladeb
.................... // V dalsim programu uz nebudou potreba
.................... #undef BEGIN
.................... #undef TEMPO
.................... #undef PAUSE
.................... #undef END
.................... #undef C
.................... #undef Cis
.................... #undef D
.................... #undef Dis
.................... #undef E
.................... #undef F
.................... #undef Fis
.................... #undef G
.................... #undef Gis
.................... #undef A
.................... #undef Ais
.................... #undef H
.................... #undef Space
....................
....................
.................... #define RXD PIN_B1 // Port pro RS232
.................... #use delay(CLOCK=20000000) // Konfigurace pro casovani RS232
.................... #use rs232(BAUD=9600,RCV=RXD,INVERT,PARITY=N,BITS=8) // Prenosove parametry RS232
*
0152: MOVLW 08
0153: MOVWF 77
0154: BSF 03.5
0155: BSF 06.1
0156: BCF 03.5
0157: BTFSS 06.1
0158: GOTO 157
0159: CLRF 61
015A: BSF 77.7
015B: GOTO 16A
015C: BCF 77.7
015D: GOTO 16A
015E: BCF 03.0
015F: BTFSS 06.1
0160: BSF 03.0
0161: RRF 61,F
0162: BSF 77.6
0163: GOTO 16A
0164: BCF 77.6
0165: DECFSZ 77,F
0166: GOTO 15E
0167: MOVF 61,W
0168: MOVWF 78
0169: GOTO 176
016A: MOVLW A7
016B: BTFSC 77.7
016C: MOVLW 2D
016D: MOVWF 78
016E: DECFSZ 78,F
016F: GOTO 16E
0170: NOP
0171: BTFSC 77.7
0172: GOTO 15C
0173: BTFSC 77.6
0174: GOTO 164
0175: GOTO 15E
0176: RETLW 00
....................
....................
.................... // Sada globalnich promennych
.................... // --------------------------
.................... // Vyuzivame globalni promenne protoze je to vyhodne z hlediska spotreby zdroju. Usetri
.................... // se vyznmane mnoho pameti programu pri predavani parametru
....................
....................
.................... unsigned int16 Adr; // Adresovy ukazatel do pameti skladeb
.................... unsigned int16 Data; // Prectena data nebo data pro zapis
.................... unsigned int1 Mode; // 0=rezim testovani, 1=rezim zapisu do FLASH
....................
.................... unsigned int16 Tempo; // Tempo (delka nejkratsi skladby v ms)
.................... unsigned int16 Pause; // Delka mezery mezi notami v ms
.................... unsigned int8 Octava; // Posunuti skladby v oktavach
....................
.................... unsigned int8 Beep; // Druh pipnuti pro proceduru SoundSpec
.................... unsigned int1 Error; // Priznak chyby
....................
.................... unsigned int8 CisloSkladby; // Cislo skladby pro proceduru Find a Play
....................
....................
.................... // Zvuky, posloupnost zadaneho poctu tonu
.................... #define SoundEndOfLine 0x01 // Kratke pipnuti na konci radky
.................... #define SoundPGM 0x03 // Trilek pri vstupu do rezimu programovani
.................... #define SoundPostPlay 0x03 // Po ukonceni prehravani
.................... #define SoundERASE 0x02 // Zvuk pri smazani bloku FLASH pameti
.................... #define SoundERR 0x05 // Chyba syntaxe
.................... void SpecBeep()
.................... // Data - pocet pipnuti, 0 znamena ticho
.................... {
.................... int Oct;
....................
.................... if (Error) Beep=SoundERR;
*
013A: BTFSS 2D.1
013B: GOTO 13E
013C: MOVLW 05
013D: MOVWF 33
....................
.................... for(Oct=2;Beep!=0;Beep--)
013E: MOVLW 02
013F: MOVWF 61
0140: MOVF 33,F
0141: BTFSC 03.2
0142: GOTO 150
.................... {
.................... SoundNote(SOUND_A,Oct++,50);
0143: MOVF 61,W
0144: INCF 61,F
0145: MOVWF 62
0146: MOVLW 09
0147: MOVWF 69
0148: MOVF 62,W
0149: MOVWF 6A
014A: CLRF 6C
014B: MOVLW 32
014C: MOVWF 6B
014D: CALL 0E2
.................... }
014E: DECF 33,F
014F: GOTO 140
....................
.................... Error=0;
0150: BCF 2D.1
0151: RETLW 00
.................... }
....................
....................
.................... // Precti slovo z pameti programu
.................... int16 ReadData()
.................... // Adr - adresa ze ktere se cte
.................... // Data - prectena data
.................... {
.................... int8 a,b; // Pomocne promenne
....................
.................... (int8)*EEADR = Adr; // Adresa, spodni cast
*
01EB: MOVF 29,W
01EC: BSF 03.6
01ED: MOVWF 0D
.................... (int8)*EEADRH = Adr >> 8; // Adresa, horni cast
01EE: BCF 03.6
01EF: MOVF 2A,W
01F0: BSF 03.6
01F1: MOVWF 0F
.................... bit_set(*EECON1,EECON1_EEPGD); // Pamet programu
01F2: BSF 03.5
01F3: BSF 0C.7
.................... bit_set(*EECON1,EECON1_RD); // Operace cteni
01F4: BSF 0C.0
.................... #ASM
.................... nop; // Povinne nop
01F5: NOP
.................... nop;
.................... #ENDASM
01F6: NOP
.................... a = (int8)*EEDATA; // Prevezmi data
01F7: BCF 03.5
01F8: MOVF 0C,W
01F9: BCF 03.6
01FA: MOVWF 61
.................... b = (int8)*EEDATAH;
01FB: BSF 03.6
01FC: MOVF 0E,W
01FD: BCF 03.6
01FE: MOVWF 62
.................... Data=make16(b,a); // Sestav vysledek ze 2 bajtu
01FF: MOVF 62,W
0200: MOVWF 2C
0201: MOVF 61,W
0202: MOVWF 2B
0203: RETLW 00
.................... }
....................
....................
.................... // Smazani cele pameti vyhrazene pro skladby
.................... void Erase()
.................... {
.................... for(Adr=STARTMEM; Adr<=ENDMEM; Adr++) // Cela oblast
*
047D: MOVLW 06
047E: MOVWF 2A
047F: CLRF 29
0480: MOVF 2A,W
0481: SUBLW 07
0482: BTFSS 03.0
0483: GOTO 4B3
.................... {
.................... ReadData();
0484: CALL 1EB
.................... if (Data!=0x3FFF) // Mazu jen bloky, ktere to potrebuji
0485: INCFSZ 2B,W
0486: GOTO 48B
0487: MOVF 2C,W
0488: SUBLW 3F
0489: BTFSC 03.2
048A: GOTO 4AF
.................... {
.................... if (input(POWER_PIC)!=0) return; // Nezapisuj pokud neni jumper povoleni programovani
048B: BSF 03.5
048C: BSF 05.3
048D: MOVLW 00
048E: BCF 03.5
048F: BTFSC 05.3
0490: MOVLW 01
0491: XORLW 00
0492: BTFSC 03.2
0493: GOTO 495
0494: GOTO 4B3
.................... (int8)*EEADR = Adr; // Adresa bloku, spodni cast
0495: MOVF 29,W
0496: BSF 03.6
0497: MOVWF 0D
.................... (int8)*EEADRH = Adr >> 8; // Adresa bloku, horni cast
0498: BCF 03.6
0499: MOVF 2A,W
049A: BSF 03.6
049B: MOVWF 0F
.................... bit_set(*EECON1,EECON1_EEPGD); // Pamet programu
049C: BSF 03.5
049D: BSF 0C.7
.................... bit_set(*EECON1,EECON1_WREN); // Povolit zapis
049E: BSF 0C.2
.................... bit_set(*EECON1,EECON1_FREE); // Operace mazani
049F: BSF 0C.4
.................... (int8)*EECON2 = 0x55; // Povinna segvence pro zapis
04A0: MOVLW 55
04A1: MOVWF 0D
.................... (int8)*EECON2 = 0xAA;
04A2: MOVLW AA
04A3: MOVWF 0D
.................... bit_set(*EECON1,EECON1_WR); // Zahajeni mazani
04A4: BSF 0C.1
.................... #ASM
.................... nop; // Povinne prazdne instrukce
04A5: NOP
.................... nop;
.................... #ENDASM
04A6: NOP
.................... bit_clear(*EECON1,EECON1_WREN); // Uz ne zapis
04A7: BCF 0C.2
.................... bit_clear(*EECON1,EECON1_FREE); // Uz ne mazani
04A8: BCF 0C.4
.................... bit_clear(*EECON1,EECON1_EEPGD); // Uz ne pamet programu
04A9: BCF 0C.7
.................... Beep=SoundERASE;
04AA: MOVLW 02
04AB: BCF 03.5
04AC: BCF 03.6
04AD: MOVWF 33
.................... SpecBeep();
04AE: CALL 13A
.................... }
.................... }
04AF: INCF 29,F
04B0: BTFSC 03.2
04B1: INCF 2A,F
04B2: GOTO 480
.................... }
....................
....................
.................... // Zapis do pameti programu po jednotlivych slovech.
.................... // Soucastka vyzaduje zapis vzdy celych osmi slov najednou. Vyuziva se toho, ze pamet FLASH
.................... // umi zapisovat jen smerem do nuly a tak staci na pozice, ktere zrovna nechceme programovat
.................... // zapsat same jednicky cimz se stav jejich stav nezmeni.
.................... void WriteData()
.................... // Adr - adresa, kam se bude zapisovat
.................... // Data - data, ktera se budou zapisovat
.................... {
.................... int i;
....................
.................... bit_set(*EECON1,EECON1_EEPGD); // Pamet programu
*
0300: BSF 03.5
0301: BSF 03.6
0302: BSF 0C.7
.................... bit_set(*EECON1,EECON1_WREN); // Zapis
0303: BSF 0C.2
.................... (int8)*EEADR = Adr & ~3; // Adresa, spodni cast, zaokrouhleno dolu na nasobek 8
0304: BCF 03.5
0305: BCF 03.6
0306: MOVF 29,W
0307: ANDLW FC
0308: BSF 03.6
0309: MOVWF 0D
.................... (int8)*EEADRH = Adr >> 8; // Adresa, horni cast
030A: BCF 03.6
030B: MOVF 2A,W
030C: BSF 03.6
030D: MOVWF 0F
.................... for (i=0; i<4; i++)
030E: BCF 03.6
030F: CLRF 61
0310: MOVF 61,W
0311: SUBLW 03
0312: BTFSS 03.0
0313: GOTO 33B
.................... {
.................... if ((Adr & 3) == i) // Pokud je adresa slova v bloku totozna s pozadovanou
0314: MOVF 29,W
0315: ANDLW 03
0316: MOVWF 62
0317: MOVF 2A,W
0318: ANDLW 00
0319: MOVWF 63
031A: MOVF 61,W
031B: SUBWF 62,W
031C: BTFSS 03.2
031D: GOTO 32A
031E: MOVF 63,F
031F: BTFSS 03.2
0320: GOTO 32A
.................... {
.................... (int8)*EEDATA =Data; // Platne slovo, spodni cast
0321: MOVF 2B,W
0322: BSF 03.6
0323: MOVWF 0C
.................... (int8)*EEDATAH=Data >> 8; // Platne slovo, horni cast
0324: BCF 03.6
0325: MOVF 2C,W
0326: BSF 03.6
0327: MOVWF 0E
.................... }
.................... else // Ostatni bunky nemenime
0328: GOTO 32E
0329: BCF 03.6
.................... {
.................... (int8)*EEDATA =0xFF; // Zbytek same jednicky
032A: MOVLW FF
032B: BSF 03.6
032C: MOVWF 0C
.................... (int8)*EEDATAH=0xFF;
032D: MOVWF 0E
.................... }
.................... (int8)*EECON2 = 0x55; // Povinna sekvence pro zapis
032E: MOVLW 55
032F: BSF 03.5
0330: MOVWF 0D
.................... (int8)*EECON2 = 0xAA;
0331: MOVLW AA
0332: MOVWF 0D
.................... bit_set(*EECON1,EECON1_WR); // Zahajeni zapisu
0333: BSF 0C.1
.................... #ASM
.................... nop; // Povinne dve prazdne instrukce
0334: NOP
.................... nop;
.................... #ENDASM
0335: NOP
.................... ((int8)*EEADR) ++; // Dalsi slovo
0336: BCF 03.5
0337: INCF 0D,F
.................... }
0338: BCF 03.6
0339: INCF 61,F
033A: GOTO 310
.................... bit_clear(*EECON1,EECON1_WREN); // Konec zapisu
033B: BSF 03.5
033C: BSF 03.6
033D: BCF 0C.2
.................... bit_clear(*EECON1,EECON1_EEPGD); // Uz ne pamet programu (bezpecnost)
033E: BCF 0C.7
.................... }
....................
....................
.................... // Zapise data Data na adresu Adr a provede posun na dalsi adresu, zapisuje se jen do
.................... // dovolene oblasti pameti a jen v pripade, ze je Mode=1
.................... void WriteDataInc()
.................... // Data - co se zapisuje
.................... // Adr - kam se zapisuje, po zapisu se adresa posouva
.................... {
.................... if (~Mode) return; // Neni rezim zapisu
*
02DC: BTFSC 2D.0
02DD: GOTO 2DF
02DE: GOTO 346
.................... if ( (Adr>=STARTMEM) & (Adr<=ENDMEM) & (input(POWER_PIC)==0) )
02DF: MOVF 2A,W
02E0: SUBLW 05
02E1: BTFSS 03.0
02E2: GOTO 2E5
02E3: MOVLW 00
02E4: GOTO 2E6
02E5: MOVLW 01
02E6: MOVWF 61
02E7: MOVF 2A,W
02E8: SUBLW 07
02E9: BTFSC 03.0
02EA: GOTO 2ED
02EB: MOVLW 00
02EC: GOTO 2EE
02ED: MOVLW 01
02EE: ANDWF 61,W
02EF: MOVWF 62
02F0: BSF 03.5
02F1: BSF 05.3
02F2: MOVLW 00
02F3: BCF 03.5
02F4: BTFSC 05.3
02F5: MOVLW 01
02F6: XORLW 00
02F7: BTFSC 03.2
02F8: GOTO 2FB
02F9: MOVLW 00
02FA: GOTO 2FC
02FB: MOVLW 01
02FC: ANDWF 62,W
02FD: XORLW 00
02FE: BTFSC 03.2
02FF: GOTO 345
.................... {
.................... WriteData();
.................... Adr++;
*
033F: BCF 03.5
0340: BCF 03.6
0341: INCF 29,F
0342: BTFSC 03.2
0343: INCF 2A,F
.................... }
.................... else
0344: GOTO 346
.................... {
.................... Error=1;
0345: BSF 2D.1
.................... }
0346: RETLW 00
.................... }
....................
....................
.................... // Najdi zacatek zadaneho cisla skladby. Promenna Adr ukazuje na zacatek skladby.
.................... // Neni-li skladba nalezena ukazuje Adr na koncovou znacku (0x3FFF) posledni skladby
.................... // nebo na konec pameti.
.................... int1 Find()
.................... // CisloSkladby - poradove cislo skladby
.................... // Adr - adresa zacatku skladby
.................... {
.................... Adr=STARTMEM-1; // Od zacatku oblasti pro skladby
*
0204: MOVLW 05
0205: MOVWF 2A
0206: MOVLW FF
0207: MOVWF 29
.................... for(;1;)
.................... {
.................... Adr++;
0208: INCF 29,F
0209: BTFSC 03.2
020A: INCF 2A,F
.................... ReadData(); // Precti data
020B: CALL 1EB
.................... if (Data==ENDOFDATA) return 1; // Priznak konce dat
020C: INCFSZ 2B,W
020D: GOTO 215
020E: MOVF 2C,W
020F: SUBLW 3F
0210: BTFSS 03.2
0211: GOTO 215
0212: MOVLW 01
0213: MOVWF 78
0214: GOTO 232
.................... if (Adr==ENDMEM+1) return 1; // Uz jsme prosli celou pamet
0215: MOVF 29,F
0216: BTFSS 03.2
0217: GOTO 21F
0218: MOVF 2A,W
0219: SUBLW 08
021A: BTFSS 03.2
021B: GOTO 21F
021C: MOVLW 01
021D: MOVWF 78
021E: GOTO 232
.................... if ((Data&MASKBEGIN)==DATABEGIN) // Priznak zacatku skladby
021F: MOVF 2B,W
0220: ANDLW 00
0221: MOVWF 61
0222: MOVF 2C,W
0223: ANDLW 38
0224: MOVWF 62
0225: MOVF 61,F
0226: BTFSS 03.2
0227: GOTO 231
0228: MOVF 62,W
0229: SUBLW 20
022A: BTFSS 03.2
022B: GOTO 231
.................... {
.................... CisloSkladby--; // Otestuj pocitadlo skladeb
022C: DECFSZ 34,F
.................... if (CisloSkladby==0) return 0; // Je to tato skladba
022D: GOTO 231
022E: MOVLW 00
022F: MOVWF 78
0230: GOTO 232
.................... }
.................... }
0231: GOTO 208
0232: RETLW 00
.................... }
....................
....................
.................... // Zahraj jednu notu
.................... void PlayData()
.................... // Data = zakodovana nota
.................... // Tempo, Octava, Pause = parametry hrane noty
.................... {
.................... SoundNote((int8)Data&0xF,Octava+(((int8)Data>>4)&0x7),Tempo*((Data>>7)&0x3F)); // Zahraj notu
0233: MOVF 2B,W
0234: ANDLW 0F
0235: MOVWF 61
0236: SWAPF 2B,W
0237: MOVWF 77
0238: MOVLW 0F
0239: ANDWF 77,F
023A: MOVF 77,W
023B: ANDLW 07
023C: ADDWF 32,W
023D: MOVWF 63
023E: RRF 2C,W
023F: MOVWF 65
0240: RRF 2B,W
0241: MOVWF 64
0242: RRF 65,F
0243: RRF 64,F
0244: RRF 65,F
0245: RRF 64,F
0246: RRF 65,F
0247: RRF 64,F
0248: RRF 65,F
0249: RRF 64,F
024A: RRF 65,F
024B: RRF 64,F
024C: RRF 65,F
024D: RRF 64,F
024E: MOVLW 01
024F: ANDWF 65,F
0250: MOVF 64,W
0251: ANDLW 3F
0252: MOVWF 77
0253: MOVF 65,W
0254: ANDLW 00
0255: MOVWF 7A
0256: MOVF 77,W
0257: MOVWF 66
0258: MOVF 7A,W
0259: MOVWF 67
025A: MOVF 2F,W
025B: MOVWF 69
025C: MOVF 2E,W
025D: MOVWF 68
025E: MOVF 7A,W
025F: MOVWF 6B
0260: MOVF 77,W
0261: MOVWF 6A
0262: CALL 177
0263: MOVF 79,W
0264: MOVWF 68
0265: MOVF 78,W
0266: MOVWF 67
0267: MOVF 61,W
0268: MOVWF 69
0269: MOVF 63,W
026A: MOVWF 6A
026B: MOVF 79,W
026C: MOVWF 6C
026D: MOVF 78,W
026E: MOVWF 6B
026F: CALL 0E2
.................... SoundNote(SOUND_Space,0,Pause); // Zahraj mezeru mezi notami
0270: MOVLW 0C
0271: MOVWF 69
0272: CLRF 6A
0273: MOVF 31,W
0274: MOVWF 6C
0275: MOVF 30,W
0276: MOVWF 6B
0277: CALL 0E2
0278: RETLW 00
.................... }
....................
....................
.................... // Zahraj skladbu od zadane adresy v promenne Adr.
.................... void Play()
.................... // CisloSkladby - cislo skladby k hrani
.................... {
.................... if (Find()) // Najdi zacatek skladby v pameti skladeb
0279: CALL 204
027A: MOVF 78,F
027B: BTFSC 03.2
027C: GOTO 27E
.................... {
.................... return; // Skladba nenalezena
027D: GOTO 2DB
.................... }
....................
.................... Tempo=100; // Default delka noty
027E: CLRF 2F
027F: MOVLW 64
0280: MOVWF 2E
.................... Pause=100; // Default mezera mezi notami
0281: CLRF 31
0282: MOVWF 30
....................
.................... Octava=Data&~MASKBEGIN; // Posunuti oktav (povinna soucast zacatku skladby)
0283: MOVF 2B,W
0284: MOVWF 32
.................... Adr++;
0285: INCF 29,F
0286: BTFSC 03.2
0287: INCF 2A,F
....................
.................... for (;1;)
.................... {
.................... if (Adr==ENDMEM+1) return; // Konec pametove oblasti
0288: MOVF 29,F
0289: BTFSS 03.2
028A: GOTO 290
028B: MOVF 2A,W
028C: SUBLW 08
028D: BTFSS 03.2
028E: GOTO 290
028F: GOTO 2DB
.................... ReadData(); // Vezmi data
0290: CALL 1EB
.................... Adr++; // Posun adresu
0291: INCF 29,F
0292: BTFSC 03.2
0293: INCF 2A,F
.................... if (Data==ENDOFDATA) return; // Konec dat
0294: INCFSZ 2B,W
0295: GOTO 29B
0296: MOVF 2C,W
0297: SUBLW 3F
0298: BTFSS 03.2
0299: GOTO 29B
029A: GOTO 2DB
.................... if ((Data&MASKBEGIN)==DATABEGIN) return; // Zacatek dalsi skladby
029B: MOVF 2B,W
029C: ANDLW 00
029D: MOVWF 61
029E: MOVF 2C,W
029F: ANDLW 38
02A0: MOVWF 62
02A1: MOVF 61,F
02A2: BTFSS 03.2
02A3: GOTO 2A9
02A4: MOVF 62,W
02A5: SUBLW 20
02A6: BTFSS 03.2
02A7: GOTO 2A9
02A8: GOTO 2DB
.................... if ((Data&MASKTEMPO)==DATATEMPO) Tempo=Data&~DATATEMPO; // Paramter TEMPO
02A9: MOVF 2B,W
02AA: ANDLW 00
02AB: MOVWF 61
02AC: MOVF 2C,W
02AD: ANDLW 38
02AE: MOVWF 62
02AF: MOVF 61,F
02B0: BTFSS 03.2
02B1: GOTO 2BB
02B2: MOVF 62,W
02B3: SUBLW 28
02B4: BTFSS 03.2
02B5: GOTO 2BB
02B6: MOVF 2B,W
02B7: MOVWF 2E
02B8: MOVF 2C,W
02B9: ANDLW D7
02BA: MOVWF 2F
.................... if ((Data&MASKPAUSE)==DATAPAUSE) Pause=Data&~DATAPAUSE; // Parametr PAUSE
02BB: MOVF 2B,W
02BC: ANDLW 00
02BD: MOVWF 61
02BE: MOVF 2C,W
02BF: ANDLW 38
02C0: MOVWF 62
02C1: MOVF 61,F
02C2: BTFSS 03.2
02C3: GOTO 2CD
02C4: MOVF 62,W
02C5: SUBLW 30
02C6: BTFSS 03.2
02C7: GOTO 2CD
02C8: MOVF 2B,W
02C9: MOVWF 30
02CA: MOVF 2C,W
02CB: ANDLW CF
02CC: MOVWF 31
.................... if ((Data&MASKNOTE)==0) // Nota
02CD: MOVF 2B,W
02CE: ANDLW 00
02CF: MOVWF 61
02D0: MOVF 2C,W
02D1: ANDLW 20
02D2: MOVWF 62
02D3: MOVF 61,F
02D4: BTFSS 03.2
02D5: GOTO 2DA
02D6: MOVF 62,F
02D7: BTFSS 03.2
02D8: GOTO 2DA
.................... {
.................... PlayData(); // Zahraj notu
02D9: CALL 233
.................... }
.................... }
02DA: GOTO 288
02DB: RETLW 00
.................... }
....................
....................
.................... // Vycisli cislo z bufferu, posune ukazovatko na prvni nezpracovany znak, preskakuje mezery
.................... int16 Number(char line[], int *a, len)
.................... {
.................... int16 Data;
.................... char c;
....................
.................... while((line[*a]==' ')&(*a<len)) // Vynech mezery na zacatku
*
018C: MOVF 62,W
018D: MOVWF 04
018E: MOVF 61,W
018F: ADDWF 00,W
0190: MOVWF 04
0191: MOVF 00,W
0192: SUBLW 20
0193: BTFSC 03.2
0194: GOTO 197
0195: MOVLW 00
0196: GOTO 198
0197: MOVLW 01
0198: MOVWF 69
0199: MOVF 62,W
019A: MOVWF 04
019B: MOVF 63,W
019C: SUBWF 00,W
019D: BTFSS 03.0
019E: GOTO 1A1
019F: MOVLW 00
01A0: GOTO 1A2
01A1: MOVLW 01
01A2: ANDWF 69,W
01A3: XORLW 00
01A4: BTFSC 03.2
01A5: GOTO 1AA
.................... (*a)++; // Posouvej ukazovatko
01A6: MOVF 62,W
01A7: MOVWF 04
01A8: INCF 00,F
01A9: GOTO 18C
....................
.................... Data=0;
01AA: CLRF 65
01AB: CLRF 64
.................... while (1)
.................... {
.................... if (*a>=len) return Data; // Konec retezce
01AC: MOVF 62,W
01AD: MOVWF 04
01AE: MOVF 63,W
01AF: SUBWF 00,W
01B0: BTFSS 03.0
01B1: GOTO 1B7
01B2: MOVF 64,W
01B3: MOVWF 78
01B4: MOVF 65,W
01B5: MOVWF 79
01B6: GOTO 1EA
.................... c=line[*a]; // Vezmi znak z pole
01B7: MOVF 62,W
01B8: MOVWF 04
01B9: MOVF 61,W
01BA: ADDWF 00,W
01BB: MOVWF 04
01BC: MOVF 00,W
01BD: MOVWF 66
.................... if ((c<'0')|(c>'9')) return Data; // Koncime pokud znak neni cislice
01BE: MOVF 66,W
01BF: SUBLW 2F
01C0: BTFSC 03.0
01C1: GOTO 1C4
01C2: MOVLW 00
01C3: GOTO 1C5
01C4: MOVLW 01
01C5: MOVWF 67
01C6: MOVF 66,W
01C7: SUBLW 39
01C8: BTFSS 03.0
01C9: GOTO 1CC
01CA: MOVLW 00
01CB: GOTO 1CD
01CC: MOVLW 01
01CD: IORWF 67,W
01CE: XORLW 00
01CF: BTFSC 03.2
01D0: GOTO 1D6
01D1: MOVF 64,W
01D2: MOVWF 78
01D3: MOVF 65,W
01D4: MOVWF 79
01D5: GOTO 1EA
.................... Data = Data * 10 + (c-'0'); // Pouzij cislici
01D6: MOVF 65,W
01D7: MOVWF 69
01D8: MOVF 64,W
01D9: MOVWF 68
01DA: CLRF 6B
01DB: MOVLW 0A
01DC: MOVWF 6A
01DD: CALL 177
01DE: MOVLW 30
01DF: SUBWF 66,W
01E0: ADDWF 78,W
01E1: MOVWF 64
01E2: MOVF 79,W
01E3: MOVWF 65
01E4: BTFSC 03.0
01E5: INCF 65,F
.................... (*a)++; // Dalsi znak
01E6: MOVF 62,W
01E7: MOVWF 04
01E8: INCF 00,F
.................... }
01E9: GOTO 1AC
01EA: RETLW 00
.................... }
....................
....................
.................... // Vyhledej klicove slovo a vrat jeho zkraceny kod
.................... // Pokud slovo neexistuje vraci -1
.................... // Format definice - retezec ukonceny nulou + zastupny znak, na konci prazdny retezec (nula)
.................... const char KeyWords[] =
.................... {
.................... 'P','L','A','Y',0, 'P',
.................... 'E','R','A','S','E',0, 'E',
.................... 'T','E','M','P','O',0, 't',
.................... 'P','A','U','S','E',0, 'p',
.................... 'B','E','G','I','N',0, 'B',
.................... 'T','E','S','T',0, 'b',
.................... 'E','N','D',0, 'Z',
.................... 'C',0. SOUND_C,
.................... 'C','I','S',0, SOUND_Cis,
.................... 'D',0, SOUND_D,
.................... 'D','I','S',0, SOUND_Dis,
.................... 'E',0, SOUND_E,
.................... 'F',0, SOUND_F,
.................... 'F','I','S',0, SOUND_Fis,
.................... 'G',0, SOUND_G,
.................... 'G','I','S',0, SOUND_Gis,
.................... 'A',0, SOUND_A,
.................... 'A','I','S',0, SOUND_Ais,
.................... 'H',0, SOUND_H,
.................... 'S','P','A','C','E',0, SOUND_Space
.................... };
*
0051: BCF 0A.0
0052: BCF 0A.1
0053: BCF 0A.2
0054: ADDWF 02,F
0055: RETLW 50
0056: RETLW 4C
0057: RETLW 41
0058: RETLW 59
0059: RETLW 00
005A: RETLW 50
005B: RETLW 45
005C: RETLW 52
005D: RETLW 41
005E: RETLW 53
005F: RETLW 45
0060: RETLW 00
0061: RETLW 45
0062: RETLW 54
0063: RETLW 45
0064: RETLW 4D
0065: RETLW 50
0066: RETLW 4F
0067: RETLW 00
0068: RETLW 74
0069: RETLW 50
006A: RETLW 41
006B: RETLW 55
006C: RETLW 53
006D: RETLW 45
006E: RETLW 00
006F: RETLW 70
0070: RETLW 42
0071: RETLW 45
0072: RETLW 47
0073: RETLW 49
0074: RETLW 4E
0075: RETLW 00
0076: RETLW 42
0077: RETLW 54
0078: RETLW 45
0079: RETLW 53
007A: RETLW 54
007B: RETLW 00
007C: RETLW 62
007D: RETLW 45
007E: RETLW 4E
007F: RETLW 44
0080: RETLW 00
0081: RETLW 5A
0082: RETLW 43
0083: RETLW 00
0084: RETLW 00
0085: RETLW 43
0086: RETLW 49
0087: RETLW 53
0088: RETLW 00
0089: RETLW 01
008A: RETLW 44
008B: RETLW 00
008C: RETLW 02
008D: RETLW 44
008E: RETLW 49
008F: RETLW 53
0090: RETLW 00
0091: RETLW 03
0092: RETLW 45
0093: RETLW 00
0094: RETLW 04
0095: RETLW 46
0096: RETLW 00
0097: RETLW 05
0098: RETLW 46
0099: RETLW 49
009A: RETLW 53
009B: RETLW 00
009C: RETLW 06
009D: RETLW 47
009E: RETLW 00
009F: RETLW 07
00A0: RETLW 47
00A1: RETLW 49
00A2: RETLW 53
00A3: RETLW 00
00A4: RETLW 08
00A5: RETLW 41
00A6: RETLW 00
00A7: RETLW 09
00A8: RETLW 41
00A9: RETLW 49
00AA: RETLW 53
00AB: RETLW 00
00AC: RETLW 0A
00AD: RETLW 48
00AE: RETLW 00
00AF: RETLW 0B
00B0: RETLW 53
00B1: RETLW 50
00B2: RETLW 41
00B3: RETLW 43
00B4: RETLW 45
00B5: RETLW 00
00B6: RETLW 0C
.................... signed int Word(char line[], unsigned int8 *a, len)
.................... {
.................... unsigned int8 i; // Index do pole klicovych slov
.................... unsigned int8 j; // index do zpracovavane radky
....................
.................... while((line[*a]==' ')&(*a<len)) // Vynech mezery na zacatku
*
03A1: MOVF 62,W
03A2: MOVWF 04
03A3: MOVF 61,W
03A4: ADDWF 00,W
03A5: MOVWF 04
03A6: MOVF 00,W
03A7: SUBLW 20
03A8: BTFSC 03.2
03A9: GOTO 3AC
03AA: MOVLW 00
03AB: GOTO 3AD
03AC: MOVLW 01
03AD: MOVWF 68
03AE: MOVF 62,W
03AF: MOVWF 04
03B0: MOVF 63,W
03B1: SUBWF 00,W
03B2: BTFSS 03.0
03B3: GOTO 3B6
03B4: MOVLW 00
03B5: GOTO 3B7
03B6: MOVLW 01
03B7: ANDWF 68,W
03B8: XORLW 00
03B9: BTFSC 03.2
03BA: GOTO 3BF
.................... (*a)++; // Posouvej ukazovatko
03BB: MOVF 62,W
03BC: MOVWF 04
03BD: INCF 00,F
03BE: GOTO 3A1
....................
.................... for (i=0;i<sizeof(KeyWords);) // Slova ze slovniku
03BF: CLRF 64
03C0: MOVF 64,W
03C1: SUBLW 61
03C2: BTFSS 03.0
03C3: GOTO 42B
.................... {
.................... for (j=*a;(j<len)&(KeyWords[i]!=0)&(KeyWords[i]==line[j]);i++,j++) // Znaky ze slova
03C4: MOVF 62,W
03C5: MOVWF 04
03C6: MOVF 00,W
03C7: MOVWF 65
03C8: MOVF 63,W
03C9: SUBWF 65,W
03CA: BTFSS 03.0
03CB: GOTO 3CE
03CC: MOVLW 00
03CD: GOTO 3CF
03CE: MOVLW 01
03CF: MOVWF 66
03D0: MOVF 64,W
03D1: CALL 051
03D2: XORLW 00
03D3: BTFSS 03.2
03D4: GOTO 3D7
03D5: MOVLW 00
03D6: GOTO 3D8
03D7: MOVLW 01
03D8: ANDWF 66,W
03D9: MOVWF 68
03DA: MOVF 64,W
03DB: CALL 051
03DC: MOVWF 69
03DD: MOVF 61,W
03DE: ADDWF 65,W
03DF: MOVWF 04
03E0: MOVF 00,W
03E1: SUBWF 69,W
03E2: BTFSC 03.2
03E3: GOTO 3E6
03E4: MOVLW 00
03E5: GOTO 3E7
03E6: MOVLW 01
03E7: ANDWF 68,W
03E8: XORLW 00
03E9: BTFSC 03.2
03EA: GOTO 3EF
.................... {
.................... }
03EB: MOVF 64,W
03EC: INCF 64,F
03ED: INCF 65,F
03EE: GOTO 3C8
.................... if ((KeyWords[i]==0)&((line[j]==' ')|(j==len)))
03EF: MOVF 64,W
03F0: CALL 051
03F1: XORLW 00
03F2: BTFSC 03.2
03F3: GOTO 3F6
03F4: MOVLW 00
03F5: GOTO 3F7
03F6: MOVLW 01
03F7: MOVWF 67
03F8: MOVF 61,W
03F9: ADDWF 65,W
03FA: MOVWF 04
03FB: MOVF 00,W
03FC: SUBLW 20
03FD: BTFSC 03.2
03FE: GOTO 401
03FF: MOVLW 00
0400: GOTO 402
0401: MOVLW 01
0402: MOVWF 69
0403: MOVF 63,W
0404: SUBWF 65,W
0405: BTFSC 03.2
0406: GOTO 409
0407: MOVLW 00
0408: GOTO 40A
0409: MOVLW 01
040A: IORWF 69,W
040B: ANDWF 67,W
040C: XORLW 00
040D: BTFSC 03.2
040E: GOTO 421
.................... {
.................... if (j>=len) j=len-1; // Korekce abychom se nedostali za konec retezce
040F: MOVF 63,W
0410: SUBWF 65,W
0411: BTFSS 03.0
0412: GOTO 416
0413: MOVLW 01
0414: SUBWF 63,W
0415: MOVWF 65
.................... *a=j+1; // Posun ukazovatko za zpracovane slovo
0416: MOVF 62,W
0417: MOVWF 04
0418: MOVLW 01
0419: ADDWF 65,W
041A: MOVWF 00
....................
.................... return KeyWords[i+1]; // Vrat zastupnou hodnotu z tabulky klicovych slov
041B: MOVLW 01
041C: ADDWF 64,W
041D: CALL 051
041E: MOVWF 78
041F: MOVWF 78
0420: GOTO 42D
.................... }
.................... while(KeyWords[i]!=0) i++; // Preskoc zbytek slova v tabulce
0421: MOVF 64,W
0422: CALL 051
0423: XORLW 00
0424: BTFSC 03.2
0425: GOTO 428
0426: INCF 64,F
0427: GOTO 421
.................... i++; // Preskoc oddelovac
0428: INCF 64,F
.................... i++; // Preskoc polozku se zastupnou hodnotou
0429: INCF 64,F
.................... }
042A: GOTO 3C0
.................... return -1; // Prosli jsme cely slovnik a nedoslo ke shode
042B: MOVLW FF
042C: MOVWF 78
.................... }
....................
....................
.................... // Programovani pres RS232
.................... #define LINELEN 40 // Delka radky pro RS232
.................... #define CR 0x0D // Odradkovani
.................... #define BS 0x08 // Back Space
.................... void Download()
.................... {
.................... char line[LINELEN]; // Buffer na radku
.................... unsigned char c; // Znak
.................... unsigned int8 a; // Ukazovatko do bufferu
.................... unsigned int8 len; // Delka retezce v radce
.................... unsigned int8 Oct; // Cislo oktavy u noty
....................
.................... output_low(POWER_386); // Zapni napajeni zesilovace
*
0347: BSF 03.5
0348: BCF 05.4
0349: BCF 03.5
034A: BCF 05.4
.................... SoundNote(SOUND_Space,3,10); // Mezera
034B: MOVLW 0C
034C: MOVWF 69
034D: MOVLW 03
034E: MOVWF 6A
034F: CLRF 6C
0350: MOVLW 0A
0351: MOVWF 6B
0352: CALL 0E2
.................... Beep=SoundPGM;
0353: MOVLW 03
0354: MOVWF 33
.................... Error=0;
0355: BCF 2D.1
.................... SpecBeep(); // Pipni na znameni vstupu do programovani
0356: CALL 13A
....................
.................... Tempo=100; // Default hodnoty
0357: CLRF 2F
0358: MOVLW 64
0359: MOVWF 2E
.................... Pause=100;
035A: CLRF 31
035B: MOVWF 30
.................... Octava=0;
035C: CLRF 32
.................... Mode=0; // Mod hrani
035D: BCF 2D.0
.................... Oct=0;
035E: CLRF 60
.................... a=0; // Na zacatku je radka prazdna
035F: CLRF 5E
....................
.................... for(;input(POWER_PIC)==0;) // Opakuj vse dokud je PGM rezim
0360: BSF 03.5
0361: BSF 05.3
0362: MOVLW 00
0363: BCF 03.5
0364: BTFSC 05.3
0365: MOVLW 01
0366: XORLW 00
0367: BTFSS 03.2
0368: GOTO 58F
.................... {
.................... Loop:
.................... c=Getc(); // Vezmi znak ze seriovky
0369: CALL 152
036A: MOVF 78,W
036B: MOVWF 5D
.................... if (c>=0x80) goto Loop; // Ignoruj znaky nad ASCII
036C: MOVF 5D,W
036D: SUBLW 7F
036E: BTFSC 03.0
036F: GOTO 371
0370: GOTO 369
.................... if (c>=0x60) c=c-0x20; // Preved velka pismena na velka pismena
0371: MOVF 5D,W
0372: SUBLW 5F
0373: BTFSC 03.0
0374: GOTO 377
0375: MOVLW 20
0376: SUBWF 5D,F
.................... if ((c==CR)|(c=='/')) // Konec radky nebo komentar
0377: MOVF 5D,W
0378: SUBLW 0D
0379: BTFSC 03.2
037A: GOTO 37D
037B: MOVLW 00
037C: GOTO 37E
037D: MOVLW 01
037E: MOVWF 61
037F: MOVF 5D,W
0380: SUBLW 2F
0381: BTFSC 03.2
0382: GOTO 385
0383: MOVLW 00
0384: GOTO 386
0385: MOVLW 01
0386: IORWF 61,W
0387: XORLW 00
0388: BTFSC 03.2
0389: GOTO 55B
.................... {
.................... while (c!=CR) c=Getc(); // Zpracuj znaky komentare
038A: MOVF 5D,W
038B: SUBLW 0D
038C: BTFSC 03.2
038D: GOTO 392
038E: CALL 152
038F: MOVF 78,W
0390: MOVWF 5D
0391: GOTO 38A
.................... len=a; // Zapamatuj si delku radky
0392: MOVF 5E,W
0393: MOVWF 5F
.................... a=0; // Postav se na zacatek radky
0394: CLRF 5E
.................... Beep=SoundEndOfLine; // Default zuk na konci radky
0395: MOVLW 01
0396: MOVWF 33
.................... // Zpracovani radky
.................... while(a<len)
0397: MOVF 5F,W
0398: SUBWF 5E,W
0399: BTFSC 03.0
039A: GOTO 558
.................... {
.................... c=Word(line,&a,len);
039B: MOVLW 35
039C: MOVWF 61
039D: MOVLW 5E
039E: MOVWF 62
039F: MOVF 5F,W
03A0: MOVWF 63
*
042D: MOVF 78,W
042E: MOVWF 5D
.................... if (c==-1) // Nezname klicove slovo
042F: MOVF 5D,W
0430: SUBLW FF
0431: BTFSS 03.2
0432: GOTO 466
.................... {
.................... if (a<len) // Nejsme uz na konci radky ??
0433: MOVF 5F,W
0434: SUBWF 5E,W
0435: BTFSC 03.0
0436: GOTO 465
.................... {
.................... if ((line[a]>='0')&(line[a]<='9')) // Stojime na cislici -> je to cislo
0437: MOVLW 35
0438: ADDWF 5E,W
0439: MOVWF 04
043A: MOVF 00,W
043B: SUBLW 2F
043C: BTFSS 03.0
043D: GOTO 440
043E: MOVLW 00
043F: GOTO 441
0440: MOVLW 01
0441: MOVWF 62
0442: MOVLW 35
0443: ADDWF 5E,W
0444: MOVWF 04
0445: MOVF 00,W
0446: SUBLW 39
0447: BTFSC 03.0
0448: GOTO 44B
0449: MOVLW 00
044A: GOTO 44C
044B: MOVLW 01
044C: ANDWF 62,W
044D: XORLW 00
044E: BTFSC 03.2
044F: GOTO 45C
.................... {
.................... // Oct=Number(line,&a,len)&0x7; // tohle nefunguje protoze je chyba v prekladaci
.................... Oct=Number(line,&a,len); // prekladac prepoklada, z W obsahuje spodni bajt vysledku
0450: MOVLW 35
0451: MOVWF 61
0452: MOVLW 5E
0453: MOVWF 62
0454: MOVF 5F,W
0455: MOVWF 63
0456: CALL 18C
0457: MOVF 78,W
0458: MOVWF 60
.................... Oct&=0x7; // ale k navratu pouziva RETLW 0 coz smaze W !
0459: MOVLW 07
045A: ANDWF 60,F
.................... }
.................... else // Stojime na pismenu nebo oddelovaci
045B: GOTO 465
.................... {
.................... if (line[a]!=' ') Error=1; // Neni to oddelovac - chyba
045C: MOVLW 35
045D: ADDWF 5E,W
045E: MOVWF 04
045F: MOVF 00,W
0460: SUBLW 20
0461: BTFSC 03.2
0462: GOTO 464
0463: BSF 2D.1
.................... a++; // Preskocim 1 znak (a kdyz to nepomuze dostanu se zase sem)
0464: INCF 5E,F
.................... }
.................... }
.................... }
.................... else if (c=='P') // Play
0465: GOTO 557
0466: MOVF 5D,W
0467: SUBLW 50
0468: BTFSS 03.2
0469: GOTO 478
.................... {
.................... CisloSkladby=Number(line,&a,len);
046A: MOVLW 35
046B: MOVWF 61
046C: MOVLW 5E
046D: MOVWF 62
046E: MOVF 5F,W
046F: MOVWF 63
0470: CALL 18C
0471: MOVF 78,W
0472: MOVWF 34
.................... Mode=0;
0473: BCF 2D.0
.................... Play();
0474: CALL 279
.................... Beep=SoundPGM;
0475: MOVLW 03
0476: MOVWF 33
.................... }
.................... else if (c=='E') // Erase
0477: GOTO 557
0478: MOVF 5D,W
0479: SUBLW 45
047A: BTFSS 03.2
047B: GOTO 4B6
.................... {
.................... Mode=0;
047C: BCF 2D.0
.................... Erase();
.................... Beep=SoundPGM;
*
04B3: MOVLW 03
04B4: MOVWF 33
.................... }
.................... else if (c=='t') // Tempo
04B5: GOTO 557
04B6: MOVF 5D,W
04B7: SUBLW 74
04B8: BTFSS 03.2
04B9: GOTO 4D6
.................... {
.................... Tempo=Number(line,&a,len)&~MASKTEMPO;
04BA: MOVLW 35
04BB: MOVWF 61
04BC: MOVLW 5E
04BD: MOVWF 62
04BE: MOVF 5F,W
04BF: MOVWF 63
04C0: CALL 18C
04C1: MOVF 78,W
04C2: MOVWF 2E
04C3: MOVF 79,W
04C4: ANDLW C7
04C5: MOVWF 2F
.................... if (Tempo==0) Tempo=100;
04C6: MOVF 2E,F
04C7: BTFSS 03.2
04C8: GOTO 4CF
04C9: MOVF 2F,F
04CA: BTFSS 03.2
04CB: GOTO 4CF
04CC: CLRF 2F
04CD: MOVLW 64
04CE: MOVWF 2E
.................... Data=Tempo|DATATEMPO;
04CF: MOVF 2E,W
04D0: MOVWF 2B
04D1: MOVF 2F,W
04D2: IORLW 28
04D3: MOVWF 2C
.................... WriteDataInc(); // Podmineny zapis do FLASH a posun na dalsi adresu
04D4: CALL 2DC
.................... }
.................... else if (c=='p') // Pause
04D5: GOTO 557
04D6: MOVF 5D,W
04D7: SUBLW 70
04D8: BTFSS 03.2
04D9: GOTO 4F6
.................... {
.................... Pause=Number(line,&a,len)&~MASKPAUSE;
04DA: MOVLW 35
04DB: MOVWF 61
04DC: MOVLW 5E
04DD: MOVWF 62
04DE: MOVF 5F,W
04DF: MOVWF 63
04E0: CALL 18C
04E1: MOVF 78,W
04E2: MOVWF 30
04E3: MOVF 79,W
04E4: ANDLW C7
04E5: MOVWF 31
.................... if (Pause==0) Pause=100;
04E6: MOVF 30,F
04E7: BTFSS 03.2
04E8: GOTO 4EF
04E9: MOVF 31,F
04EA: BTFSS 03.2
04EB: GOTO 4EF
04EC: CLRF 31
04ED: MOVLW 64
04EE: MOVWF 30
.................... Data=Pause|DATAPAUSE;
04EF: MOVF 30,W
04F0: MOVWF 2B
04F1: MOVF 31,W
04F2: IORLW 30
04F3: MOVWF 2C
.................... WriteDataInc(); // Podmineny zapis do FLASH a posun na dalsi adresu
04F4: CALL 2DC
.................... }
.................... else if (c=='B') // Begin
04F5: GOTO 557
04F6: MOVF 5D,W
04F7: SUBLW 42
04F8: BTFSS 03.2
04F9: GOTO 50D
.................... {
.................... CisloSkladby=~0; // Neplatne cislo skladby
04FA: MOVLW FF
04FB: MOVWF 34
.................... Find(); // najde konec posledni skladby
04FC: CALL 204
.................... Octava=Number(line,&a,len)&~MASKBEGIN;
04FD: MOVLW 35
04FE: MOVWF 61
04FF: MOVLW 5E
0500: MOVWF 62
0501: MOVF 5F,W
0502: MOVWF 63
0503: CALL 18C
0504: MOVF 78,W
0505: MOVWF 32
.................... Data=DATABEGIN|Octava; // Zacatecni znacka
0506: MOVF 32,W
0507: MOVWF 2B
0508: MOVLW 20
0509: MOVWF 2C
.................... Mode=1; // Mod zapisu do FLASH pameti
050A: BSF 2D.0
.................... WriteDataInc(); // Podmineny zapis do FLASH a posun na dalsi adresu
050B: CALL 2DC
.................... }
.................... else if (c=='b') // Test
050C: GOTO 557
050D: MOVF 5D,W
050E: SUBLW 62
050F: BTFSS 03.2
0510: GOTO 51C
.................... {
.................... Octava=Number(line,&a,len)&~MASKBEGIN;
0511: MOVLW 35
0512: MOVWF 61
0513: MOVLW 5E
0514: MOVWF 62
0515: MOVF 5F,W
0516: MOVWF 63
0517: CALL 18C
0518: MOVF 78,W
0519: MOVWF 32
.................... Mode=0;
051A: BCF 2D.0
.................... }
.................... else if (c=='Z') // End
051B: GOTO 557
051C: MOVF 5D,W
051D: SUBLW 5A
051E: BTFSS 03.2
051F: GOTO 522
.................... {
.................... Mode=0;
0520: BCF 2D.0
.................... }
.................... else // Nota
0521: GOTO 557
.................... {
.................... Data=Number(line,&a,len); // Delka noty (nepovinna)
0522: MOVLW 35
0523: MOVWF 61
0524: MOVLW 5E
0525: MOVWF 62
0526: MOVF 5F,W
0527: MOVWF 63
0528: CALL 18C
0529: MOVF 79,W
052A: MOVWF 2C
052B: MOVF 78,W
052C: MOVWF 2B
.................... Data&=0x3F; // Jen platny rozsah
052D: MOVLW 3F
052E: ANDWF 2B,F
052F: MOVLW 00
0530: ANDWF 2C,F
.................... if (Data==0) Data++; // Je-li nulova delka - dej jednotkovou
0531: MOVF 2B,F
0532: BTFSS 03.2
0533: GOTO 53A
0534: MOVF 2C,F
0535: BTFSS 03.2
0536: GOTO 53A
0537: INCF 2B,F
0538: BTFSC 03.2
0539: INCF 2C,F
.................... Data<<=7; // Delka
053A: RLF 2B,F
053B: RLF 2C,F
053C: RLF 2B,F
053D: RLF 2C,F
053E: RLF 2B,F
053F: RLF 2C,F
0540: RLF 2B,F
0541: RLF 2C,F
0542: RLF 2B,F
0543: RLF 2C,F
0544: RLF 2B,F
0545: RLF 2C,F
0546: RLF 2B,F
0547: RLF 2C,F
0548: MOVLW 80
0549: ANDWF 2B,F
.................... Data|=c; // Nota
054A: MOVF 5D,W
054B: IORWF 2B,F
.................... Data|=(Oct<<4); // Oktava
054C: SWAPF 60,W
054D: MOVWF 77
054E: MOVLW F0
054F: ANDWF 77,F
0550: MOVF 77,W
0551: IORWF 2B,F
.................... WriteDataInc(); // Podmineny zapis do FLASH a posun na dalsi adresu
0552: CALL 2DC
.................... if (~Mode)
0553: BTFSC 2D.0
0554: GOTO 557
.................... {
.................... PlayData(); // Zahraj notu
0555: CALL 233
.................... Beep=0; // Po zahrani noty uz nepipej na konci radky
0556: CLRF 33
.................... }
.................... }
.................... }
0557: GOTO 397
.................... a=0; // Radka zpracovana, nuluj jeji delku
0558: CLRF 5E
.................... SpecBeep(); // Pipni
0559: CALL 13A
.................... goto Loop;
055A: GOTO 369
.................... }
.................... if ((c==BS)&(a>0)) {a--;goto Loop;} // Smaz znak
055B: MOVF 5D,W
055C: SUBLW 08
055D: BTFSC 03.2
055E: GOTO 561
055F: MOVLW 00
0560: GOTO 562
0561: MOVLW 01
0562: MOVWF 61
0563: MOVF 5E,F
0564: BTFSS 03.2
0565: GOTO 568
0566: MOVLW 00
0567: GOTO 569
0568: MOVLW 01
0569: ANDWF 61,W
056A: XORLW 00
056B: BTFSC 03.2
056C: GOTO 56F
056D: DECF 5E,F
056E: GOTO 369
.................... if ((c==',')|(c<=' ')) c=' '; // Vsechny ostatni ridici znaky i carka jsou oddelovac
056F: MOVF 5D,W
0570: SUBLW 2C
0571: BTFSC 03.2
0572: GOTO 575
0573: MOVLW 00
0574: GOTO 576
0575: MOVLW 01
0576: MOVWF 61
0577: MOVF 5D,W
0578: SUBLW 20
0579: BTFSC 03.0
057A: GOTO 57D
057B: MOVLW 00
057C: GOTO 57E
057D: MOVLW 01
057E: IORWF 61,W
057F: XORLW 00
0580: BTFSC 03.2
0581: GOTO 584
0582: MOVLW 20
0583: MOVWF 5D
.................... if (a<LINELEN) line[a++]=c; // Zapis znak do bufferu a posun ukazovatko
0584: MOVF 5E,W
0585: SUBLW 27
0586: BTFSS 03.0
0587: GOTO 58E
0588: MOVF 5E,W
0589: INCF 5E,F
058A: ADDLW 35
058B: MOVWF 04
058C: MOVF 5D,W
058D: MOVWF 00
.................... }
058E: GOTO 360
058F: GOTO 5BE (RETURN)
.................... }
....................
....................
.................... // Tabulka pro prekodovani tlacitek
.................... const int8 KeyTranslate[16] = {0, 1, 2, 5, 3, 6, 8, 11, 4, 7, 9, 12, 10, 13, 14, 15};
*
00B7: BCF 0A.0
00B8: BCF 0A.1
00B9: BCF 0A.2
00BA: ADDWF 02,F
00BB: RETLW 00
00BC: RETLW 01
00BD: RETLW 02
00BE: RETLW 05
00BF: RETLW 03
00C0: RETLW 06
00C1: RETLW 08
00C2: RETLW 0B
00C3: RETLW 04
00C4: RETLW 07
00C5: RETLW 09
00C6: RETLW 0C
00C7: RETLW 0A
00C8: RETLW 0D
00C9: RETLW 0E
00CA: RETLW 0F
....................
.................... void main()
.................... {
*
0590: CLRF 04
0591: MOVLW 1F
0592: ANDWF 03,F
0593: MOVLW 07
0594: BSF 03.5
0595: MOVWF 1F
0596: BCF 05.0
0597: BCF 03.5
0598: BCF 05.0
.................... Start:
....................
.................... // Inicializace
.................... port_b_pullups(TRUE); // Zapni pull-up odpory na portu B
0599: BSF 03.5
059A: BCF 01.7
.................... set_tris_a(0b00001000); // Nastav nepouzite vyvody jako vystupy
059B: MOVLW 08
059C: MOVWF 05
.................... set_tris_b(0b11110000); // 1 znamena vstup
059D: MOVLW F0
059E: MOVWF 06
.................... *0x9F = 6; // Vsechny vstupy jsou digitalni
059F: MOVLW 06
05A0: MOVWF 1F
....................
.................... // Test na rezim programovani
.................... if ((input(POWER_PIC)==0)&(input(RXD)==0)) // Podminka programovani
05A1: BSF 05.3
05A2: MOVLW 00
05A3: BCF 03.5
05A4: BTFSC 05.3
05A5: MOVLW 01
05A6: XORLW 00
05A7: BTFSC 03.2
05A8: GOTO 5AB
05A9: MOVLW 00
05AA: GOTO 5AC
05AB: MOVLW 01
05AC: MOVWF 36
05AD: BSF 03.5
05AE: BSF 06.1
05AF: MOVLW 00
05B0: BCF 03.5
05B1: BTFSC 06.1
05B2: MOVLW 01
05B3: XORLW 00
05B4: BTFSC 03.2
05B5: GOTO 5B8
05B6: MOVLW 00
05B7: GOTO 5B9
05B8: MOVLW 01
05B9: ANDWF 36,W
05BA: XORLW 00
05BB: BTFSC 03.2
05BC: GOTO 5BE
.................... Download(); // Pripojen RS232 a propojka na PGM
05BD: GOTO 347
....................
.................... // Zapnuti napajeni
.................... output_low(POWER_PIC); // Pripoj GND pro procesor
05BE: BSF 03.5
05BF: BCF 05.3
05C0: BCF 03.5
05C1: BCF 05.3
.................... SoundNote(SOUND_Space,3,10); // Mezera
05C2: MOVLW 0C
05C3: MOVWF 69
05C4: MOVLW 03
05C5: MOVWF 6A
05C6: CLRF 6C
05C7: MOVLW 0A
05C8: MOVWF 6B
05C9: CALL 0E2
.................... output_low(POWER_386); // Zapni napajeni zesilovace
05CA: BSF 03.5
05CB: BCF 05.4
05CC: BCF 03.5
05CD: BCF 05.4
.................... SoundNote(SOUND_Space,3,100); // Mezera (jinak se chybne detekuje tlacitko)
05CE: MOVLW 0C
05CF: MOVWF 69
05D0: MOVLW 03
05D1: MOVWF 6A
05D2: CLRF 6C
05D3: MOVLW 64
05D4: MOVWF 6B
05D5: CALL 0E2
....................
.................... // Cteni tlacitek
.................... #use FAST_IO(B)
.................... CisloSkladby=(input_b() >> 4) ^ 0xFF & 0xF; // Precti stav tlacitek
05D6: SWAPF 06,W
05D7: MOVWF 77
05D8: MOVLW 0F
05D9: ANDWF 77,F
05DA: MOVF 77,W
05DB: XORLW 0F
05DC: MOVWF 34
.................... #use STANDARD_IO(B)
.................... CisloSkladby=KeyTranslate[CisloSkladby]; // Prekoduj je do binarniho kodu
05DD: MOVF 34,W
05DE: CALL 0B7
05DF: MOVWF 78
05E0: MOVWF 34
....................
.................... // Prehrani skladby
.................... Play(); // Zahraj skladbu
05E1: CALL 279
....................
.................... // Po odehrani usni a cekej na zmacknuti tlacitka
.................... #use FAST_IO(B)
.................... if (input_B()); // Precti stav portu B (vuci tomuto stavu se bude hlidat zmena)
05E2: MOVF 06,W
05E3: XORLW 00
05E4: BTFSC 03.2
05E5: GOTO 5E6
.................... #use STANDARD_IO(B)
.................... bit_clear(*0xB,0); // Nuluj priznak preruseni od zmeny stavu portu B
05E6: BCF 0B.0
.................... enable_interrupts(INT_RB); // Povol preruseni od zmeny stavu portu B
05E7: BSF 0B.3
....................
.................... output_high(POWER_386); // Vypni napajeni zesilovace
05E8: BSF 03.5
05E9: BCF 05.4
05EA: BCF 03.5
05EB: BSF 05.4
.................... output_float(POWER_PIC); // Odpoj GND
05EC: BSF 03.5
05ED: BSF 05.3
.................... Sleep(); // Usni aby byla minimalni klidova spotreba
05EE: SLEEP
....................
.................... disable_interrupts(INT_RB); // Zakaz preruseni od portu
05EF: BCF 03.5
05F0: BCF 0B.3
.................... goto Start; // Po probuzeni skoc na zacatek
05F1: GOTO 599
.................... }
....................
05F2: SLEEP
/Designs/MB01B/SW/1_00/Skladby/BednaOdWhisky.txt
0,0 → 1,126
// Pisnicka "Bedna od Whisky"
//
// Tato pisnicka je napsana ve formatu, ktery se da pouzit jak pro primy
// preklad do firmwaru melodickeho zvonku tak i pro dodatecne nahrani
 
BEGIN 2, // Zacatek skladby
TEMPO 100, // Delka nejkratsi noty v ms
PAUSE 100, // Delka mezery mezi notami
 
1 A 2,
2 C 2,
2 E 2,
2 A 2,
2 G 4,
2 E 2,
2 E 2,
2 A 2,
2 G 2,
2 E 2,
2 D 2,
2 E 4,
Space 4,
1 A 2,
2 C 2,
2 E 2,
2 A 2,
2 G 2,
2 G 2,
2 E 2,
2 E 2,
1 A 2,
2 E 2,
1 H 2,
2 E 2,
1 A 4,
Space 4,
1 A 2,
2 C 2,
2 E 2,
2 A 2,
2 G 2,
2 G 2,
2 E 4,
2 A 2,
2 G 2,
2 E 2,
2 D 2,
2 E 4,
Space 2,
2 E 2,
1 A 2,
2 C 2,
2 E 2,
2 A 2,
2 G 2,
2 E 4,
2 E 2,
2 A 2,
2 A 2,
2 GIS 2,
2 H 2,
2 A 4,
Space 8,
2 E 2,
2 A 2,
2 A 2,
2 A 2,
2 GIS 2,
2 FIS 2,
2 A 4,
2 A 2,
2 H 2,
2 H 2,
2 A 2,
2 H 2,
3 CIS 2,
2 A 4,
2 E 2,
2 A 2,
2 A 2,
2 A 2,
2 GIS 2,
2 FIS 2,
2 A 2,
2 A 2,
2 A 2,
2 H 2,
2 H 2,
2 A 2,
2 GIS 2,
2 A 4,
Space 2,
2 E 2,
2 A 2,
2 A 2,
2 A 2,
2 GIS 2,
2 FIS 2,
2 A 4,
2 A 2,
2 H 2,
2 H 2,
2 A 2,
2 H 2,
3 CIS 2,
2 A 4,
2 E 2,
2 A 2,
2 A 2,
2 A 2,
2 GIS 2,
2 FIS 2,
2 A 2,
Space 2,
2 A 2,
2 H 2,
2 H 2,
2 A 2,
2 GIS 2,
2 A 8,
2 G 2,
2 A 8,
2 G 2,
2 A 8,
 
END
/Designs/MB01B/SW/1_00/Skladby/KdyzMeBaliZaVojacka.txt
0,0 → 1,58
// Pisnicka "Kdyz me brali za vojacka"
//
// Tato pisnicka je napsana ve formatu, ktery se da pouzit jak pro primy
// preklad do firmwaru melodickeho zvonku tak i pro dodatecne nahrani
 
BEGIN 2, // Zacatek skladby
TEMPO 150, // Delka nejkratsi noty v ms
PAUSE 100, // Delka mezery mezi notami
 
1 A 1,
2 C 1,
2 E 1,
2 D 1,
2 C 1,
1 H 1,
2 C 2,
2 D 1,
2 E 2,
2 D 1,
2 G 1,
2 G 1,
2 G 1,
2 G 1,
2 A 1,
2 E 2,
Space 4,
2 D 1,
2 F 1,
2 A 1,
2 G 1,
2 F 1,
2 E 1,
2 E 1,
2 F 1,
2 E 1,
2 C 1,
1 A 2,
1 GIS 1,
1 H 1,
2 E 1,
2 D 1,
1 H 1,
2 C 1,
1 A 2,
Space 2,
1 H 2,
2 C 2,
Space 2,
2 D 2,
2 E 1,
2 E 1,
2 E 1,
2 D 1,
1 H 1,
2 C 1,
1 A 2,
 
END
/Designs/MB01B/SW/1_00/Skladby/Medvedi.txt
0,0 → 1,173
// Pisnicka "Medvedi"
//
// Tato pisnicka je napsana ve formatu, ktery se da pouzit jak pro primy
// preklad do firmwaru melodickeho zvonku tak i pro dodatecne nahrani
 
BEGIN 1, // Zacatek skladby
TEMPO 150, // Delka nejkratsi noty v ms
PAUSE 100, // Delka mezery mezi notami
 
1 C 1, // 1
1 C 1,
1 C 1,
1 E 1,
1 D 1,
0 G 1,
 
1 C 3, // 2
Space 4,
 
1 E 1, // 3
1 E 1,
1 E 1,
1 E 1,
1 D 1,
1 G 1,
 
1 E 2, // 4
Space 4,
 
1 G 1, // 5
1 G 1,
1 A 1,
1 G 1,
1 F 1,
1 E 1,
 
1 F 1, // 6
1 A 1,
1 G 1,
1 F 1,
1 E 1,
1 D 1,
 
1 C 1, // 7
0 H 1,
1 C 1,
1 E 1,
1 D 1,
0 G 1,
 
1 C 3, // 8
Space 4,
1 A 1, // 9
1 A 1,
1 A 1,
1 A 1,
1 H 1,
2 D 1,
 
2 C 4, // 10
Space 2,
 
2 E 1, // 11
2 E 1,
2 E 1,
2 E 1,
2 D 1,
2 G 1,
 
2 E 4, // 12
Space 2,
 
2 G 1, // 13
2 G 1,
2 A 1,
2 G 1,
2 F 1,
2 E 1,
 
2 F 1, // 14
2 A 1,
2 G 1,
2 F 1,
2 E 1,
2 D 1,
 
2 C 1, // 15
1 H 1,
2 C 1,
2 E 1,
2 D 1,
1 G 1,
 
2 C 4, // 16
Space 2,
 
1 C 6, // 1
0 G 2,
 
1 D 3, // 2
Space 3,
 
1 G 1, // 3
1 G 1,
1 Fis 1,
1 G 1,
1 A 1,
1 Fis 1,
 
1 G 2, // 4
Space 4,
 
1 G 1, // 5
1 G 1,
1 A 1,
1 G 1,
1 F 1,
1 E 1,
 
1 F 1, // 6
1 A 1,
1 G 1,
1 F 1,
1 E 1,
1 D 1,
 
1 C 6, // 7
1 E 2,
 
1 D 3, // 8
Space 3,
 
1 C 6, // 9
0 G 2,
 
1 D 3, // 10
Space 3,
 
1 G 1, // 11
1 G 1,
1 Fis 1,
1 G 1,
1 A 1,
1 Fis 1,
 
1 G 2, // 12
Space 4,
 
1 G 1, // 13
1 G 1,
1 A 1,
1 G 1,
1 F 1,
1 E 1,
 
1 F 1, // 14
1 A 1,
1 G 1,
1 F 1,
1 E 1,
1 D 1,
 
1 C 1, // 15
0 H 1,
1 C 1,
1 E 1,
1 D 1,
0 G 1,
 
1 C 2, // 16
Space 4,
 
END
/Designs/MB01B/SW/1_00/Skladby/Test.txt
0,0 → 1,27
// Testovaci posloupnost vsech not
//
// Tento soubor nelze vlozit do zdrojaku, da se jen natahnout po seriovce
// Nezapomente prosim, ze delka radky s notami je maximalne 40 znaku
 
BEGIN 0, // Zacatek skladby bez posunuti oktavy
TEMPO 2000, // Kazdy ton bude znit 2s aby se dala zmerit frekvence
PAUSE 100, // Delka mezery mezi notami
 
0 C Cis D Dis E F Fis G Gis A Ais H
Space
1 C Cis D Dis E F Fis G Gis A Ais H
Space
2 C Cis D Dis E F Fis G Gis A Ais H
Space
3 C Cis D Dis E F Fis G Gis A Ais H
Space
4 C Cis D Dis E F Fis G Gis A Ais H
Space
5 C Cis D Dis E F Fis G Gis A Ais H
Space
6 C Cis D Dis E F Fis G Gis A Ais H
Space
7 C Cis D Dis E F Fis G Gis A Ais H
Space
 
END
/Designs/MB01B/SW/1_00/Skladby/TheFinalSoundDown.txt
0,0 → 1,61
// Pisnicka "The Final Sound Down"
//
// Tato pisnicka je napsana ve formatu, ktery se da pouzit jak pro primy
// preklad do firmwaru melodickeho zvonku tak i pro dodatecne nahrani
 
BEGIN 3, // Zacatek skladby
TEMPO 100, // Delka nejkratsi noty v ms
PAUSE 100, // Delka mezery mezi notami
 
1 A 1,
1 G 1,
1 A 4,
1 D 4,
Space 2,
 
1 Ais 1,
1 A 1,
1 Ais 2,
1 A 2,
1 G 4,
Space 2,
 
1 Ais 1,
1 A 1,
1 Ais 4,
1 D 4,
Space 2,
 
1 G 1,
1 F 1,
1 G 2,
1 F 2,
1 E 2,
1 G 2,
1 F 4,
Space 2,
 
1 E 1,
1 F 1,
1 G 4,
Space 2,
 
1 F 1,
1 G 1,
1 A 2,
1 G 2,
1 F 2,
1 E 2,
1 D 4,
1 Ais 4,
1 A 4,
Space 2,
 
1 A 1,
1 Ais 1,
1 A 1,
1 G 1,
1 A 4,
Space 2,
 
END
/Designs/MB01B/SW/1_00/data.c
0,0 → 1,75
// Tento soubor definuje vse potrebne pro ulozeni skladeb do pameti programu.
// Dale definuje pislusna makra pro snadne definice. Tyto definice jsou voleny
// zamerne tak, aby mohl byt pouzit stejny soubor s definici skladby jak
// pro vlozeni primo do firmwaru v dobe prekladu tak i k dodatecnemu nahrani
// skladby pres seriovou linku.
 
// Definice hranic pameti pro ulozeni pisnicek
#define STARTMEM 0x600 // Zde zacina pametoa oblast pro pisnicky
#define ENDMEM 0x7ff // Zde konci pametova oblast pro pisnicky
 
// Definice konstant pro kodovani dat
#define ENDOFDATA 0x3FFF // Priznak konce pisnicek (prazdna pamet)
#define DATABEGIN 0x2000 // Kod zacatku skladby
#define MASKBEGIN 0x3800
#define DATATEMPO 0x2800 // Kod pro nastaveni tempa
#define MASKTEMPO 0x3800
#define DATAPAUSE 0x3000 // Kod pro nastaveni mezery mezi notami
#define MASKPAUSE 0x3800
#define MASKNOTE 0x2000 // Nejvissi bit 0 urcuje, ze jde o notu
 
// Pseudomakra pro jednoduchy zapis skladeb do zdrojaku jazyka C
#define BEGIN DATABEGIN+ // Zacatek pisnicky + posunuti oktav
#define TEMPO DATATEMPO+ // Delka nejskratsi noty v ms
#define PAUSE DATAPAUSE+ // Delka mezery mezi notami
#define END // Konec skladby, zde nic neznamena
 
// Pseudomakra pro zapis not, zapisuje se cislo oktavy, nota, delka noty
#define C *16 + SOUND_C + 128 *
#define Cis *16 + SOUND_Cis + 128 *
#define D *16 + SOUND_D + 128 *
#define Dis *16 + SOUND_Dis + 128 *
#define E *16 + SOUND_E + 128 *
#define F *16 + SOUND_F + 128 *
#define Fis *16 + SOUND_Fis + 128 *
#define G *16 + SOUND_G + 128 *
#define Gis *16 + SOUND_Gis + 128 *
#define A *16 + SOUND_A + 128 *
#define Ais *16 + SOUND_Ais + 128 *
#define H *16 + SOUND_H + 128 *
#define Space SOUND_Space + 128 *
 
// Pametova oblast
#ORG 0x600,0x7FF {} // Vyhrazeni oblasti pameti pro ulozeni pisnicek
#ROM 0x600 = { // Naplneni oblasti pameti daty
 
// Pisnicky jako soucast firwaru se vkladaji sem
// Museji mit stejny format jako uvedene priklady aby zafungovaly makra
#include "Skladby\TheFinalSoundDown.txt"
#include "Skladby\BednaOdWhisky.txt"
#include "Skladby\KdyzMeBaliZaVojacka.txt"
#include "Skladby\Medvedi.txt"
 
// Koncova znacka a konec oblasti pro skladby
ENDOFDATA
}
 
// Zruseni definic maker pro definici skladeb
// V dalsim programu uz nebudou potreba
#undef BEGIN
#undef TEMPO
#undef PAUSE
#undef END
#undef C
#undef Cis
#undef D
#undef Dis
#undef E
#undef F
#undef Fis
#undef G
#undef Gis
#undef A
#undef Ais
#undef H
#undef Space
/Designs/MB01B/SW/1_00/mb01a.c
0,0 → 1,497
// Melodicky zvonek MB01A_1_00
//
// Prohram pro melodicky zvonek s pouzitim knihovny Sound_t1.C
//
// (c)miho 2004
//
// Historie:
// 1.00 Uvodni verze
 
#include <16F819.h> // Definice procesoru
#fuses HS,NOPROTECT,NOWDT,PUT,NOLVP,NOBROWNOUT,WRT // Definice konfiguracniho slova
 
#define POWER_386 PIN_A4 // L zapne napajeni pro zesilovac LM386
#define POWER_PIC PIN_A3 // L pripoji GND pro procesor PIC
 
#define SOUND_HI PIN_B3 // Akusticky vystup
#define SOUND_LO PIN_B2 // Akusticky vystup
#define SOUND_CLOCK 20000000 // Frekvence hodin
#define SOUND_LowOctave 1 // O oktavu vys protoze mame moc rychly krystal
#include "Sound_T1.c" // Hudebni knihovna
 
#include "Data.c" // Datovy blok pro predpripravene skladby
 
#define RXD PIN_B1 // Port pro RS232
#use delay(CLOCK=20000000) // Konfigurace pro casovani RS232
#use rs232(BAUD=9600,RCV=RXD,INVERT,PARITY=N,BITS=8) // Prenosove parametry RS232
 
 
// Sada globalnich promennych
// --------------------------
// Vyuzivame globalni promenne protoze je to vyhodne z hlediska spotreby zdroju. Usetri
// se vyznmane mnoho pameti programu pri predavani parametru
 
 
unsigned int16 Adr; // Adresovy ukazatel do pameti skladeb
unsigned int16 Data; // Prectena data nebo data pro zapis
unsigned int1 Mode; // 0=rezim testovani, 1=rezim zapisu do FLASH
 
unsigned int16 Tempo; // Tempo (delka nejkratsi skladby v ms)
unsigned int16 Pause; // Delka mezery mezi notami v ms
unsigned int8 Octava; // Posunuti skladby v oktavach
 
unsigned int8 Beep; // Druh pipnuti pro proceduru SoundSpec
unsigned int1 Error; // Priznak chyby
 
unsigned int8 CisloSkladby; // Cislo skladby pro proceduru Find a Play
 
 
// Zvuky, posloupnost zadaneho poctu tonu
#define SoundEndOfLine 0x01 // Kratke pipnuti na konci radky
#define SoundPGM 0x03 // Trilek pri vstupu do rezimu programovani
#define SoundPostPlay 0x03 // Po ukonceni prehravani
#define SoundERASE 0x02 // Zvuk pri smazani bloku FLASH pameti
#define SoundERR 0x05 // Chyba syntaxe
void SpecBeep()
// Data - pocet pipnuti, 0 znamena ticho
{
int Oct;
 
if (Error) Beep=SoundERR;
 
for(Oct=2;Beep!=0;Beep--)
{
SoundNote(SOUND_A,Oct++,50);
}
Error=0;
}
 
 
// Precti slovo z pameti programu
int16 ReadData()
// Adr - adresa ze ktere se cte
// Data - prectena data
{
int8 a,b; // Pomocne promenne
 
(int8)*EEADR = Adr; // Adresa, spodni cast
(int8)*EEADRH = Adr >> 8; // Adresa, horni cast
bit_set(*EECON1,EECON1_EEPGD); // Pamet programu
bit_set(*EECON1,EECON1_RD); // Operace cteni
#ASM
nop; // Povinne nop
nop;
#ENDASM
a = (int8)*EEDATA; // Prevezmi data
b = (int8)*EEDATAH;
Data=make16(b,a); // Sestav vysledek ze 2 bajtu
}
 
 
// Smazani cele pameti vyhrazene pro skladby
void Erase()
{
for(Adr=STARTMEM; Adr<=ENDMEM; Adr++) // Cela oblast
{
ReadData();
if (Data!=0x3FFF) // Mazu jen bloky, ktere to potrebuji
{
if (input(POWER_PIC)!=0) return; // Nezapisuj pokud neni jumper povoleni programovani
(int8)*EEADR = Adr; // Adresa bloku, spodni cast
(int8)*EEADRH = Adr >> 8; // Adresa bloku, horni cast
bit_set(*EECON1,EECON1_EEPGD); // Pamet programu
bit_set(*EECON1,EECON1_WREN); // Povolit zapis
bit_set(*EECON1,EECON1_FREE); // Operace mazani
(int8)*EECON2 = 0x55; // Povinna segvence pro zapis
(int8)*EECON2 = 0xAA;
bit_set(*EECON1,EECON1_WR); // Zahajeni mazani
#ASM
nop; // Povinne prazdne instrukce
nop;
#ENDASM
bit_clear(*EECON1,EECON1_WREN); // Uz ne zapis
bit_clear(*EECON1,EECON1_FREE); // Uz ne mazani
bit_clear(*EECON1,EECON1_EEPGD); // Uz ne pamet programu
Beep=SoundERASE;
SpecBeep();
}
}
}
 
 
// Zapis do pameti programu po jednotlivych slovech.
// Soucastka vyzaduje zapis vzdy celych osmi slov najednou. Vyuziva se toho, ze pamet FLASH
// umi zapisovat jen smerem do nuly a tak staci na pozice, ktere zrovna nechceme programovat
// zapsat same jednicky cimz se stav jejich stav nezmeni.
void WriteData()
// Adr - adresa, kam se bude zapisovat
// Data - data, ktera se budou zapisovat
{
int i;
 
bit_set(*EECON1,EECON1_EEPGD); // Pamet programu
bit_set(*EECON1,EECON1_WREN); // Zapis
(int8)*EEADR = Adr & ~3; // Adresa, spodni cast, zaokrouhleno dolu na nasobek 8
(int8)*EEADRH = Adr >> 8; // Adresa, horni cast
for (i=0; i<4; i++)
{
if ((Adr & 3) == i) // Pokud je adresa slova v bloku totozna s pozadovanou
{
(int8)*EEDATA =Data; // Platne slovo, spodni cast
(int8)*EEDATAH=Data >> 8; // Platne slovo, horni cast
}
else // Ostatni bunky nemenime
{
(int8)*EEDATA =0xFF; // Zbytek same jednicky
(int8)*EEDATAH=0xFF;
}
(int8)*EECON2 = 0x55; // Povinna sekvence pro zapis
(int8)*EECON2 = 0xAA;
bit_set(*EECON1,EECON1_WR); // Zahajeni zapisu
#ASM
nop; // Povinne dve prazdne instrukce
nop;
#ENDASM
((int8)*EEADR) ++; // Dalsi slovo
}
bit_clear(*EECON1,EECON1_WREN); // Konec zapisu
bit_clear(*EECON1,EECON1_EEPGD); // Uz ne pamet programu (bezpecnost)
}
 
 
// Zapise data Data na adresu Adr a provede posun na dalsi adresu, zapisuje se jen do
// dovolene oblasti pameti a jen v pripade, ze je Mode=1
void WriteDataInc()
// Data - co se zapisuje
// Adr - kam se zapisuje, po zapisu se adresa posouva
{
if (~Mode) return; // Neni rezim zapisu
if ( (Adr>=STARTMEM) & (Adr<=ENDMEM) & (input(POWER_PIC)==0) )
{
WriteData();
Adr++;
}
else
{
Error=1;
}
}
 
 
// Najdi zacatek zadaneho cisla skladby. Promenna Adr ukazuje na zacatek skladby.
// Neni-li skladba nalezena ukazuje Adr na koncovou znacku (0x3FFF) posledni skladby
// nebo na konec pameti.
int1 Find()
// CisloSkladby - poradove cislo skladby
// Adr - adresa zacatku skladby
{
Adr=STARTMEM-1; // Od zacatku oblasti pro skladby
for(;1;)
{
Adr++;
ReadData(); // Precti data
if (Data==ENDOFDATA) return 1; // Priznak konce dat
if (Adr==ENDMEM+1) return 1; // Uz jsme prosli celou pamet
if ((Data&MASKBEGIN)==DATABEGIN) // Priznak zacatku skladby
{
CisloSkladby--; // Otestuj pocitadlo skladeb
if (CisloSkladby==0) return 0; // Je to tato skladba
}
}
}
 
 
// Zahraj jednu notu
void PlayData()
// Data = zakodovana nota
// Tempo, Octava, Pause = parametry hrane noty
{
SoundNote((int8)Data&0xF,Octava+(((int8)Data>>4)&0x7),Tempo*((Data>>7)&0x3F)); // Zahraj notu
SoundNote(SOUND_Space,0,Pause); // Zahraj mezeru mezi notami
}
 
 
// Zahraj skladbu od zadane adresy v promenne Adr.
void Play()
// CisloSkladby - cislo skladby k hrani
{
if (Find()) // Najdi zacatek skladby v pameti skladeb
{
return; // Skladba nenalezena
}
 
Tempo=100; // Default delka noty
Pause=100; // Default mezera mezi notami
 
Octava=Data&~MASKBEGIN; // Posunuti oktav (povinna soucast zacatku skladby)
Adr++;
 
for (;1;)
{
if (Adr==ENDMEM+1) return; // Konec pametove oblasti
ReadData(); // Vezmi data
Adr++; // Posun adresu
if (Data==ENDOFDATA) return; // Konec dat
if ((Data&MASKBEGIN)==DATABEGIN) return; // Zacatek dalsi skladby
if ((Data&MASKTEMPO)==DATATEMPO) Tempo=Data&~DATATEMPO; // Paramter TEMPO
if ((Data&MASKPAUSE)==DATAPAUSE) Pause=Data&~DATAPAUSE; // Parametr PAUSE
if ((Data&MASKNOTE)==0) // Nota
{
PlayData(); // Zahraj notu
}
}
}
 
 
// Vycisli cislo z bufferu, posune ukazovatko na prvni nezpracovany znak, preskakuje mezery
int16 Number(char line[], int *a, len)
{
int16 Data;
char c;
 
while((line[*a]==' ')&(*a<len)) // Vynech mezery na zacatku
(*a)++; // Posouvej ukazovatko
 
Data=0;
while (1)
{
if (*a>=len) return Data; // Konec retezce
c=line[*a]; // Vezmi znak z pole
if ((c<'0')|(c>'9')) return Data; // Koncime pokud znak neni cislice
Data = Data * 10 + (c-'0'); // Pouzij cislici
(*a)++; // Dalsi znak
}
}
 
 
// Vyhledej klicove slovo a vrat jeho zkraceny kod
// Pokud slovo neexistuje vraci -1
// Format definice - retezec ukonceny nulou + zastupny znak, na konci prazdny retezec (nula)
const char KeyWords[] =
{
'P','L','A','Y',0, 'P',
'E','R','A','S','E',0, 'E',
'T','E','M','P','O',0, 't',
'P','A','U','S','E',0, 'p',
'B','E','G','I','N',0, 'B',
'T','E','S','T',0, 'b',
'E','N','D',0, 'Z',
'C',0. SOUND_C,
'C','I','S',0, SOUND_Cis,
'D',0, SOUND_D,
'D','I','S',0, SOUND_Dis,
'E',0, SOUND_E,
'F',0, SOUND_F,
'F','I','S',0, SOUND_Fis,
'G',0, SOUND_G,
'G','I','S',0, SOUND_Gis,
'A',0, SOUND_A,
'A','I','S',0, SOUND_Ais,
'H',0, SOUND_H,
'S','P','A','C','E',0, SOUND_Space
};
signed int Word(char line[], unsigned int8 *a, len)
{
unsigned int8 i; // Index do pole klicovych slov
unsigned int8 j; // index do zpracovavane radky
 
while((line[*a]==' ')&(*a<len)) // Vynech mezery na zacatku
(*a)++; // Posouvej ukazovatko
 
for (i=0;i<sizeof(KeyWords);) // Slova ze slovniku
{
for (j=*a;(j<len)&(KeyWords[i]!=0)&(KeyWords[i]==line[j]);i++,j++) // Znaky ze slova
{
}
if ((KeyWords[i]==0)&((line[j]==' ')|(j==len)))
{
if (j>=len) j=len-1; // Korekce abychom se nedostali za konec retezce
*a=j+1; // Posun ukazovatko za zpracovane slovo
 
return KeyWords[i+1]; // Vrat zastupnou hodnotu z tabulky klicovych slov
}
while(KeyWords[i]!=0) i++; // Preskoc zbytek slova v tabulce
i++; // Preskoc oddelovac
i++; // Preskoc polozku se zastupnou hodnotou
}
return -1; // Prosli jsme cely slovnik a nedoslo ke shode
}
 
 
// Programovani pres RS232
#define LINELEN 40 // Delka radky pro RS232
#define CR 0x0D // Odradkovani
#define BS 0x08 // Back Space
void Download()
{
char line[LINELEN]; // Buffer na radku
unsigned char c; // Znak
unsigned int8 a; // Ukazovatko do bufferu
unsigned int8 len; // Delka retezce v radce
unsigned int8 Oct; // Cislo oktavy u noty
 
output_low(POWER_386); // Zapni napajeni zesilovace
SoundNote(SOUND_Space,3,10); // Mezera
Beep=SoundPGM;
Error=0;
SpecBeep(); // Pipni na znameni vstupu do programovani
 
Tempo=100; // Default hodnoty
Pause=100;
Octava=0;
Mode=0; // Mod hrani
Oct=0;
a=0; // Na zacatku je radka prazdna
 
for(;input(POWER_PIC)==0;) // Opakuj vse dokud je PGM rezim
{
Loop:
c=Getc(); // Vezmi znak ze seriovky
if (c>=0x80) goto Loop; // Ignoruj znaky nad ASCII
if (c>=0x60) c=c-0x20; // Preved velka pismena na velka pismena
if ((c==CR)|(c=='/')) // Konec radky nebo komentar
{
while (c!=CR) c=Getc(); // Zpracuj znaky komentare
len=a; // Zapamatuj si delku radky
a=0; // Postav se na zacatek radky
Beep=SoundEndOfLine; // Default zuk na konci radky
// Zpracovani radky
while(a<len)
{
c=Word(line,&a,len);
if (c==-1) // Nezname klicove slovo
{
if (a<len) // Nejsme uz na konci radky ?
{
if ((line[a]>='0')&(line[a]<='9')) // Stojime na cislici -> je to cislo
{
// Oct=Number(line,&a,len)&0x7; // tohle nefunguje protoze je chyba v prekladaci
Oct=Number(line,&a,len); // prekladac prepoklada, z W obsahuje spodni bajt vysledku
Oct&=0x7; // ale k navratu pouziva RETLW 0 coz smaze W !
}
else // Stojime na pismenu nebo oddelovaci
{
if (line[a]!=' ') Error=1; // Neni to oddelovac - chyba
a++; // Preskocim 1 znak (a kdyz to nepomuze dostanu se zase sem)
}
}
}
else if (c=='P') // Play
{
CisloSkladby=Number(line,&a,len);
Mode=0;
Play();
Beep=SoundPGM;
}
else if (c=='E') // Erase
{
Mode=0;
Erase();
Beep=SoundPGM;
}
else if (c=='t') // Tempo
{
Tempo=Number(line,&a,len)&~MASKTEMPO;
if (Tempo==0) Tempo=100;
Data=Tempo|DATATEMPO;
WriteDataInc(); // Podmineny zapis do FLASH a posun na dalsi adresu
}
else if (c=='p') // Pause
{
Pause=Number(line,&a,len)&~MASKPAUSE;
if (Pause==0) Pause=100;
Data=Pause|DATAPAUSE;
WriteDataInc(); // Podmineny zapis do FLASH a posun na dalsi adresu
}
else if (c=='B') // Begin
{
CisloSkladby=~0; // Neplatne cislo skladby
Find(); // najde konec posledni skladby
Octava=Number(line,&a,len)&~MASKBEGIN;
Data=DATABEGIN|Octava; // Zacatecni znacka
Mode=1; // Mod zapisu do FLASH pameti
WriteDataInc(); // Podmineny zapis do FLASH a posun na dalsi adresu
}
else if (c=='b') // Test
{
Octava=Number(line,&a,len)&~MASKBEGIN;
Mode=0;
}
else if (c=='Z') // End
{
Mode=0;
}
else // Nota
{
Data=Number(line,&a,len); // Delka noty (nepovinna)
Data&=0x3F; // Jen platny rozsah
if (Data==0) Data++; // Je-li nulova delka - dej jednotkovou
Data<<=7; // Delka
Data|=c; // Nota
Data|=(Oct<<4); // Oktava
WriteDataInc(); // Podmineny zapis do FLASH a posun na dalsi adresu
if (~Mode)
{
PlayData(); // Zahraj notu
Beep=0; // Po zahrani noty uz nepipej na konci radky
}
}
}
a=0; // Radka zpracovana, nuluj jeji delku
SpecBeep(); // Pipni
goto Loop;
}
if ((c==BS)&(a>0)) {a--;goto Loop;} // Smaz znak
if ((c==',')|(c<=' ')) c=' '; // Vsechny ostatni ridici znaky i carka jsou oddelovac
if (a<LINELEN) line[a++]=c; // Zapis znak do bufferu a posun ukazovatko
}
}
 
 
// Tabulka pro prekodovani tlacitek
const int8 KeyTranslate[16] = {0, 1, 2, 5, 3, 6, 8, 11, 4, 7, 9, 12, 10, 13, 14, 15};
 
void main()
{
Start:
 
// Inicializace
port_b_pullups(TRUE); // Zapni pull-up odpory na portu B
set_tris_a(0b00001000); // Nastav nepouzite vyvody jako vystupy
set_tris_b(0b11110000); // 1 znamena vstup
*0x9F = 6; // Vsechny vstupy jsou digitalni
 
// Test na rezim programovani
if ((input(POWER_PIC)==0)&(input(RXD)==0)) // Podminka programovani
Download(); // Pripojen RS232 a propojka na PGM
 
// Zapnuti napajeni
output_low(POWER_PIC); // Pripoj GND pro procesor
SoundNote(SOUND_Space,3,10); // Mezera
output_low(POWER_386); // Zapni napajeni zesilovace
SoundNote(SOUND_Space,3,100); // Mezera (jinak se chybne detekuje tlacitko)
 
// Cteni tlacitek
#use FAST_IO(B)
CisloSkladby=(input_b() >> 4) ^ 0xFF & 0xF; // Precti stav tlacitek
#use STANDARD_IO(B)
CisloSkladby=KeyTranslate[CisloSkladby]; // Prekoduj je do binarniho kodu
 
// Prehrani skladby
Play(); // Zahraj skladbu
 
// Po odehrani usni a cekej na zmacknuti tlacitka
#use FAST_IO(B)
if (input_B()); // Precti stav portu B (vuci tomuto stavu se bude hlidat zmena)
#use STANDARD_IO(B)
bit_clear(*0xB,0); // Nuluj priznak preruseni od zmeny stavu portu B
enable_interrupts(INT_RB); // Povol preruseni od zmeny stavu portu B
 
output_high(POWER_386); // Vypni napajeni zesilovace
output_float(POWER_PIC); // Odpoj GND
Sleep(); // Usni aby byla minimalni klidova spotreba
 
disable_interrupts(INT_RB); // Zakaz preruseni od portu
goto Start; // Po probuzeni skoc na zacatek
}
/Designs/MB01B/SW/1_00/sound_t1.c
0,0 → 1,202
// Knihovna pro generovani hudebnich zvuku dane frekvence a delky nebo
// dane noty temperovaneho ladeni a delky.
//
// Pro gnerovani pouziva casovac T0, T1 a jednotku CCP1.
//
// POZOR -- POZOR -- POZOR
// Pri nizsi frekvenci XTALu (nez asi 5MHz) je rezie preruseni tak velka, ze spotrebuje
// veskery strojovy cas a uz nedojde k ukonceni rozehraneho tonu vyssi frekvence (z oktavy 7
// nebo nad cca 8KHz). Resenim je pouzit vlastni INT proceduru s minimalni rezii.
//
// (c)miho 2004
//
// Historie
// 1.00 Uvodni verze
 
 
// Konfiguracni parametry
//#define SOUND_HI PIN_xx // Pozitivni vystup
//#define SOUND_LO PIN_xx // Komplementarni vystup
#ifndef SOUND_CLOCK
#define SOUND_CLOCK 4000000 // Frelvence krystalu v Hz
#endif
 
 
// Definice hudebnich tonu (not) pro proceduru SoundNote()
#define SOUND_C 0
#define SOUND_Cis 1
#define SOUND_D 2
#define SOUND_Dis 3
#define SOUND_E 4
#define SOUND_F 5
#define SOUND_Fis 6
#define SOUND_G 7
#define SOUND_Gis 8
#define SOUND_A 9
#define SOUND_Ais 10
#define SOUND_H 11
#define SOUND_Space 12 // Pomlka
 
 
// Prototypy verejnych procedur
 
void SoundBeep(unsigned int16 Frequency, unsigned int16 Duration);
// Predava se frekvence v Hz a doba trvani v ms (0 znamena ticho)
 
void SoundNote(unsigned int8 Note, Octave, unsigned int16 Duration);
// Predava se cislo noty (0 je C), posunuti v oktavach (0 nejnizsi ton,
// SOUND_Space je ticho), doba trvani v ms
 
// Alternativni makra pro generovani konstatnich tonu
// SoundBeepMacro(Frequency, Duration) - frekvence nesmi byt 0
// SoundNoteMacro(Note, Octave, Duration) - nepodporuje SOUND_Space
// SoundSpaceMacro(Duration) - hraje ticho
 
// Privatni cast
 
 
#int_ccp1
void IntCCP1()
// Preruseni od jednotky CCP1 generuje vystup
{
volatile int1 Data; // Posledni stav vystupu
output_bit(SOUND_HI,Data); // Nastav vystup
output_bit(SOUND_LO,~Data);
Data=~Data; // Otoc stav vystupu
}
 
 
#if SOUND_CLOCK < (65535*32*4*2) // < 16.7 MHz
#define SOUND_PRESCALE 1
#elif SOUND_CLOCK < (65535*32*4*2*2) // < 33.6 MHz
#define SOUND_PRESCALE 2
#elif SOUND_CLOCK < (65535*32*4*2*4) // < 67.1 MHz
#define SOUND_PRESCALE 4
#elif SOUND_CLOCK < (65535*32*4*2*8) // < 134 MHz
#define SOUND_PRESCALE 8
#else
#error SOUND_CLOCK Frequency too high
#endif
#bit T0IF=0x0B.2
void SoundBeep(unsigned int16 Frequency, unsigned int16 Duration)
// Predava se frekvence v Hz a doba trvani v ms (0 znamena ticho)
// Rozumne frekvence jsou od 32Hz
{
unsigned int16 Time; // Pocitadlo zlomkoveho casu
 
// Inicializace casovace
if (Frequency!=0) // Frekvence 0 znamena ticho
{
setup_ccp1(CCP_COMPARE_RESET_TIMER);
set_timer1(0);
(int16)CCP_1=SOUND_CLOCK/SOUND_PRESCALE/4/2/Frequency;
#if SOUND_PRESCALE==1
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
#elif SOUND_PRESCALE==2
setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
#elif SOUND_PRESCALE==4
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
#elif SOUND_PRESCALE==8
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
#endif
enable_interrupts(int_ccp1);
enable_interrupts(global);
}
 
// Delka tonu merena casovacem T0 (bez preruseni)
Time=0;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
while (Duration)
{
if (T0IF) // Preteceni T0 - kazdych (1/CLK)*4*256
{
T0IF = 0;
Time += (256*4*1000*2048+SOUND_CLOCK/2)/SOUND_CLOCK;
}
if (Time>>11)
{
Time -= 2048;
Duration--;
}
}
 
// Konec casovace
disable_interrupts(int_ccp1);
disable_interrupts(global);
}
 
 
// Definice casu pulperody pro nejnizsi oktavu, v kvantech casovace T1
// Pulperiody tonu v dalsich oktavach se ziskavaji rotaci vpravo
#define SOUND_Peri_C ((30578*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 30578us
#define SOUND_Peri_Cis ((28862*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 28862us
#define SOUND_Peri_D ((27242*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 27242us
#define SOUND_Peri_Dis ((25713*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 25713us
#define SOUND_Peri_E ((24270*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 24270us
#define SOUND_Peri_F ((22908*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 22908us
#define SOUND_Peri_Fis ((21622*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 21622us
#define SOUND_Peri_G ((20408*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 20408us
#define SOUND_Peri_Gis ((19263*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 19263us
#define SOUND_Peri_A ((18182*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 18182us
#define SOUND_Peri_Ais ((17161*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 17161us
#define SOUND_Peri_H ((16198*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 16198us
 
// Kontrola na delku konstanty (musi byt mensi nez delka citace)
#if SOUND_Peri_C > 65535
#error "SOUND_Peri_C too long (Note C requires delay > 65535 cycles)"
#endif
 
// Casove konstanty pro noty nejnizsi oktavy
const unsigned int16 Table[12] =
SOUND_Peri_C, SOUND_Peri_Cis, SOUND_Peri_D, SOUND_Peri_Dis,
SOUND_Peri_E, SOUND_Peri_F, SOUND_Peri_Fis, SOUND_Peri_G,
SOUND_Peri_Gis, SOUND_Peri_A, SOUND_Peri_Ais, SOUND_Peri_H;
 
 
void SoundNote(unsigned int8 Note, Octave, unsigned int16 Duration)
// Predava se cislo noty (0 je C), posunuti v oktavach (0 nejnizsi ton)
// doba trvani v ms (0 znamena ticho)
// Zahraje zadanou notu v zadane oktave dane delky
{
unsigned int16 Time; // Pocitadlo zlomkoveho casu
 
// Inicializace casovace
if (Note!=SOUND_Space) // Pokud se ma hrat spust hrani
{
setup_ccp1(CCP_COMPARE_RESET_TIMER);
set_timer1(0);
(int16)CCP_1=Table[Note]>>Octave;
#if SOUND_PRESCALE==1
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
#elif SOUND_PRESCALE==2
setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
#elif SOUND_PRESCALE==4
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
#elif SOUND_PRESCALE==8
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
#endif
enable_interrupts(int_ccp1);
enable_interrupts(global);
}
 
// Delka tonu merena casovacem T0 (bez preruseni)
Time=0;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
while (Duration)
{
if (T0IF) // Preteceni T0 - kazdych (1/CLK)*4*256
{
T0IF = 0;
Time += (256*4*1000*2048+SOUND_CLOCK/2)/SOUND_CLOCK;
}
if (Time>>11)
{
Time -= 2048;
Duration--;
}
}
 
// Konec casovace
disable_interrupts(int_ccp1);
disable_interrupts(global);
}
/Designs/MB01B/SW/1_01/16F819.H
0,0 → 1,206
//////// Standard Header file for the PIC16F628 device ////////////////
#device PIC16F819
#nolist
//////// Program memory: 2048x14 Data RAM: 224 Stack: 8
//////// I/O: 16 Analog Pins: 0
//////// Data EEPROM: 112
//////// C Scratch area: 20 ID Location: 2000
//////// Fuses: LP,XT,HS,EC,NOWDT,WDT,NOPUT,PUT,PROTECT,PROTECT_50%
//////// Fuses: PROTECT_75%,NOPROTECT,NOBROWNOUT,BROWNOUT,MCLR,NOMCLR,LVP
//////// Fuses: NOLVP,ER_IO,INTRC_IO,ER,INTRC,CPD,NOCPD
////////
////////////////////////////////////////////////////////////////// I/O
// Discrete I/O Functions: SET_TRIS_x(), OUTPUT_x(), INPUT_x(),
// PORT_B_PULLUPS(), INPUT(),
// OUTPUT_LOW(), OUTPUT_HIGH(),
// OUTPUT_FLOAT(), OUTPUT_BIT()
// Constants used to identify pins in the above are:
 
#define PIN_A0 40
#define PIN_A1 41
#define PIN_A2 42
#define PIN_A3 43
#define PIN_A4 44
#define PIN_A5 45
#define PIN_A6 46
#define PIN_A7 47
 
#define PIN_B0 48
#define PIN_B1 49
#define PIN_B2 50
#define PIN_B3 51
#define PIN_B4 52
#define PIN_B5 53
#define PIN_B6 54
#define PIN_B7 55
 
////////////////////////////////////////////////////////////////// Useful defines
#define FALSE 0
#define TRUE 1
 
#define BYTE int
#define BOOLEAN short int
 
#define getc getch
#define fgetc getch
#define getchar getch
#define putc putchar
#define fputc putchar
#define fgets gets
#define fputs puts
 
////////////////////////////////////////////////////////////////// Control
// Control Functions: RESET_CPU(), SLEEP(), RESTART_CAUSE()
// Constants returned from RESTART_CAUSE() are:
#define WDT_FROM_SLEEP 0
#define WDT_TIMEOUT 8
#define MCLR_FROM_SLEEP 16
#define NORMAL_POWER_UP 24
 
 
////////////////////////////////////////////////////////////////// Timer 0
// Timer 0 (AKA RTCC)Functions: SETUP_COUNTERS() or SETUP_TIMER0(),
// SET_TIMER0() or SET_RTCC(),
// GET_TIMER0() or GET_RTCC()
// Constants used for SETUP_TIMER0() are:
#define RTCC_INTERNAL 0
#define RTCC_EXT_L_TO_H 32
#define RTCC_EXT_H_TO_L 48
 
#define RTCC_DIV_1 8
#define RTCC_DIV_2 0
#define RTCC_DIV_4 1
#define RTCC_DIV_8 2
#define RTCC_DIV_16 3
#define RTCC_DIV_32 4
#define RTCC_DIV_64 5
#define RTCC_DIV_128 6
#define RTCC_DIV_256 7
 
 
#define RTCC_8_BIT 0
 
// Constants used for SETUP_COUNTERS() are the above
// constants for the 1st param and the following for
// the 2nd param:
 
////////////////////////////////////////////////////////////////// WDT
// Watch Dog Timer Functions: SETUP_WDT() or SETUP_COUNTERS() (see above)
// RESTART_WDT()
//
#define WDT_18MS 8
#define WDT_36MS 9
#define WDT_72MS 10
#define WDT_144MS 11
#define WDT_288MS 12
#define WDT_576MS 13
#define WDT_1152MS 14
#define WDT_2304MS 15
 
////////////////////////////////////////////////////////////////// Timer 1
// Timer 1 Functions: SETUP_TIMER_1, GET_TIMER1, SET_TIMER1
// Constants used for SETUP_TIMER_1() are:
// (or (via |) together constants from each group)
#define T1_DISABLED 0
#define T1_INTERNAL 0x85
#define T1_EXTERNAL 0x87
#define T1_EXTERNAL_SYNC 0x83
 
#define T1_CLK_OUT 8
 
#define T1_DIV_BY_1 0
#define T1_DIV_BY_2 0x10
#define T1_DIV_BY_4 0x20
#define T1_DIV_BY_8 0x30
 
////////////////////////////////////////////////////////////////// Timer 2
// Timer 2 Functions: SETUP_TIMER_2, GET_TIMER2, SET_TIMER2
// Constants used for SETUP_TIMER_2() are:
#define T2_DISABLED 0
#define T2_DIV_BY_1 4
#define T2_DIV_BY_4 5
#define T2_DIV_BY_16 6
 
////////////////////////////////////////////////////////////////// CCP
// CCP Functions: SETUP_CCPx, SET_PWMx_DUTY
// CCP Variables: CCP_x, CCP_x_LOW, CCP_x_HIGH
// Constants used for SETUP_CCPx() are:
#define CCP_OFF 0
#define CCP_CAPTURE_FE 4
#define CCP_CAPTURE_RE 5
#define CCP_CAPTURE_DIV_4 6
#define CCP_CAPTURE_DIV_16 7
#define CCP_COMPARE_SET_ON_MATCH 8
#define CCP_COMPARE_CLR_ON_MATCH 9
#define CCP_COMPARE_INT 0xA
#define CCP_COMPARE_RESET_TIMER 0xB
#define CCP_PWM 0xC
#define CCP_PWM_PLUS_1 0x1c
#define CCP_PWM_PLUS_2 0x2c
#define CCP_PWM_PLUS_3 0x3c
long CCP_1;
#byte CCP_1 = 0x15
#byte CCP_1_LOW= 0x15
#byte CCP_1_HIGH= 0x16
////////////////////////////////////////////////////////////////// COMP
// Comparator Variables: C1OUT, C2OUT
// Constants used in setup_comparators() are:
#define A0_A3_A1_A2 4
#define A0_A2_A1_A2 3
#define NC_NC_A1_A2 5
#define NC_NC_NC_NC 7
#define A0_VR_A1_VR 2
#define A3_VR_A2_VR 10
#define A0_A2_A1_A2_OUT_ON_A3_A4 6
#define A3_A2_A1_A2 9
 
#bit C1OUT = 0x1f.6
#bit C2OUT = 0x1f.7
 
////////////////////////////////////////////////////////////////// VREF
// Constants used in setup_vref() are:
#define VREF_LOW 0xa0
#define VREF_HIGH 0x80
#define VREF_A2 0x40
 
////////////////////////////////////////////////////////////////// INT
// Interrupt Functions: ENABLE_INTERRUPTS(), DISABLE_INTERRUPTS(),
// EXT_INT_EDGE()
//
// Constants used in EXT_INT_EDGE() are:
#define L_TO_H 0x40
#define H_TO_L 0
// Constants used in ENABLE/DISABLE_INTERRUPTS() are:
#define GLOBAL 0x0BC0
#define INT_RTCC 0x0B20
#define INT_RB 0x0B08
#define INT_EXT 0x0B10
#define INT_TBE 0x8C10
#define INT_RDA 0x8C20
#define INT_TIMER1 0x8C01
#define INT_TIMER2 0x8C02
#define INT_CCP1 0x8C04
#define INT_LCD 0x8C80
#define INT_COMP 0x8C40
#define INT_EEPROM 0x0B40
#define INT_TIMER0 0x0B20
 
// Definice reistru pro pristup k EEPROM
#define EEDATA 0x010C
#define EEADR 0x010D
#define EEDATAH 0x010E
#define EEADRH 0x010F
#define EECON1 0x018C
#define EECON1_RD 0
#define EECON1_WR 1
#define EECON1_WREN 2
#define EECON1_WRERR 3
#define EECON1_FREE 4
#define EECON1_EEPGD 7
#define EECON2 0x018D
#define PIR2 0x000D
#define PIR2_EEIF 4
#define PIE2 0x008D
#define PIR2_EEIE 4
 
#list
/Designs/MB01B/SW/1_01/DATA.C
0,0 → 1,75
// Tento soubor definuje vse potrebne pro ulozeni skladeb do pameti programu.
// Dale definuje pislusna makra pro snadne definice. Tyto definice jsou voleny
// zamerne tak, aby mohl byt pouzit stejny soubor s definici skladby jak
// pro vlozeni primo do firmwaru v dobe prekladu tak i k dodatecnemu nahrani
// skladby pres seriovou linku.
 
// Definice hranic pameti pro ulozeni pisnicek
#define STARTMEM 0x600 // Zde zacina pametoa oblast pro pisnicky
#define ENDMEM 0x7ff // Zde konci pametova oblast pro pisnicky
 
// Definice konstant pro kodovani dat
#define ENDOFDATA 0x3FFF // Priznak konce pisnicek (prazdna pamet)
#define DATABEGIN 0x2000 // Kod zacatku skladby
#define MASKBEGIN 0x3800
#define DATATEMPO 0x2800 // Kod pro nastaveni tempa
#define MASKTEMPO 0x3800
#define DATAPAUSE 0x3000 // Kod pro nastaveni mezery mezi notami
#define MASKPAUSE 0x3800
#define MASKNOTE 0x2000 // Nejvissi bit 0 urcuje, ze jde o notu
 
// Pseudomakra pro jednoduchy zapis skladeb do zdrojaku jazyka C
#define BEGIN DATABEGIN+ // Zacatek pisnicky + posunuti oktav
#define TEMPO DATATEMPO+ // Delka nejskratsi noty v ms
#define PAUSE DATAPAUSE+ // Delka mezery mezi notami
#define END // Konec skladby, zde nic neznamena
 
// Pseudomakra pro zapis not, zapisuje se cislo oktavy, nota, delka noty
#define C *16 + SOUND_C + 128 *
#define Cis *16 + SOUND_Cis + 128 *
#define D *16 + SOUND_D + 128 *
#define Dis *16 + SOUND_Dis + 128 *
#define E *16 + SOUND_E + 128 *
#define F *16 + SOUND_F + 128 *
#define Fis *16 + SOUND_Fis + 128 *
#define G *16 + SOUND_G + 128 *
#define Gis *16 + SOUND_Gis + 128 *
#define A *16 + SOUND_A + 128 *
#define Ais *16 + SOUND_Ais + 128 *
#define H *16 + SOUND_H + 128 *
#define Space SOUND_Space + 128 *
 
// Pametova oblast
#ORG 0x600,0x7FF {} // Vyhrazeni oblasti pameti pro ulozeni pisnicek
#ROM 0x600 = { // Naplneni oblasti pameti daty
 
// Pisnicky jako soucast firwaru se vkladaji sem
// Museji mit stejny format jako uvedene priklady aby zafungovaly makra
#include "Skladby\TheFinalSoundDown.txt"
#include "Skladby\BednaOdWhisky.txt"
#include "Skladby\KdyzMeBaliZaVojacka.txt"
#include "Skladby\Medvedi.txt"
 
// Koncova znacka a konec oblasti pro skladby
ENDOFDATA
}
 
// Zruseni definic maker pro definici skladeb
// V dalsim programu uz nebudou potreba
#undef BEGIN
#undef TEMPO
#undef PAUSE
#undef END
#undef C
#undef Cis
#undef D
#undef Dis
#undef E
#undef F
#undef Fis
#undef G
#undef Gis
#undef A
#undef Ais
#undef H
#undef Space
/Designs/MB01B/SW/1_01/MB01A.C
0,0 → 1,515
// Melodicky zvonek MB01A_1_00
//
// Prohram pro melodicky zvonek s pouzitim knihovny Sound_t1.C
//
// (c)miho 2004, pefi 2004
//
// Historie:
// 1.00 Uvodni verze
// 1.01 Zaveden WDT
 
#include <16F819.h> // Definice procesoru
#fuses HS,NOPROTECT,WDT,PUT,NOLVP,NOBROWNOUT,WRT // Definice konfiguracniho slova
 
#define POWER_386 PIN_A4 // L zapne napajeni pro zesilovac LM386
#define POWER_PIC PIN_A3 // L pripoji GND pro procesor PIC
 
#define SOUND_HI PIN_B3 // Akusticky vystup
#define SOUND_LO PIN_B2 // Akusticky vystup
#define SOUND_CLOCK 20000000 // Frekvence hodin
#define SOUND_LowOctave 1 // O oktavu vys protoze mame moc rychly krystal
#define SOUND_WDT 1 // Budeme pouzivat WDT
#include "Sound_T1.c" // Hudebni knihovna
 
#include "Data.c" // Datovy blok pro predpripravene skladby
 
#define RXD PIN_B1 // Port pro RS232
#use delay(CLOCK=20000000,RESTART_WDT) // Konfigurace pro casovani RS232
#use rs232(BAUD=9600,RCV=RXD,RESTART_WDT,INVERT,PARITY=N,BITS=8) // Prenosove parametry RS232
 
 
// Sada globalnich promennych
// --------------------------
// Vyuzivame globalni promenne protoze je to vyhodne z hlediska spotreby zdroju. Usetri
// se vyznmane mnoho pameti programu pri predavani parametru
 
 
unsigned int16 Adr; // Adresovy ukazatel do pameti skladeb
unsigned int16 Data; // Prectena data nebo data pro zapis
unsigned int1 Mode; // 0=rezim testovani, 1=rezim zapisu do FLASH
 
unsigned int16 Tempo; // Tempo (delka nejkratsi skladby v ms)
unsigned int16 Pause; // Delka mezery mezi notami v ms
unsigned int8 Octava; // Posunuti skladby v oktavach
 
unsigned int8 Beep; // Druh pipnuti pro proceduru SoundSpec
unsigned int1 Error; // Priznak chyby
 
unsigned int8 CisloSkladby; // Cislo skladby pro proceduru Find a Play
 
 
// Zvuky, posloupnost zadaneho poctu tonu
#define SoundEndOfLine 0x01 // Kratke pipnuti na konci radky
#define SoundPGM 0x03 // Trilek pri vstupu do rezimu programovani
#define SoundPostPlay 0x03 // Po ukonceni prehravani
#define SoundERASE 0x02 // Zvuk pri smazani bloku FLASH pameti
#define SoundERR 0x05 // Chyba syntaxe
 
void SpecBeep()
// Data - pocet pipnuti, 0 znamena ticho
{
int Oct;
 
if (Error) Beep=SoundERR;
 
for(Oct=2;Beep!=0;Beep--)
{
SoundNote(SOUND_A,Oct++,50);
}
 
Error=0;
}
 
 
// Precti slovo z pameti programu
int16 ReadData()
// Adr - adresa ze ktere se cte
// Data - prectena data
{
int8 a,b; // Pomocne promenne
 
(int8)*EEADR = Adr; // Adresa, spodni cast
(int8)*EEADRH = Adr >> 8; // Adresa, horni cast
bit_set(*EECON1,EECON1_EEPGD); // Pamet programu
bit_set(*EECON1,EECON1_RD); // Operace cteni
#ASM
nop; // Povinne nop
nop;
#ENDASM
a = (int8)*EEDATA; // Prevezmi data
b = (int8)*EEDATAH;
Data=make16(b,a); // Sestav vysledek ze 2 bajtu
}
 
 
// Smazani cele pameti vyhrazene pro skladby
void Erase()
{
for(Adr=STARTMEM; Adr<=ENDMEM; Adr++) // Cela oblast
{
ReadData();
if (Data!=0x3FFF) // Mazu jen bloky, ktere to potrebuji
{
if (input(POWER_PIC)!=0) return; // Nezapisuj pokud neni jumper povoleni programovani
(int8)*EEADR = Adr; // Adresa bloku, spodni cast
(int8)*EEADRH = Adr >> 8; // Adresa bloku, horni cast
bit_set(*EECON1,EECON1_EEPGD); // Pamet programu
bit_set(*EECON1,EECON1_WREN); // Povolit zapis
bit_set(*EECON1,EECON1_FREE); // Operace mazani
(int8)*EECON2 = 0x55; // Povinna sekvence pro zapis
(int8)*EECON2 = 0xAA;
bit_set(*EECON1,EECON1_WR); // Zahajeni mazani
#ASM
nop; // Povinne prazdne instrukce
nop;
#ENDASM
bit_clear(*EECON1,EECON1_WREN); // Uz ne zapis
bit_clear(*EECON1,EECON1_FREE); // Uz ne mazani
bit_clear(*EECON1,EECON1_EEPGD); // Uz ne pamet programu
Beep=SoundERASE;
SpecBeep();
}
}
}
 
 
// Zapis do pameti programu po jednotlivych slovech.
// Soucastka vyzaduje zapis vzdy celych osmi slov najednou. Vyuziva se toho, ze pamet FLASH
// umi zapisovat jen smerem do nuly a tak staci na pozice, ktere zrovna nechceme programovat
// zapsat same jednicky cimz se stav jejich stav nezmeni.
void WriteData()
// Adr - adresa, kam se bude zapisovat
// Data - data, ktera se budou zapisovat
{
int i;
 
bit_set(*EECON1,EECON1_EEPGD); // Pamet programu
bit_set(*EECON1,EECON1_WREN); // Zapis
(int8)*EEADR = Adr & ~3; // Adresa, spodni cast, zaokrouhleno dolu na nasobek 8
(int8)*EEADRH = Adr >> 8; // Adresa, horni cast
for (i=0; i<4; i++)
{
if ((Adr & 3) == i) // Pokud je adresa slova v bloku totozna s pozadovanou
{
(int8)*EEDATA =Data; // Platne slovo, spodni cast
(int8)*EEDATAH=Data >> 8; // Platne slovo, horni cast
}
else // Ostatni bunky nemenime
{
(int8)*EEDATA =0xFF; // Zbytek same jednicky
(int8)*EEDATAH=0xFF;
}
(int8)*EECON2 = 0x55; // Povinna sekvence pro zapis
(int8)*EECON2 = 0xAA;
bit_set(*EECON1,EECON1_WR); // Zahajeni zapisu
#ASM
nop; // Povinne dve prazdne instrukce
nop;
#ENDASM
((int8)*EEADR) ++; // Dalsi slovo
}
bit_clear(*EECON1,EECON1_WREN); // Konec zapisu
bit_clear(*EECON1,EECON1_EEPGD); // Uz ne pamet programu (bezpecnost)
}
 
 
// Zapise data Data na adresu Adr a provede posun na dalsi adresu, zapisuje se jen do
// dovolene oblasti pameti a jen v pripade, ze je Mode=1
void WriteDataInc()
// Data - co se zapisuje
// Adr - kam se zapisuje, po zapisu se adresa posouva
{
if (~Mode) return; // Neni rezim zapisu
if ( (Adr>=STARTMEM) & (Adr<=ENDMEM) & (input(POWER_PIC)==0) )
{
WriteData();
Adr++;
}
else
{
Error=1;
}
}
 
 
// Najdi zacatek zadaneho cisla skladby. Promenna Adr ukazuje na zacatek skladby.
// Neni-li skladba nalezena ukazuje Adr na koncovou znacku (0x3FFF) posledni skladby
// nebo na konec pameti.
int1 Find()
// CisloSkladby - poradove cislo skladby
// Adr - adresa zacatku skladby
{
Adr=STARTMEM-1; // Od zacatku oblasti pro skladby
for(;1;)
{
Adr++;
ReadData(); // Precti data
if (Data==ENDOFDATA) return 1; // Priznak konce dat
if (Adr==ENDMEM+1) return 1; // Uz jsme prosli celou pamet
if ((Data&MASKBEGIN)==DATABEGIN) // Priznak zacatku skladby
{
CisloSkladby--; // Otestuj pocitadlo skladeb
if (CisloSkladby==0) return 0; // Je to tato skladba
}
}
}
 
 
// Zahraj jednu notu
void PlayData()
// Data = zakodovana nota
// Tempo, Octava, Pause = parametry hrane noty
{
SoundNote((int8)Data&0xF,Octava+(((int8)Data>>4)&0x7),Tempo*((Data>>7)&0x3F)); // Nota
SoundNote(SOUND_Space,0,Pause); // Mezera
}
 
 
// Zahraj skladbu od zadane adresy v promenne Adr.
void Play()
// CisloSkladby - cislo skladby k hrani
{
if (Find()) // Najdi zacatek skladby v pameti skladeb
{
return; // Skladba nenalezena
}
 
Tempo=100; // Default delka noty
Pause=100; // Default mezera mezi notami
 
Octava=Data&~MASKBEGIN; // Posunuti oktav (povinna soucast zacatku skladby)
Adr++;
 
for (;1;)
{
if (Adr==ENDMEM+1) return; // Konec pametove oblasti
ReadData(); // Vezmi data
Adr++; // Posun adresu
if (Data==ENDOFDATA) return; // Konec dat
if ((Data&MASKBEGIN)==DATABEGIN) return; // Zacatek dalsi skladby
if ((Data&MASKTEMPO)==DATATEMPO) Tempo=Data&~DATATEMPO; // Paramter TEMPO
if ((Data&MASKPAUSE)==DATAPAUSE) Pause=Data&~DATAPAUSE; // Parametr PAUSE
if ((Data&MASKNOTE)==0) // Nota
{
PlayData(); // Zahraj notu
}
}
}
 
 
// Vycisli cislo z bufferu, posune ukazovatko na prvni nezpracovany znak, preskakuje mezery
int16 Number(char line[], int *a, len)
{
int16 Data;
char c;
 
while((line[*a]==' ')&(*a<len)) // Vynech mezery na zacatku
(*a)++; // Posouvej ukazovatko
 
Data=0;
while (1)
{
if (*a>=len) return Data; // Konec retezce
c=line[*a]; // Vezmi znak z pole
if ((c<'0')|(c>'9')) return Data; // Koncime pokud znak neni cislice
Data = Data * 10 + (c-'0'); // Pouzij cislici
(*a)++; // Dalsi znak
}
}
 
 
// Vyhledej klicove slovo a vrat jeho zkraceny kod
// Pokud slovo neexistuje vraci -1
// Format definice - retezec ukonceny nulou + zastupny znak, na konci prazdny retezec (nula)
const char KeyWords[] =
{
'P','L','A','Y',0, 'P',
'E','R','A','S','E',0, 'E',
'T','E','M','P','O',0, 't',
'P','A','U','S','E',0, 'p',
'B','E','G','I','N',0, 'B',
'T','E','S','T',0, 'b',
'E','N','D',0, 'Z',
'C',0. SOUND_C,
'C','I','S',0, SOUND_Cis,
'D',0, SOUND_D,
'D','I','S',0, SOUND_Dis,
'E',0, SOUND_E,
'F',0, SOUND_F,
'F','I','S',0, SOUND_Fis,
'G',0, SOUND_G,
'G','I','S',0, SOUND_Gis,
'A',0, SOUND_A,
'A','I','S',0, SOUND_Ais,
'H',0, SOUND_H,
'S','P','A','C','E',0, SOUND_Space
};
signed int Word(char line[], unsigned int8 *a, len)
{
unsigned int8 i; // Index do pole klicovych slov
unsigned int8 j; // index do zpracovavane radky
 
while((line[*a]==' ')&(*a<len)) // Vynech mezery na zacatku
(*a)++; // Posouvej ukazovatko
 
for (i=0;i<sizeof(KeyWords);) // Slova ze slovniku
{
for (j=*a;(j<len)&(KeyWords[i]!=0)&(KeyWords[i]==line[j]);i++,j++) // Znaky ze slova
{
}
if ((KeyWords[i]==0)&((line[j]==' ')|(j==len)))
{
if (j>=len) j=len-1; // Korekce abychom se nedostali za konec retezce
*a=j+1; // Posun ukazovatko za zpracovane slovo
 
return KeyWords[i+1]; // Vrat zastupnou hodnotu z tabulky klicovych slov
}
while(KeyWords[i]!=0) i++; // Preskoc zbytek slova v tabulce
i++; // Preskoc oddelovac
i++; // Preskoc polozku se zastupnou hodnotou
}
return -1; // Prosli jsme cely slovnik a nedoslo ke shode
}
 
 
// Programovani pres RS232
#define LINELEN 40 // Delka radky pro RS232
#define CR 0x0D // Odradkovani
#define BS 0x08 // Back Space
 
#separate
void Download()
{
char line[LINELEN]; // Buffer na radku
unsigned char c; // Znak
unsigned int8 a; // Ukazovatko do bufferu
unsigned int8 len; // Delka retezce v radce
unsigned int8 Oct; // Cislo oktavy u noty
 
output_low(POWER_386); // Zapni napajeni zesilovace
SoundNote(SOUND_Space,3,10); // Mezera
Beep=SoundPGM;
Error=0;
SpecBeep(); // Pipni na znameni vstupu do programovani
 
Tempo=100; // Default hodnoty
Pause=100;
Octava=0;
Mode=0; // Mod hrani
Oct=0;
a=0; // Na zacatku je radka prazdna
 
for(;input(POWER_PIC)==0;) // Opakuj vse dokud je PGM rezim
{
Loop:
c=Getc(); // Vezmi znak ze seriovky
if (c>=0x80) goto Loop; // Ignoruj znaky nad ASCII
if (c>=0x60) c=c-0x20; // Preved velka pismena na velka pismena
if ((c==CR)|(c=='/')) // Konec radky nebo komentar
{
while (c!=CR) c=Getc(); // Zpracuj znaky komentare
len=a; // Zapamatuj si delku radky
a=0; // Postav se na zacatek radky
Beep=SoundEndOfLine; // Default zuk na konci radky
// Zpracovani radky
while(a<len)
{
restart_wdt(); // Nuluj watchdog abychom se nezresetovali
c=Word(line,&a,len);
if (c==-1) // Nezname klicove slovo
{
if (a<len) // Nejsme uz na konci radky ?
{
if ((line[a]>='0')&(line[a]<='9')) // Stojime na cislici -> je to cislo
{
// Oct=Number(line,&a,len)&0x7; // tohle nefunguje protoze je chyba v prekladaci
Oct=Number(line,&a,len); // prekladac prepoklada, z W obsahuje spodni bajt vysledku
Oct&=0x7; // ale k navratu pouziva RETLW 0 coz smaze W !
}
else // Stojime na pismenu nebo oddelovaci
{
if (line[a]!=' ') Error=1; // Neni to oddelovac - chyba
a++; // Preskocim 1 znak (a kdyz to nepomuze dostanu se zase sem)
}
}
}
else if (c=='P') // Play
{
CisloSkladby=Number(line,&a,len);
Mode=0;
Play();
Beep=SoundPGM;
}
else if (c=='E') // Erase
{
Mode=0;
Erase();
Beep=SoundPGM;
}
else if (c=='t') // Tempo
{
Tempo=Number(line,&a,len)&~MASKTEMPO;
if (Tempo==0) Tempo=100;
Data=Tempo|DATATEMPO;
WriteDataInc(); // Podmineny zapis do FLASH a posun na dalsi adresu
}
else if (c=='p') // Pause
{
Pause=Number(line,&a,len)&~MASKPAUSE;
if (Pause==0) Pause=100;
Data=Pause|DATAPAUSE;
WriteDataInc(); // Podmineny zapis do FLASH a posun na dalsi adresu
}
else if (c=='B') // Begin
{
CisloSkladby=~0; // Neplatne cislo skladby
Find(); // najde konec posledni skladby
Octava=Number(line,&a,len)&~MASKBEGIN;
Data=DATABEGIN|Octava; // Zacatecni znacka
Mode=1; // Mod zapisu do FLASH pameti
WriteDataInc(); // Podmineny zapis do FLASH a posun na dalsi adresu
}
else if (c=='b') // Test
{
Octava=Number(line,&a,len)&~MASKBEGIN;
Mode=0;
}
else if (c=='Z') // End
{
Mode=0;
}
else // Nota
{
Data=Number(line,&a,len); // Delka noty (nepovinna)
Data&=0x3F; // Jen platny rozsah
if (Data==0) Data++; // Je-li nulova delka - dej jednotkovou
Data<<=7; // Delka
Data|=c; // Nota
Data|=(Oct<<4); // Oktava
WriteDataInc(); // Podmineny zapis do FLASH a posun na dalsi adresu
if (~Mode)
{
PlayData(); // Zahraj notu
Beep=0; // Po zahrani noty uz nepipej na konci radky
}
}
}
a=0; // Radka zpracovana, nuluj jeji delku
SpecBeep(); // Pipni
goto Loop;
}
if ((c==BS)&(a>0)) {a--;goto Loop;} // Smaz znak
if ((c==',')|(c<=' ')) c=' '; // Vsechny ostatni ridici znaky i carka jsou oddelovac
if (a<LINELEN) line[a++]=c; // Zapis znak do bufferu a posun ukazovatko
}
}
 
 
// Tabulka pro prekodovani tlacitek
const int8 KeyTranslate[16] = {0, 1, 2, 5, 3, 6, 8, 11, 4, 7, 9, 12, 10, 13, 14, 15};
 
void main()
{
Start:
 
if (restart_cause()==WDT_FROM_SLEEP) // Osetreni probuzeni od WDT
{
sleep();
}
// Inicializace WDT
// setup_wdt(WDT_16MS); // nelze pouzit, zabira 15 instukci
#asm
bsf 0x03,5 // banka 1 nebo 3 aby se mohlo k OPTION registu
bcf 0x81,3 // WDT primo tedy 16ms
#endasm
 
// Inicializace
port_b_pullups(TRUE); // Zapni pull-up odpory na portu B
set_tris_a(0b00001000); // Nastav nepouzite vyvody jako vystupy
set_tris_b(0b11110000); // 1 znamena vstup
*0x9F = 6; // Vsechny vstupy jsou digitalni
 
// Test na rezim programovani
if ((input(POWER_PIC)==0)&(input(RXD)==0)) // Podminka programovani
Download(); // Pripojen RS232 a propojka na PGM
 
// Zapnuti napajeni
output_low(POWER_PIC); // Pripoj GND pro procesor
SoundNote(SOUND_Space,3,10); // Mezera
output_low(POWER_386); // Zapni napajeni zesilovace
SoundNote(SOUND_Space,3,100); // Mezera (jinak se chybne detekuje tlacitko)
 
// Cteni tlacitek
#use FAST_IO(B)
CisloSkladby=(input_b() >> 4) ^ 0xFF & 0xF; // Precti stav tlacitek
#use STANDARD_IO(B)
CisloSkladby=KeyTranslate[CisloSkladby]; // Prekoduj je do binarniho kodu
 
// Prehrani skladby
Play(); // Zahraj skladbu
 
// Po odehrani usni a cekej na zmacknuti tlacitka
#use FAST_IO(B)
if (input_B()); // Precti stav portu B (vuci tomuto stavu se bude hlidat zmena)
#use STANDARD_IO(B)
bit_clear(*0xB,0); // Nuluj priznak preruseni od zmeny stavu portu B
enable_interrupts(INT_RB); // Povol preruseni od zmeny stavu portu B
 
output_high(POWER_386); // Vypni napajeni zesilovace
output_float(POWER_PIC); // Odpoj GND
 
Sleep(); // Usni aby byla minimalni klidova spotreba
 
disable_interrupts(INT_RB); // Zakaz preruseni od portu
goto Start; // Po probuzeni skoc na zacatek
}
/Designs/MB01B/SW/1_01/MB01A.HEX
0,0 → 1,239
:1000000000308A00952D0000FF00030E8301A1003F
:100010007F08A0000A08A8008A01A00E0408A20018
:100020007708A3007808A4007908A5007A08A6003C
:100030007B08A700831383128C308400001D2228C4
:100040000C19CB28220884002308F7002408F800A4
:100050002508F9002608FA002708FB0028088A006E
:10006000210E8300FF0E7F0E09000A108A100A116C
:1000700082074E349534ED348C34043485348D3419
:100080007D3481347634DB346F3493346934A63470
:1000900063340E345E34C7345834CB34533417349D
:1000A0004F340A108A100A11820750344C344134FC
:1000B0005934003450344534523441345334453487
:1000C00000344534543445344D3450344F340034C6
:1000D000743450344134553453344534003470341E
:1000E00042344534473449344E3400344234543475
:1000F0004534533454340034623445344E3444343B
:1001000000345A34433400340034433449345334D3
:100110000034013444340034023444344934533418
:100120000034033445340034043446340034053498
:1001300046344934533400340634473400340734E9
:1001400047344934533400340834413400340934DA
:1001500041344934533400340A34483400340B34C5
:100160005334503441344334453400340C340A1091
:100170008A100A1182070034013402340534033432
:10018000063408340B340434073409340C340A348C
:100190000D340E340F347218CF288611D0288615EE
:1001A00083168611721CD82883120611DA2883164A
:1001B00083120615831606110130F20683120C1104
:1001C0008A11222869080C3C031909290B30970071
:1001D0008F018E010310690DF700EF006F0A3520C3
:1001E000FA006F083520F0007A08F10096007008D8
:1001F00095006A08F700031902290310960C950C64
:10020000F70BFD289530900083160C15C030831233
:100210008B04EE01ED0183160108C0390838810016
:1002200083126B086C04031933290B1D1C290B1155
:100230006930ED070318EE0AFA016E0CF900F90CAB
:10024000F90C1F30F90579087A04031931290030B7
:10025000ED020830031C0930EE026B080319EC03B1
:10026000EB036400112983160C1183120B138B13FB
:100270008B1B37290034AD1C3F290530B3000230F9
:10028000E100B308031951296108E10AE2000930CD
:10029000E9006208EA00EC013230EB00E220B3032F
:1002A0004129AD1000340830F7008316861464002D
:1002B000831286185D2983165729E101F7176E29E5
:1002C000F7136E290310861C0314E10C77176E29AF
:1002D0007713F70B62296108F8007A29A730F71B1A
:1002E0002D30F800F80B72290000F71B6029771BEE
:1002F0006829622900341030F700FA01EC01E90C9A
:10030000E80C031C89296A08FA070318EC0A6B0831
:10031000EC07EC0CFA0CF90CF80CF70B7F29003405
:10032000620884006108000784000008203C03196B
:100330009B2900309C290130E90062088400630891
:100340000002031CA5290030A62901306905003AE6
:100350000319AE2962088400800A9029E501E401AE
:100360006208840063080002031CBB296408F800CB
:100370006508F900EE29620884006108000784001E
:100380000008E60066082F3C0318C8290030C92978
:100390000130E7006608393C031CD0290030D12920
:1003A00001306704003A0319DA296408F800650887
:1003B000F900EE296508E9006408E800EB010A305D
:1003C000EA007B21303066027807E4007908E50016
:1003D0000318E50A62088400800AB029003429085D
:1003E00003178D0003132A0803178F0083168C1739
:1003F0000C140000000083120C080313E100031723
:100400000E080313E2006208AC006108AB00003480
:100410000530AA00FF30A900A90A0319AA0AEF2192
:100420002B0F192A2C083F3C031D192A0130F80014
:10043000362AA908031D232A2A08083C031D232A5B
:100440000130F800362A2B080039E1002C08383931
:10045000E200E108031D352A6208203C031D352A0D
:10046000B40B352A0030F800362A0C2A00342B0849
:100470000F39E1002B0EF7000F30F7057708073929
:100480003207E3002C0CE5002B0CE400E50CE40C37
:10049000E50CE40CE50CE40CE50CE40CE50CE40CD8
:1004A000E50CE40C0130E50564083F39F700650808
:1004B0000039FA007708E6007A08E7002F08E9001B
:1004C0002E08E8007A08EB007708EA007B2179081B
:1004D000E8007808E7006108E9006308EA007908A5
:1004E000EC007808EB00E2200C30E900EA0131086A
:1004F000EC003008EB00E22000340822F808031971
:10050000822ADF2AAF016430AE00B101B0002B08AF
:10051000B200A90A0319AA0AA908031D942A2A08E5
:10052000083C031D942ADF2AEF21A90A0319AA0A0D
:100530002B0F9F2A2C083F3C031D9F2ADF2A2B08E4
:100540000039E1002C083839E200E108031DAD2A2A
:100550006208203C031DAD2ADF2A2B080039E10088
:100560002C083839E200E108031DBF2A6208283C44
:10057000031DBF2A2B08AE002C08D739AF002B086B
:100580000039E1002C083839E200E108031DD12AC6
:100590006208303C031DD12A2B08B0002C08CF394B
:1005A000B1002B080039E1002C082039E200E108F5
:1005B000031DDE2AE208031DDE2A37228C2A0034BE
:1005C0002D18E32A4A2B2A08053C031CE92A00308F
:1005D000EA2A0130E1002A08073C0318F12A00301A
:1005E000F22A01306105E20083168515003083127E
:1005F00085190130003A0319FF2A0030002B013021
:100600006205003A0319492B831603178C170C1542
:10061000831203132908FC3903178D0003132A08DA
:1006200003178F000313E1016108033C031C3F2BF8
:1006300029080339E2002A080039E3006108620250
:10064000031D2E2BE308031D2E2B2B0803178C00F4
:1006500003132C0803178E00322B0313FF300317EC
:100660008C008E00553083168D00AA308D008C14BE
:100670000000000083128D0A0313E10A142B831675
:1006800003170C118C1383120313A90A0319AA0A66
:100690004A2BAD14003483160512831205120C3058
:1006A000E9000330EA00EC010A30EB00E2200330FD
:1006B000B300AD103B21AF016430AE00B101B0001A
:1006C000B2012D10E001DE01831685150030831282
:1006D00085190130003A031D942D53217808DD005F
:1006E0005D087F3C0318752B6D2B5D085F3C03187C
:1006F0007B2B2030DD025D080D3C0319812B00307F
:10070000822B0130E1005D082F3C0319892B00305A
:100710008A2B01306104003A0319602D5D080D3CFD
:100720000319962B53217808DD008E2B5E08DF001D
:10073000DE010130B3005F085E0203185D2D640026
:100740003530E1005E30E2005F08E30062088400BB
:100750006108000784000008203C0319B12B003019
:10076000B22B0130E8006208840063080002031C19
:10077000BB2B0030BC2B01306805003A0319C42B99
:1007800062088400800AA62BE4016408613C031C13
:10079000302C620884000008E50063086502031C31
:1007A000D32B0030D42B0130E60064085120003AEE
:1007B000031DDC2B0030DD2B01306605E8006408EA
:1007C0005120E900610865078400000869020319E7
:1007D000EB2B0030EC2B01306805003A0319F42BA9
:1007E0006408E40AE50ACD2B64085120003A031995
:1007F000FB2B0030FC2B0130E7006108650784000B
:100800000008203C0319062C0030072C0130E900B9
:100810006308650203190E2C00300F2C01306904A7
:100820006705003A0319262C63086502031C1B2C7C
:1008300001306302E5006208840001306507800032
:10084000013064075120F800F800322C6408512070
:10085000003A03192D2CE40A262CE40AE40AC52BDD
:10086000FF30F8007808DD005D08FF3C031D6B2CAD
:100870005F085E0203186A2C35305E0784000008AA
:100880002F3C031C452C0030462C0130E200353053
:100890005E0784000008393C0318502C0030512CAE
:1008A00001306205003A0319612C3530E1005E30F9
:1008B000E2005F08E30090217808E0000730E005DF
:1008C0006A2C35305E0784000008203C0319692C2F
:1008D000AD14DE0A5C2D5D08503C031D7D2C3530C7
:1008E000E1005E30E2005F08E30090217808B40088
:1008F0002D107D220330B3005C2D5D08453C031DA7
:10090000BB2C2D100630AA00A9012A08073C031CA5
:10091000B82CEF212B0F902C2C083F3C0319B42C42
:10092000831685150030831285190130003A0319AA
:100930009A2CB82C290803178D0003132A080317D3
:100940008F0083168C170C150C1655308D00AA30AD
:100950008D008C14000000000C110C128C1302305E
:1009600083120313B3003B21A90A0319AA0A852C99
:100970000330B3005C2D5D08743C031DDB2C353067
:10098000E1005E30E2005F08E30090217808AE00ED
:100990007908C739AF00AE08031DD42CAF08031D7A
:1009A000D42CAF016430AE002E08AB002F082838DD
:1009B000AC00E0225C2D5D08703C031DFB2C353043
:1009C000E1005E30E2005F08E30090217808B000AB
:1009D0007908C739B100B008031DF42CB108031D14
:1009E000F42CB1016430B0003008AB00310830386D
:1009F000AC00E0225C2D5D08423C031D122DFF304F
:100A0000B40008223530E1005E30E2005F08E30008
:100A100090217808B2003208AB002030AC002D14D1
:100A2000E0225C2D5D08623C031D212D3530E10084
:100A30005E30E2005F08E30090217808B2002D10DC
:100A40005C2D5D085A3C031D272D2D105C2D353083
:100A5000E1005E30E2005F08E30090217908AC001D
:100A60007808AB003F30AB050030AC05AB08031D88
:100A70003F2DAC08031D3F2DAB0A0319AC0AAB0D8B
:100A8000AC0DAB0DAC0DAB0DAC0DAB0DAC0DAB0DA2
:100A9000AC0DAB0DAC0DAB0DAC0D8030AB055D08F6
:100AA000AB04600EF700F030F7057708AB04E022E6
:100AB0002D185C2D3722B3019B2BDE013B216D2BC2
:100AC0005D08083C0319662D0030672D0130E100F8
:100AD000DE08031D6D2D00306E2D01306105003ADA
:100AE0000319742DDE036D2B5D082C3C03197A2D40
:100AF00000307B2D0130E1005D08203C0318822D81
:100B00000030832D01306104003A0319892D203013
:100B1000DD005E08273C031C932D5E08DE0A353E8F
:100B200084005D088000642BCB2D84011F30830579
:100B3000073083169F00051083120510030818392B
:100B4000003A031DA42D63008316831681118113BF
:100B500008308500F030860006309F008515003093
:100B6000831285190130003A0319B82D0030B92DD0
:100B70000130B600831686140030831286180130C7
:100B8000003A0319C52D0030C62D01303605003A54
:100B90000319CB2D4B2B83168511831285110C3035
:100BA000E9000330EA00EC010A30EB00E220831692
:100BB0000512831205120C30E9000330EA00EC0143
:100BC0006430EB00E220060EF7000F30F7057708DF
:100BD0000F3AB4003408B720F800B4007D220608AC
:100BE000003A0319F32D0B108B158316051283128F
:100BF000051683168515630083128B119E2D6300E5
:100C000003206428643099009700190212020C0135
:100C10009A0099001A01190117020C019A00990013
:100C20001A0212020C019700950017011501140118
:100C3000170115020C019400950017020C01950094
:100C40009700190117011501140112021A02190265
:100C50000C0199009A009900970019020C010220DA
:100C6000642864301901200124012901270224018C
:100C70002401290127012401220124020C02190167
:100C80002001240129012701270124012401190140
:100C900024011B01240119020C0219012001240165
:100CA000290127012701240229012701240122010A
:100CB00024020C012401190120012401290127012A
:100CC000240224012901290128012B0129020C04F5
:100CD00024012901290129012801260129022901CC
:100CE0002B012B0129012B013101290224012901AA
:100CF00029012901280126012901290129012B01A6
:100D00002B012901280129020C01240129012901B3
:100D1000290128012601290229012B012B01290182
:100D20002B0131012902240129012901290128016E
:100D3000260129010C0129012B012B012901280180
:100D40002904270129042701290402209628643058
:100D50009900A000A400A200A0009B002001A20016
:100D60002401A200A700A700A700A700A900240152
:100D70000C02A200A500A900A700A500A400A400E1
:100D8000A500A400A000190198009B00A400A200E7
:100D90009B00A00019010C011B0120010C01220184
:100DA000A400A400A400A2009B00A000190101203F
:100DB0009628643090009000900094009200870084
:100DC00090010C029400940094009400920097000B
:100DD00014010C0297009700990097009500940069
:100DE00095009900970095009400920090008B0068
:100DF000900094009200870090010C0299009900E5
:100E0000990099009B00A20020020C01A400A400FC
:100E1000A400A400A200A70024020C01A700A700C0
:100E2000A900A700A500A400A500A900A700A5008F
:100E3000A400A200A0009B00A000A400A2009700B4
:100E400020020C011003070192018C01970097000A
:100E5000960097009900960017010C0297009700E2
:100E600099009700950094009500990097009500CF
:100E7000940092001003140192018C0110030701E9
:100E800092018C01970097009600970099009600B8
:100E900017010C02970097009900970095009400A5
:100EA00095009900970095009400920090008B00A7
:0E0EB000900094009200870010010C02FF3F9A
:02400E00263951
:00000001FF
;PIC16F819
/Designs/MB01B/SW/1_01/MB01A.LST
0,0 → 1,2773
CCS PCW C Compiler, Version 3.110, 15448
 
Filename: mb01a.LST
 
ROM used: 1536 (75%)
Largest free fragment is 512
RAM used: 29 (17%) at main() level
88 (50%) worst case
Stack: 6 worst case (5 in main + 1 for interrupts)
 
*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 595
0003: NOP
0004: MOVWF 7F
0005: SWAPF 03,W
0006: CLRF 03
0007: MOVWF 21
0008: MOVF 7F,W
0009: MOVWF 20
000A: MOVF 0A,W
000B: MOVWF 28
000C: CLRF 0A
000D: SWAPF 20,F
000E: MOVF 04,W
000F: MOVWF 22
0010: MOVF 77,W
0011: MOVWF 23
0012: MOVF 78,W
0013: MOVWF 24
0014: MOVF 79,W
0015: MOVWF 25
0016: MOVF 7A,W
0017: MOVWF 26
0018: MOVF 7B,W
0019: MOVWF 27
001A: BCF 03.7
001B: BCF 03.5
001C: MOVLW 8C
001D: MOVWF 04
001E: BTFSS 00.2
001F: GOTO 022
0020: BTFSC 0C.2
0021: GOTO 0CB
0022: MOVF 22,W
0023: MOVWF 04
0024: MOVF 23,W
0025: MOVWF 77
0026: MOVF 24,W
0027: MOVWF 78
0028: MOVF 25,W
0029: MOVWF 79
002A: MOVF 26,W
002B: MOVWF 7A
002C: MOVF 27,W
002D: MOVWF 7B
002E: MOVF 28,W
002F: MOVWF 0A
0030: SWAPF 21,W
0031: MOVWF 03
0032: SWAPF 7F,F
0033: SWAPF 7F,W
0034: RETFIE
.................... // Melodicky zvonek MB01A_1_00
.................... //
.................... // Prohram pro melodicky zvonek s pouzitim knihovny Sound_t1.C
.................... //
.................... // (c)miho 2004, pefi 2004
.................... //
.................... // Historie:
.................... // 1.00 Uvodni verze
.................... // 1.01 Zaveden WDT
....................
.................... #include <16F819.h> // Definice procesoru
.................... //////// Standard Header file for the PIC16F628 device ////////////////
.................... #device PIC16F819
.................... #list
....................
.................... #fuses HS,NOPROTECT,WDT,PUT,NOLVP,NOBROWNOUT,WRT // Definice konfiguracniho slova
....................
.................... #define POWER_386 PIN_A4 // L zapne napajeni pro zesilovac LM386
.................... #define POWER_PIC PIN_A3 // L pripoji GND pro procesor PIC
....................
.................... #define SOUND_HI PIN_B3 // Akusticky vystup
.................... #define SOUND_LO PIN_B2 // Akusticky vystup
.................... #define SOUND_CLOCK 20000000 // Frekvence hodin
.................... #define SOUND_LowOctave 1 // O oktavu vys protoze mame moc rychly krystal
.................... #define SOUND_WDT 1 // Budeme pouzivat WDT
.................... #include "Sound_T1.c" // Hudebni knihovna
.................... // Knihovna pro generovani hudebnich zvuku dane frekvence a delky nebo
.................... // dane noty temperovaneho ladeni a delky.
.................... //
.................... // Pro gnerovani pouziva casovac T0, T1 a jednotku CCP1.
.................... //
.................... // POZOR -- POZOR -- POZOR
.................... // Pri nizsi frekvenci XTALu (nez asi 5MHz) je rezie preruseni tak velka, ze spotrebuje
.................... // veskery strojovy cas a uz nedojde k ukonceni rozehraneho tonu vyssi frekvence (z oktavy 7
.................... // nebo nad cca 8KHz). Resenim je pouzit vlastni INT proceduru s minimalni rezii.
.................... //
.................... // (c)miho 2004, pefi 2004,
.................... //
.................... // Historie
.................... // 1.00 Uvodni verze
.................... // 1.01 Pridana podpora zapnuteho WDT
....................
.................... // Konfiguracni parametry
.................... //#define SOUND_HI PIN_xx // Pozitivni vystup
.................... //#define SOUND_LO PIN_xx // Komplementarni vystup
.................... //#define SOUND_WDT 1 // Pokud je pouzit WDT
.................... #ifndef SOUND_CLOCK
.................... #define SOUND_CLOCK 4000000 // Frelvence krystalu v Hz
.................... #endif
....................
....................
.................... // Definice hudebnich tonu (not) pro proceduru SoundNote()
.................... #define SOUND_C 0
.................... #define SOUND_Cis 1
.................... #define SOUND_D 2
.................... #define SOUND_Dis 3
.................... #define SOUND_E 4
.................... #define SOUND_F 5
.................... #define SOUND_Fis 6
.................... #define SOUND_G 7
.................... #define SOUND_Gis 8
.................... #define SOUND_A 9
.................... #define SOUND_Ais 10
.................... #define SOUND_H 11
.................... #define SOUND_Space 12 // Pomlka
....................
....................
.................... // Prototypy verejnych procedur
....................
.................... void SoundBeep(unsigned int16 Frequency, unsigned int16 Duration);
.................... // Predava se frekvence v Hz a doba trvani v ms (0 znamena ticho)
....................
.................... void SoundNote(unsigned int8 Note, Octave, unsigned int16 Duration);
.................... // Predava se cislo noty (0 je C), posunuti v oktavach (0 nejnizsi ton,
.................... // SOUND_Space je ticho), doba trvani v ms
....................
.................... // Alternativni makra pro generovani konstatnich tonu
.................... // SoundBeepMacro(Frequency, Duration) - frekvence nesmi byt 0
.................... // SoundNoteMacro(Note, Octave, Duration) - nepodporuje SOUND_Space
.................... // SoundSpaceMacro(Duration) - hraje ticho
....................
.................... // Privatni cast
....................
....................
.................... #int_ccp1
.................... void IntCCP1()
.................... // Preruseni od jednotky CCP1 generuje vystup
.................... {
.................... volatile int1 Data; // Posledni stav vystupu
.................... output_bit(SOUND_HI,Data); // Nastav vystup
*
00CB: BTFSC 72.0
00CC: GOTO 0CF
00CD: BCF 06.3
00CE: GOTO 0D0
00CF: BSF 06.3
00D0: BSF 03.5
00D1: BCF 06.3
.................... output_bit(SOUND_LO,~Data);
00D2: BTFSS 72.0
00D3: GOTO 0D8
00D4: BCF 03.5
00D5: BCF 06.2
00D6: GOTO 0DA
00D7: BSF 03.5
00D8: BCF 03.5
00D9: BSF 06.2
00DA: BSF 03.5
00DB: BCF 06.2
.................... Data=~Data; // Otoc stav vystupu
00DC: MOVLW 01
00DD: XORWF 72,F
.................... }
....................
....................
.................... #if SOUND_CLOCK < (65535*32*4*2) // < 16.7 MHz
.................... #define SOUND_PRESCALE 1
.................... #elif SOUND_CLOCK < (65535*32*4*2*2) // < 33.6 MHz
.................... #define SOUND_PRESCALE 2
.................... #elif SOUND_CLOCK < (65535*32*4*2*4) // < 67.1 MHz
.................... #define SOUND_PRESCALE 4
.................... #elif SOUND_CLOCK < (65535*32*4*2*8) // < 134 MHz
.................... #define SOUND_PRESCALE 8
.................... #else
.................... #error SOUND_CLOCK Frequency too high
.................... #endif
00DE: BCF 03.5
00DF: BCF 0C.2
00E0: BCF 0A.3
00E1: GOTO 022
.................... #bit T0IF=0x0B.2
.................... void SoundBeep(unsigned int16 Frequency, unsigned int16 Duration)
.................... // Predava se frekvence v Hz a doba trvani v ms (0 znamena ticho)
.................... // Rozumne frekvence jsou od 32Hz
.................... {
.................... unsigned int16 Time; // Pocitadlo zlomkoveho casu
....................
.................... // Inicializace casovace
.................... if (Frequency!=0) // Frekvence 0 znamena ticho
.................... {
.................... setup_ccp1(CCP_COMPARE_RESET_TIMER);
.................... set_timer1(0);
.................... (int16)CCP_1=SOUND_CLOCK/SOUND_PRESCALE/4/2/Frequency;
.................... #if SOUND_PRESCALE==1
.................... setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
.................... #elif SOUND_PRESCALE==2
.................... setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
.................... #elif SOUND_PRESCALE==4
.................... setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
.................... #elif SOUND_PRESCALE==8
.................... setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
.................... #endif
.................... enable_interrupts(int_ccp1);
.................... enable_interrupts(global);
.................... }
....................
.................... // Delka tonu merena casovacem T0 (bez preruseni)
.................... Time=0;
.................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
.................... while (Duration)
.................... {
.................... #ifdef SOUND_WDT
.................... restart_wdt(); // Nuluj watchdog abychom se nezresetovali
.................... #endif
.................... if (T0IF) // Preteceni T0 - kazdych (1/CLK)*4*256
.................... {
.................... T0IF = 0;
.................... Time += (256*4*1000*2048+SOUND_CLOCK/2)/SOUND_CLOCK;
.................... }
.................... if (Time>>11)
.................... {
.................... Time -= 2048;
.................... Duration--;
.................... }
.................... }
....................
.................... // Konec casovace
.................... disable_interrupts(int_ccp1);
.................... disable_interrupts(global);
.................... }
....................
....................
.................... // Definice casu pulperody pro nejnizsi oktavu, v kvantech casovace T1
.................... // Pulperiody tonu v dalsich oktavach se ziskavaji rotaci vpravo
.................... #define SOUND_Peri_C ((30578*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 30578us
.................... #define SOUND_Peri_Cis ((28862*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 28862us
.................... #define SOUND_Peri_D ((27242*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 27242us
.................... #define SOUND_Peri_Dis ((25713*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 25713us
.................... #define SOUND_Peri_E ((24270*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 24270us
.................... #define SOUND_Peri_F ((22908*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 22908us
.................... #define SOUND_Peri_Fis ((21622*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 21622us
.................... #define SOUND_Peri_G ((20408*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 20408us
.................... #define SOUND_Peri_Gis ((19263*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 19263us
.................... #define SOUND_Peri_A ((18182*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 18182us
.................... #define SOUND_Peri_Ais ((17161*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 17161us
.................... #define SOUND_Peri_H ((16198*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 16198us
....................
.................... // Kontrola na delku konstanty (musi byt mensi nez delka citace)
.................... #if SOUND_Peri_C > 65535
.................... #error "SOUND_Peri_C too long (Note C requires delay > 65535 cycles)"
.................... #endif
....................
.................... // Casove konstanty pro noty nejnizsi oktavy
.................... const unsigned int16 Table[12] =
.................... SOUND_Peri_C, SOUND_Peri_Cis, SOUND_Peri_D, SOUND_Peri_Dis,
.................... SOUND_Peri_E, SOUND_Peri_F, SOUND_Peri_Fis, SOUND_Peri_G,
.................... SOUND_Peri_Gis, SOUND_Peri_A, SOUND_Peri_Ais, SOUND_Peri_H;
*
0035: BCF 0A.0
0036: BCF 0A.1
0037: BCF 0A.2
0038: ADDWF 02,F
0039: RETLW 4E
003A: RETLW 95
003B: RETLW ED
003C: RETLW 8C
003D: RETLW 04
003E: RETLW 85
003F: RETLW 8D
0040: RETLW 7D
0041: RETLW 81
0042: RETLW 76
0043: RETLW DB
0044: RETLW 6F
0045: RETLW 93
0046: RETLW 69
0047: RETLW A6
0048: RETLW 63
0049: RETLW 0E
004A: RETLW 5E
004B: RETLW C7
004C: RETLW 58
004D: RETLW CB
004E: RETLW 53
004F: RETLW 17
0050: RETLW 4F
....................
....................
.................... void SoundNote(unsigned int8 Note, Octave, unsigned int16 Duration)
.................... // Predava se cislo noty (0 je C), posunuti v oktavach (0 nejnizsi ton)
.................... // doba trvani v ms (0 znamena ticho)
.................... // Zahraje zadanou notu v zadane oktave dane delky
.................... {
.................... unsigned int16 Time; // Pocitadlo zlomkoveho casu
....................
.................... // Inicializace casovace
.................... if (Note!=SOUND_Space) // Pokud se ma hrat spust hrani
*
00E2: MOVF 69,W
00E3: SUBLW 0C
00E4: BTFSC 03.2
00E5: GOTO 109
.................... {
.................... setup_ccp1(CCP_COMPARE_RESET_TIMER);
00E6: MOVLW 0B
00E7: MOVWF 17
.................... set_timer1(0);
00E8: CLRF 0F
00E9: CLRF 0E
.................... (int16)CCP_1=Table[Note]>>Octave;
00EA: BCF 03.0
00EB: RLF 69,W
00EC: MOVWF 77
00ED: MOVWF 6F
00EE: INCF 6F,W
00EF: CALL 035
00F0: MOVWF 7A
00F1: MOVF 6F,W
00F2: CALL 035
00F3: MOVWF 70
00F4: MOVF 7A,W
00F5: MOVWF 71
00F6: MOVWF 16
00F7: MOVF 70,W
00F8: MOVWF 15
00F9: MOVF 6A,W
00FA: MOVWF 77
00FB: BTFSC 03.2
00FC: GOTO 102
00FD: BCF 03.0
00FE: RRF 16,F
00FF: RRF 15,F
0100: DECFSZ 77,F
0101: GOTO 0FD
.................... #if SOUND_PRESCALE==1
.................... setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
.................... #elif SOUND_PRESCALE==2
.................... setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
0102: MOVLW 95
0103: MOVWF 10
.................... #elif SOUND_PRESCALE==4
.................... setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
.................... #elif SOUND_PRESCALE==8
.................... setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
.................... #endif
.................... enable_interrupts(int_ccp1);
0104: BSF 03.5
0105: BSF 0C.2
.................... enable_interrupts(global);
0106: MOVLW C0
0107: BCF 03.5
0108: IORWF 0B,F
.................... }
....................
.................... // Delka tonu merena casovacem T0 (bez preruseni)
.................... Time=0;
0109: CLRF 6E
010A: CLRF 6D
.................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
010B: BSF 03.5
010C: MOVF 01,W
010D: ANDLW C0
010E: IORLW 08
010F: MOVWF 01
.................... while (Duration)
0110: BCF 03.5
0111: MOVF 6B,W
0112: IORWF 6C,W
0113: BTFSC 03.2
0114: GOTO 133
.................... {
.................... if (T0IF) // Preteceni T0 - kazdych (1/CLK)*4*256
0115: BTFSS 0B.2
0116: GOTO 11C
.................... {
.................... T0IF = 0;
0117: BCF 0B.2
.................... Time += (256*4*1000*2048+SOUND_CLOCK/2)/SOUND_CLOCK;
0118: MOVLW 69
0119: ADDWF 6D,F
011A: BTFSC 03.0
011B: INCF 6E,F
.................... }
.................... if (Time>>11)
011C: CLRF 7A
011D: RRF 6E,W
011E: MOVWF 79
011F: RRF 79,F
0120: RRF 79,F
0121: MOVLW 1F
0122: ANDWF 79,F
0123: MOVF 79,W
0124: IORWF 7A,W
0125: BTFSC 03.2
0126: GOTO 131
.................... {
.................... Time -= 2048;
0127: MOVLW 00
0128: SUBWF 6D,F
0129: MOVLW 08
012A: BTFSS 03.0
012B: MOVLW 09
012C: SUBWF 6E,F
.................... Duration--;
012D: MOVF 6B,W
012E: BTFSC 03.2
012F: DECF 6C,F
0130: DECF 6B,F
.................... }
.................... #ifdef SOUND_WDT
.................... restart_wdt(); // Nuluj watchdog abychom se nezresetovali
0131: CLRWDT
.................... #endif
.................... }
0132: GOTO 111
....................
.................... // Konec casovace
.................... disable_interrupts(int_ccp1);
0133: BSF 03.5
0134: BCF 0C.2
.................... disable_interrupts(global);
0135: BCF 03.5
0136: BCF 0B.6
0137: BCF 0B.7
0138: BTFSC 0B.7
0139: GOTO 137
013A: RETLW 00
.................... }
....................
....................
.................... #include "Data.c" // Datovy blok pro predpripravene skladby
.................... // Tento soubor definuje vse potrebne pro ulozeni skladeb do pameti programu.
.................... // Dale definuje pislusna makra pro snadne definice. Tyto definice jsou voleny
.................... // zamerne tak, aby mohl byt pouzit stejny soubor s definici skladby jak
.................... // pro vlozeni primo do firmwaru v dobe prekladu tak i k dodatecnemu nahrani
.................... // skladby pres seriovou linku.
....................
.................... // Definice hranic pameti pro ulozeni pisnicek
.................... #define STARTMEM 0x600 // Zde zacina pametoa oblast pro pisnicky
.................... #define ENDMEM 0x7ff // Zde konci pametova oblast pro pisnicky
....................
.................... // Definice konstant pro kodovani dat
.................... #define ENDOFDATA 0x3FFF // Priznak konce pisnicek (prazdna pamet)
.................... #define DATABEGIN 0x2000 // Kod zacatku skladby
.................... #define MASKBEGIN 0x3800
.................... #define DATATEMPO 0x2800 // Kod pro nastaveni tempa
.................... #define MASKTEMPO 0x3800
.................... #define DATAPAUSE 0x3000 // Kod pro nastaveni mezery mezi notami
.................... #define MASKPAUSE 0x3800
.................... #define MASKNOTE 0x2000 // Nejvissi bit 0 urcuje, ze jde o notu
....................
.................... // Pseudomakra pro jednoduchy zapis skladeb do zdrojaku jazyka C
.................... #define BEGIN DATABEGIN+ // Zacatek pisnicky + posunuti oktav
.................... #define TEMPO DATATEMPO+ // Delka nejskratsi noty v ms
.................... #define PAUSE DATAPAUSE+ // Delka mezery mezi notami
.................... #define END // Konec skladby, zde nic neznamena
....................
.................... // Pseudomakra pro zapis not, zapisuje se cislo oktavy, nota, delka noty
.................... #define C *16 + SOUND_C + 128 *
.................... #define Cis *16 + SOUND_Cis + 128 *
.................... #define D *16 + SOUND_D + 128 *
.................... #define Dis *16 + SOUND_Dis + 128 *
.................... #define E *16 + SOUND_E + 128 *
.................... #define F *16 + SOUND_F + 128 *
.................... #define Fis *16 + SOUND_Fis + 128 *
.................... #define G *16 + SOUND_G + 128 *
.................... #define Gis *16 + SOUND_Gis + 128 *
.................... #define A *16 + SOUND_A + 128 *
.................... #define Ais *16 + SOUND_Ais + 128 *
.................... #define H *16 + SOUND_H + 128 *
.................... #define Space SOUND_Space + 128 *
....................
.................... // Pametova oblast
.................... #ORG 0x600,0x7FF {} // Vyhrazeni oblasti pameti pro ulozeni pisnicek
.................... #ROM 0x600 = { // Naplneni oblasti pameti daty
....................
.................... // Pisnicky jako soucast firwaru se vkladaji sem
.................... // Museji mit stejny format jako uvedene priklady aby zafungovaly makra
.................... #include "Skladby\TheFinalSoundDown.txt"
.................... // Pisnicka "The Final Sound Down"
.................... //
.................... // Tato pisnicka je napsana ve formatu, ktery se da pouzit jak pro primy
.................... // preklad do firmwaru melodickeho zvonku tak i pro dodatecne nahrani
....................
.................... BEGIN 3, // Zacatek skladby
.................... TEMPO 100, // Delka nejkratsi noty v ms
.................... PAUSE 100, // Delka mezery mezi notami
....................
.................... 1 A 1,
.................... 1 G 1,
.................... 1 A 4,
.................... 1 D 4,
.................... Space 2,
....................
.................... 1 Ais 1,
.................... 1 A 1,
.................... 1 Ais 2,
.................... 1 A 2,
.................... 1 G 4,
.................... Space 2,
....................
.................... 1 Ais 1,
.................... 1 A 1,
.................... 1 Ais 4,
.................... 1 D 4,
.................... Space 2,
....................
.................... 1 G 1,
.................... 1 F 1,
.................... 1 G 2,
.................... 1 F 2,
.................... 1 E 2,
.................... 1 G 2,
.................... 1 F 4,
.................... Space 2,
....................
.................... 1 E 1,
.................... 1 F 1,
.................... 1 G 4,
.................... Space 2,
....................
.................... 1 F 1,
.................... 1 G 1,
.................... 1 A 2,
.................... 1 G 2,
.................... 1 F 2,
.................... 1 E 2,
.................... 1 D 4,
.................... 1 Ais 4,
.................... 1 A 4,
.................... Space 2,
....................
.................... 1 A 1,
.................... 1 Ais 1,
.................... 1 A 1,
.................... 1 G 1,
.................... 1 A 4,
.................... Space 2,
....................
.................... END
....................
.................... #include "Skladby\BednaOdWhisky.txt"
.................... // Pisnicka "Bedna od Whisky"
.................... //
.................... // Tato pisnicka je napsana ve formatu, ktery se da pouzit jak pro primy
.................... // preklad do firmwaru melodickeho zvonku tak i pro dodatecne nahrani
....................
.................... BEGIN 2, // Zacatek skladby
.................... TEMPO 100, // Delka nejkratsi noty v ms
.................... PAUSE 100, // Delka mezery mezi notami
....................
.................... 1 A 2,
.................... 2 C 2,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 G 4,
.................... 2 E 2,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 G 2,
.................... 2 E 2,
.................... 2 D 2,
.................... 2 E 4,
.................... Space 4,
.................... 1 A 2,
.................... 2 C 2,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 G 2,
.................... 2 G 2,
.................... 2 E 2,
.................... 2 E 2,
.................... 1 A 2,
.................... 2 E 2,
.................... 1 H 2,
.................... 2 E 2,
.................... 1 A 4,
.................... Space 4,
.................... 1 A 2,
.................... 2 C 2,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 G 2,
.................... 2 G 2,
.................... 2 E 4,
.................... 2 A 2,
.................... 2 G 2,
.................... 2 E 2,
.................... 2 D 2,
.................... 2 E 4,
.................... Space 2,
.................... 2 E 2,
.................... 1 A 2,
.................... 2 C 2,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 G 2,
.................... 2 E 4,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 GIS 2,
.................... 2 H 2,
.................... 2 A 4,
.................... Space 8,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 GIS 2,
.................... 2 FIS 2,
.................... 2 A 4,
.................... 2 A 2,
.................... 2 H 2,
.................... 2 H 2,
.................... 2 A 2,
.................... 2 H 2,
.................... 3 CIS 2,
.................... 2 A 4,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 GIS 2,
.................... 2 FIS 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 H 2,
.................... 2 H 2,
.................... 2 A 2,
.................... 2 GIS 2,
.................... 2 A 4,
.................... Space 2,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 GIS 2,
.................... 2 FIS 2,
.................... 2 A 4,
.................... 2 A 2,
.................... 2 H 2,
.................... 2 H 2,
.................... 2 A 2,
.................... 2 H 2,
.................... 3 CIS 2,
.................... 2 A 4,
.................... 2 E 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 A 2,
.................... 2 GIS 2,
.................... 2 FIS 2,
.................... 2 A 2,
.................... Space 2,
.................... 2 A 2,
.................... 2 H 2,
.................... 2 H 2,
.................... 2 A 2,
.................... 2 GIS 2,
.................... 2 A 8,
.................... 2 G 2,
.................... 2 A 8,
.................... 2 G 2,
.................... 2 A 8,
....................
.................... END
....................
.................... #include "Skladby\KdyzMeBaliZaVojacka.txt"
.................... // Pisnicka "Kdyz me brali za vojacka"
.................... //
.................... // Tato pisnicka je napsana ve formatu, ktery se da pouzit jak pro primy
.................... // preklad do firmwaru melodickeho zvonku tak i pro dodatecne nahrani
....................
.................... BEGIN 2, // Zacatek skladby
.................... TEMPO 150, // Delka nejkratsi noty v ms
.................... PAUSE 100, // Delka mezery mezi notami
....................
.................... 1 A 1,
.................... 2 C 1,
.................... 2 E 1,
.................... 2 D 1,
.................... 2 C 1,
.................... 1 H 1,
.................... 2 C 2,
.................... 2 D 1,
.................... 2 E 2,
.................... 2 D 1,
.................... 2 G 1,
.................... 2 G 1,
.................... 2 G 1,
.................... 2 G 1,
.................... 2 A 1,
.................... 2 E 2,
.................... Space 4,
.................... 2 D 1,
.................... 2 F 1,
.................... 2 A 1,
.................... 2 G 1,
.................... 2 F 1,
.................... 2 E 1,
.................... 2 E 1,
.................... 2 F 1,
.................... 2 E 1,
.................... 2 C 1,
.................... 1 A 2,
.................... 1 GIS 1,
.................... 1 H 1,
.................... 2 E 1,
.................... 2 D 1,
.................... 1 H 1,
.................... 2 C 1,
.................... 1 A 2,
.................... Space 2,
.................... 1 H 2,
.................... 2 C 2,
.................... Space 2,
.................... 2 D 2,
.................... 2 E 1,
.................... 2 E 1,
.................... 2 E 1,
.................... 2 D 1,
.................... 1 H 1,
.................... 2 C 1,
.................... 1 A 2,
....................
.................... END
....................
.................... #include "Skladby\Medvedi.txt"
.................... // Pisnicka "Medvedi"
.................... //
.................... // Tato pisnicka je napsana ve formatu, ktery se da pouzit jak pro primy
.................... // preklad do firmwaru melodickeho zvonku tak i pro dodatecne nahrani
....................
.................... BEGIN 1, // Zacatek skladby
.................... TEMPO 150, // Delka nejkratsi noty v ms
.................... PAUSE 100, // Delka mezery mezi notami
....................
.................... 1 C 1, // 1
.................... 1 C 1,
.................... 1 C 1,
.................... 1 E 1,
.................... 1 D 1,
.................... 0 G 1,
....................
.................... 1 C 3, // 2
.................... Space 4,
....................
.................... 1 E 1, // 3
.................... 1 E 1,
.................... 1 E 1,
.................... 1 E 1,
.................... 1 D 1,
.................... 1 G 1,
....................
.................... 1 E 2, // 4
.................... Space 4,
....................
.................... 1 G 1, // 5
.................... 1 G 1,
.................... 1 A 1,
.................... 1 G 1,
.................... 1 F 1,
.................... 1 E 1,
....................
.................... 1 F 1, // 6
.................... 1 A 1,
.................... 1 G 1,
.................... 1 F 1,
.................... 1 E 1,
.................... 1 D 1,
....................
.................... 1 C 1, // 7
.................... 0 H 1,
.................... 1 C 1,
.................... 1 E 1,
.................... 1 D 1,
.................... 0 G 1,
....................
.................... 1 C 3, // 8
.................... Space 4,
.................... 1 A 1, // 9
.................... 1 A 1,
.................... 1 A 1,
.................... 1 A 1,
.................... 1 H 1,
.................... 2 D 1,
....................
.................... 2 C 4, // 10
.................... Space 2,
....................
.................... 2 E 1, // 11
.................... 2 E 1,
.................... 2 E 1,
.................... 2 E 1,
.................... 2 D 1,
.................... 2 G 1,
....................
.................... 2 E 4, // 12
.................... Space 2,
....................
.................... 2 G 1, // 13
.................... 2 G 1,
.................... 2 A 1,
.................... 2 G 1,
.................... 2 F 1,
.................... 2 E 1,
....................
.................... 2 F 1, // 14
.................... 2 A 1,
.................... 2 G 1,
.................... 2 F 1,
.................... 2 E 1,
.................... 2 D 1,
....................
.................... 2 C 1, // 15
.................... 1 H 1,
.................... 2 C 1,
.................... 2 E 1,
.................... 2 D 1,
.................... 1 G 1,
....................
.................... 2 C 4, // 16
.................... Space 2,
....................
.................... 1 C 6, // 1
.................... 0 G 2,
....................
.................... 1 D 3, // 2
.................... Space 3,
....................
.................... 1 G 1, // 3
.................... 1 G 1,
.................... 1 Fis 1,
.................... 1 G 1,
.................... 1 A 1,
.................... 1 Fis 1,
....................
.................... 1 G 2, // 4
.................... Space 4,
....................
.................... 1 G 1, // 5
.................... 1 G 1,
.................... 1 A 1,
.................... 1 G 1,
.................... 1 F 1,
.................... 1 E 1,
....................
.................... 1 F 1, // 6
.................... 1 A 1,
.................... 1 G 1,
.................... 1 F 1,
.................... 1 E 1,
.................... 1 D 1,
....................
.................... 1 C 6, // 7
.................... 1 E 2,
....................
.................... 1 D 3, // 8
.................... Space 3,
....................
.................... 1 C 6, // 9
.................... 0 G 2,
....................
.................... 1 D 3, // 10
.................... Space 3,
....................
.................... 1 G 1, // 11
.................... 1 G 1,
.................... 1 Fis 1,
.................... 1 G 1,
.................... 1 A 1,
.................... 1 Fis 1,
....................
.................... 1 G 2, // 12
.................... Space 4,
....................
.................... 1 G 1, // 13
.................... 1 G 1,
.................... 1 A 1,
.................... 1 G 1,
.................... 1 F 1,
.................... 1 E 1,
....................
.................... 1 F 1, // 14
.................... 1 A 1,
.................... 1 G 1,
.................... 1 F 1,
.................... 1 E 1,
.................... 1 D 1,
....................
.................... 1 C 1, // 15
.................... 0 H 1,
.................... 1 C 1,
.................... 1 E 1,
.................... 1 D 1,
.................... 0 G 1,
....................
.................... 1 C 2, // 16
.................... Space 4,
....................
.................... END
....................
....................
.................... // Koncova znacka a konec oblasti pro skladby
.................... ENDOFDATA
.................... }
....................
.................... // Zruseni definic maker pro definici skladeb
.................... // V dalsim programu uz nebudou potreba
.................... #undef BEGIN
.................... #undef TEMPO
.................... #undef PAUSE
.................... #undef END
.................... #undef C
.................... #undef Cis
.................... #undef D
.................... #undef Dis
.................... #undef E
.................... #undef F
.................... #undef Fis
.................... #undef G
.................... #undef Gis
.................... #undef A
.................... #undef Ais
.................... #undef H
.................... #undef Space
....................
....................
.................... #define RXD PIN_B1 // Port pro RS232
.................... #use delay(CLOCK=20000000,RESTART_WDT) // Konfigurace pro casovani RS232
.................... #use rs232(BAUD=9600,RCV=RXD,RESTART_WDT,INVERT,PARITY=N,BITS=8) // Prenosove parametry RS232
*
0153: MOVLW 08
0154: MOVWF 77
0155: BSF 03.5
0156: BSF 06.1
0157: CLRWDT
0158: BCF 03.5
0159: BTFSC 06.1
015A: GOTO 15D
015B: BSF 03.5
015C: GOTO 157
015D: CLRF 61
015E: BSF 77.7
015F: GOTO 16E
0160: BCF 77.7
0161: GOTO 16E
0162: BCF 03.0
0163: BTFSS 06.1
0164: BSF 03.0
0165: RRF 61,F
0166: BSF 77.6
0167: GOTO 16E
0168: BCF 77.6
0169: DECFSZ 77,F
016A: GOTO 162
016B: MOVF 61,W
016C: MOVWF 78
016D: GOTO 17A
016E: MOVLW A7
016F: BTFSC 77.7
0170: MOVLW 2D
0171: MOVWF 78
0172: DECFSZ 78,F
0173: GOTO 172
0174: NOP
0175: BTFSC 77.7
0176: GOTO 160
0177: BTFSC 77.6
0178: GOTO 168
0179: GOTO 162
017A: RETLW 00
....................
....................
.................... // Sada globalnich promennych
.................... // --------------------------
.................... // Vyuzivame globalni promenne protoze je to vyhodne z hlediska spotreby zdroju. Usetri
.................... // se vyznmane mnoho pameti programu pri predavani parametru
....................
....................
.................... unsigned int16 Adr; // Adresovy ukazatel do pameti skladeb
.................... unsigned int16 Data; // Prectena data nebo data pro zapis
.................... unsigned int1 Mode; // 0=rezim testovani, 1=rezim zapisu do FLASH
....................
.................... unsigned int16 Tempo; // Tempo (delka nejkratsi skladby v ms)
.................... unsigned int16 Pause; // Delka mezery mezi notami v ms
.................... unsigned int8 Octava; // Posunuti skladby v oktavach
....................
.................... unsigned int8 Beep; // Druh pipnuti pro proceduru SoundSpec
.................... unsigned int1 Error; // Priznak chyby
....................
.................... unsigned int8 CisloSkladby; // Cislo skladby pro proceduru Find a Play
....................
....................
.................... // Zvuky, posloupnost zadaneho poctu tonu
.................... #define SoundEndOfLine 0x01 // Kratke pipnuti na konci radky
.................... #define SoundPGM 0x03 // Trilek pri vstupu do rezimu programovani
.................... #define SoundPostPlay 0x03 // Po ukonceni prehravani
.................... #define SoundERASE 0x02 // Zvuk pri smazani bloku FLASH pameti
.................... #define SoundERR 0x05 // Chyba syntaxe
....................
.................... void SpecBeep()
.................... // Data - pocet pipnuti, 0 znamena ticho
.................... {
.................... int Oct;
....................
.................... if (Error) Beep=SoundERR;
*
013B: BTFSS 2D.1
013C: GOTO 13F
013D: MOVLW 05
013E: MOVWF 33
....................
.................... for(Oct=2;Beep!=0;Beep--)
013F: MOVLW 02
0140: MOVWF 61
0141: MOVF 33,F
0142: BTFSC 03.2
0143: GOTO 151
.................... {
.................... SoundNote(SOUND_A,Oct++,50);
0144: MOVF 61,W
0145: INCF 61,F
0146: MOVWF 62
0147: MOVLW 09
0148: MOVWF 69
0149: MOVF 62,W
014A: MOVWF 6A
014B: CLRF 6C
014C: MOVLW 32
014D: MOVWF 6B
014E: CALL 0E2
.................... }
014F: DECF 33,F
0150: GOTO 141
....................
.................... Error=0;
0151: BCF 2D.1
0152: RETLW 00
.................... }
....................
....................
.................... // Precti slovo z pameti programu
.................... int16 ReadData()
.................... // Adr - adresa ze ktere se cte
.................... // Data - prectena data
.................... {
.................... int8 a,b; // Pomocne promenne
....................
.................... (int8)*EEADR = Adr; // Adresa, spodni cast
*
01EF: MOVF 29,W
01F0: BSF 03.6
01F1: MOVWF 0D
.................... (int8)*EEADRH = Adr >> 8; // Adresa, horni cast
01F2: BCF 03.6
01F3: MOVF 2A,W
01F4: BSF 03.6
01F5: MOVWF 0F
.................... bit_set(*EECON1,EECON1_EEPGD); // Pamet programu
01F6: BSF 03.5
01F7: BSF 0C.7
.................... bit_set(*EECON1,EECON1_RD); // Operace cteni
01F8: BSF 0C.0
.................... #ASM
.................... nop; // Povinne nop
01F9: NOP
.................... nop;
.................... #ENDASM
01FA: NOP
.................... a = (int8)*EEDATA; // Prevezmi data
01FB: BCF 03.5
01FC: MOVF 0C,W
01FD: BCF 03.6
01FE: MOVWF 61
.................... b = (int8)*EEDATAH;
01FF: BSF 03.6
0200: MOVF 0E,W
0201: BCF 03.6
0202: MOVWF 62
.................... Data=make16(b,a); // Sestav vysledek ze 2 bajtu
0203: MOVF 62,W
0204: MOVWF 2C
0205: MOVF 61,W
0206: MOVWF 2B
0207: RETLW 00
.................... }
....................
....................
.................... // Smazani cele pameti vyhrazene pro skladby
.................... void Erase()
.................... {
.................... for(Adr=STARTMEM; Adr<=ENDMEM; Adr++) // Cela oblast
*
0482: MOVLW 06
0483: MOVWF 2A
0484: CLRF 29
0485: MOVF 2A,W
0486: SUBLW 07
0487: BTFSS 03.0
0488: GOTO 4B8
.................... {
.................... ReadData();
0489: CALL 1EF
.................... if (Data!=0x3FFF) // Mazu jen bloky, ktere to potrebuji
048A: INCFSZ 2B,W
048B: GOTO 490
048C: MOVF 2C,W
048D: SUBLW 3F
048E: BTFSC 03.2
048F: GOTO 4B4
.................... {
.................... if (input(POWER_PIC)!=0) return; // Nezapisuj pokud neni jumper povoleni programovani
0490: BSF 03.5
0491: BSF 05.3
0492: MOVLW 00
0493: BCF 03.5
0494: BTFSC 05.3
0495: MOVLW 01
0496: XORLW 00
0497: BTFSC 03.2
0498: GOTO 49A
0499: GOTO 4B8
.................... (int8)*EEADR = Adr; // Adresa bloku, spodni cast
049A: MOVF 29,W
049B: BSF 03.6
049C: MOVWF 0D
.................... (int8)*EEADRH = Adr >> 8; // Adresa bloku, horni cast
049D: BCF 03.6
049E: MOVF 2A,W
049F: BSF 03.6
04A0: MOVWF 0F
.................... bit_set(*EECON1,EECON1_EEPGD); // Pamet programu
04A1: BSF 03.5
04A2: BSF 0C.7
.................... bit_set(*EECON1,EECON1_WREN); // Povolit zapis
04A3: BSF 0C.2
.................... bit_set(*EECON1,EECON1_FREE); // Operace mazani
04A4: BSF 0C.4
.................... (int8)*EECON2 = 0x55; // Povinna sekvence pro zapis
04A5: MOVLW 55
04A6: MOVWF 0D
.................... (int8)*EECON2 = 0xAA;
04A7: MOVLW AA
04A8: MOVWF 0D
.................... bit_set(*EECON1,EECON1_WR); // Zahajeni mazani
04A9: BSF 0C.1
.................... #ASM
.................... nop; // Povinne prazdne instrukce
04AA: NOP
.................... nop;
.................... #ENDASM
04AB: NOP
.................... bit_clear(*EECON1,EECON1_WREN); // Uz ne zapis
04AC: BCF 0C.2
.................... bit_clear(*EECON1,EECON1_FREE); // Uz ne mazani
04AD: BCF 0C.4
.................... bit_clear(*EECON1,EECON1_EEPGD); // Uz ne pamet programu
04AE: BCF 0C.7
.................... Beep=SoundERASE;
04AF: MOVLW 02
04B0: BCF 03.5
04B1: BCF 03.6
04B2: MOVWF 33
.................... SpecBeep();
04B3: CALL 13B
.................... }
.................... }
04B4: INCF 29,F
04B5: BTFSC 03.2
04B6: INCF 2A,F
04B7: GOTO 485
.................... }
....................
....................
.................... // Zapis do pameti programu po jednotlivych slovech.
.................... // Soucastka vyzaduje zapis vzdy celych osmi slov najednou. Vyuziva se toho, ze pamet FLASH
.................... // umi zapisovat jen smerem do nuly a tak staci na pozice, ktere zrovna nechceme programovat
.................... // zapsat same jednicky cimz se stav jejich stav nezmeni.
.................... void WriteData()
.................... // Adr - adresa, kam se bude zapisovat
.................... // Data - data, ktera se budou zapisovat
.................... {
.................... int i;
....................
.................... bit_set(*EECON1,EECON1_EEPGD); // Pamet programu
*
0304: BSF 03.5
0305: BSF 03.6
0306: BSF 0C.7
.................... bit_set(*EECON1,EECON1_WREN); // Zapis
0307: BSF 0C.2
.................... (int8)*EEADR = Adr & ~3; // Adresa, spodni cast, zaokrouhleno dolu na nasobek 8
0308: BCF 03.5
0309: BCF 03.6
030A: MOVF 29,W
030B: ANDLW FC
030C: BSF 03.6
030D: MOVWF 0D
.................... (int8)*EEADRH = Adr >> 8; // Adresa, horni cast
030E: BCF 03.6
030F: MOVF 2A,W
0310: BSF 03.6
0311: MOVWF 0F
.................... for (i=0; i<4; i++)
0312: BCF 03.6
0313: CLRF 61
0314: MOVF 61,W
0315: SUBLW 03
0316: BTFSS 03.0
0317: GOTO 33F
.................... {
.................... if ((Adr & 3) == i) // Pokud je adresa slova v bloku totozna s pozadovanou
0318: MOVF 29,W
0319: ANDLW 03
031A: MOVWF 62
031B: MOVF 2A,W
031C: ANDLW 00
031D: MOVWF 63
031E: MOVF 61,W
031F: SUBWF 62,W
0320: BTFSS 03.2
0321: GOTO 32E
0322: MOVF 63,F
0323: BTFSS 03.2
0324: GOTO 32E
.................... {
.................... (int8)*EEDATA =Data; // Platne slovo, spodni cast
0325: MOVF 2B,W
0326: BSF 03.6
0327: MOVWF 0C
.................... (int8)*EEDATAH=Data >> 8; // Platne slovo, horni cast
0328: BCF 03.6
0329: MOVF 2C,W
032A: BSF 03.6
032B: MOVWF 0E
.................... }
.................... else // Ostatni bunky nemenime
032C: GOTO 332
032D: BCF 03.6
.................... {
.................... (int8)*EEDATA =0xFF; // Zbytek same jednicky
032E: MOVLW FF
032F: BSF 03.6
0330: MOVWF 0C
.................... (int8)*EEDATAH=0xFF;
0331: MOVWF 0E
.................... }
.................... (int8)*EECON2 = 0x55; // Povinna sekvence pro zapis
0332: MOVLW 55
0333: BSF 03.5
0334: MOVWF 0D
.................... (int8)*EECON2 = 0xAA;
0335: MOVLW AA
0336: MOVWF 0D
.................... bit_set(*EECON1,EECON1_WR); // Zahajeni zapisu
0337: BSF 0C.1
.................... #ASM
.................... nop; // Povinne dve prazdne instrukce
0338: NOP
.................... nop;
.................... #ENDASM
0339: NOP
.................... ((int8)*EEADR) ++; // Dalsi slovo
033A: BCF 03.5
033B: INCF 0D,F
.................... }
033C: BCF 03.6
033D: INCF 61,F
033E: GOTO 314
.................... bit_clear(*EECON1,EECON1_WREN); // Konec zapisu
033F: BSF 03.5
0340: BSF 03.6
0341: BCF 0C.2
.................... bit_clear(*EECON1,EECON1_EEPGD); // Uz ne pamet programu (bezpecnost)
0342: BCF 0C.7
.................... }
....................
....................
.................... // Zapise data Data na adresu Adr a provede posun na dalsi adresu, zapisuje se jen do
.................... // dovolene oblasti pameti a jen v pripade, ze je Mode=1
.................... void WriteDataInc()
.................... // Data - co se zapisuje
.................... // Adr - kam se zapisuje, po zapisu se adresa posouva
.................... {
.................... if (~Mode) return; // Neni rezim zapisu
*
02E0: BTFSC 2D.0
02E1: GOTO 2E3
02E2: GOTO 34A
.................... if ( (Adr>=STARTMEM) & (Adr<=ENDMEM) & (input(POWER_PIC)==0) )
02E3: MOVF 2A,W
02E4: SUBLW 05
02E5: BTFSS 03.0
02E6: GOTO 2E9
02E7: MOVLW 00
02E8: GOTO 2EA
02E9: MOVLW 01
02EA: MOVWF 61
02EB: MOVF 2A,W
02EC: SUBLW 07
02ED: BTFSC 03.0
02EE: GOTO 2F1
02EF: MOVLW 00
02F0: GOTO 2F2
02F1: MOVLW 01
02F2: ANDWF 61,W
02F3: MOVWF 62
02F4: BSF 03.5
02F5: BSF 05.3
02F6: MOVLW 00
02F7: BCF 03.5
02F8: BTFSC 05.3
02F9: MOVLW 01
02FA: XORLW 00
02FB: BTFSC 03.2
02FC: GOTO 2FF
02FD: MOVLW 00
02FE: GOTO 300
02FF: MOVLW 01
0300: ANDWF 62,W
0301: XORLW 00
0302: BTFSC 03.2
0303: GOTO 349
.................... {
.................... WriteData();
.................... Adr++;
*
0343: BCF 03.5
0344: BCF 03.6
0345: INCF 29,F
0346: BTFSC 03.2
0347: INCF 2A,F
.................... }
.................... else
0348: GOTO 34A
.................... {
.................... Error=1;
0349: BSF 2D.1
.................... }
034A: RETLW 00
.................... }
....................
....................
.................... // Najdi zacatek zadaneho cisla skladby. Promenna Adr ukazuje na zacatek skladby.
.................... // Neni-li skladba nalezena ukazuje Adr na koncovou znacku (0x3FFF) posledni skladby
.................... // nebo na konec pameti.
.................... int1 Find()
.................... // CisloSkladby - poradove cislo skladby
.................... // Adr - adresa zacatku skladby
.................... {
.................... Adr=STARTMEM-1; // Od zacatku oblasti pro skladby
*
0208: MOVLW 05
0209: MOVWF 2A
020A: MOVLW FF
020B: MOVWF 29
.................... for(;1;)
.................... {
.................... Adr++;
020C: INCF 29,F
020D: BTFSC 03.2
020E: INCF 2A,F
.................... ReadData(); // Precti data
020F: CALL 1EF
.................... if (Data==ENDOFDATA) return 1; // Priznak konce dat
0210: INCFSZ 2B,W
0211: GOTO 219
0212: MOVF 2C,W
0213: SUBLW 3F
0214: BTFSS 03.2
0215: GOTO 219
0216: MOVLW 01
0217: MOVWF 78
0218: GOTO 236
.................... if (Adr==ENDMEM+1) return 1; // Uz jsme prosli celou pamet
0219: MOVF 29,F
021A: BTFSS 03.2
021B: GOTO 223
021C: MOVF 2A,W
021D: SUBLW 08
021E: BTFSS 03.2
021F: GOTO 223
0220: MOVLW 01
0221: MOVWF 78
0222: GOTO 236
.................... if ((Data&MASKBEGIN)==DATABEGIN) // Priznak zacatku skladby
0223: MOVF 2B,W
0224: ANDLW 00
0225: MOVWF 61
0226: MOVF 2C,W
0227: ANDLW 38
0228: MOVWF 62
0229: MOVF 61,F
022A: BTFSS 03.2
022B: GOTO 235
022C: MOVF 62,W
022D: SUBLW 20
022E: BTFSS 03.2
022F: GOTO 235
.................... {
.................... CisloSkladby--; // Otestuj pocitadlo skladeb
0230: DECFSZ 34,F
.................... if (CisloSkladby==0) return 0; // Je to tato skladba
0231: GOTO 235
0232: MOVLW 00
0233: MOVWF 78
0234: GOTO 236
.................... }
.................... }
0235: GOTO 20C
0236: RETLW 00
.................... }
....................
....................
.................... // Zahraj jednu notu
.................... void PlayData()
.................... // Data = zakodovana nota
.................... // Tempo, Octava, Pause = parametry hrane noty
.................... {
.................... SoundNote((int8)Data&0xF,Octava+(((int8)Data>>4)&0x7),Tempo*((Data>>7)&0x3F)); // Nota
0237: MOVF 2B,W
0238: ANDLW 0F
0239: MOVWF 61
023A: SWAPF 2B,W
023B: MOVWF 77
023C: MOVLW 0F
023D: ANDWF 77,F
023E: MOVF 77,W
023F: ANDLW 07
0240: ADDWF 32,W
0241: MOVWF 63
0242: RRF 2C,W
0243: MOVWF 65
0244: RRF 2B,W
0245: MOVWF 64
0246: RRF 65,F
0247: RRF 64,F
0248: RRF 65,F
0249: RRF 64,F
024A: RRF 65,F
024B: RRF 64,F
024C: RRF 65,F
024D: RRF 64,F
024E: RRF 65,F
024F: RRF 64,F
0250: RRF 65,F
0251: RRF 64,F
0252: MOVLW 01
0253: ANDWF 65,F
0254: MOVF 64,W
0255: ANDLW 3F
0256: MOVWF 77
0257: MOVF 65,W
0258: ANDLW 00
0259: MOVWF 7A
025A: MOVF 77,W
025B: MOVWF 66
025C: MOVF 7A,W
025D: MOVWF 67
025E: MOVF 2F,W
025F: MOVWF 69
0260: MOVF 2E,W
0261: MOVWF 68
0262: MOVF 7A,W
0263: MOVWF 6B
0264: MOVF 77,W
0265: MOVWF 6A
0266: CALL 17B
0267: MOVF 79,W
0268: MOVWF 68
0269: MOVF 78,W
026A: MOVWF 67
026B: MOVF 61,W
026C: MOVWF 69
026D: MOVF 63,W
026E: MOVWF 6A
026F: MOVF 79,W
0270: MOVWF 6C
0271: MOVF 78,W
0272: MOVWF 6B
0273: CALL 0E2
.................... SoundNote(SOUND_Space,0,Pause); // Mezera
0274: MOVLW 0C
0275: MOVWF 69
0276: CLRF 6A
0277: MOVF 31,W
0278: MOVWF 6C
0279: MOVF 30,W
027A: MOVWF 6B
027B: CALL 0E2
027C: RETLW 00
.................... }
....................
....................
.................... // Zahraj skladbu od zadane adresy v promenne Adr.
.................... void Play()
.................... // CisloSkladby - cislo skladby k hrani
.................... {
.................... if (Find()) // Najdi zacatek skladby v pameti skladeb
027D: CALL 208
027E: MOVF 78,F
027F: BTFSC 03.2
0280: GOTO 282
.................... {
.................... return; // Skladba nenalezena
0281: GOTO 2DF
.................... }
....................
.................... Tempo=100; // Default delka noty
0282: CLRF 2F
0283: MOVLW 64
0284: MOVWF 2E
.................... Pause=100; // Default mezera mezi notami
0285: CLRF 31
0286: MOVWF 30
....................
.................... Octava=Data&~MASKBEGIN; // Posunuti oktav (povinna soucast zacatku skladby)
0287: MOVF 2B,W
0288: MOVWF 32
.................... Adr++;
0289: INCF 29,F
028A: BTFSC 03.2
028B: INCF 2A,F
....................
.................... for (;1;)
.................... {
.................... if (Adr==ENDMEM+1) return; // Konec pametove oblasti
028C: MOVF 29,F
028D: BTFSS 03.2
028E: GOTO 294
028F: MOVF 2A,W
0290: SUBLW 08
0291: BTFSS 03.2
0292: GOTO 294
0293: GOTO 2DF
.................... ReadData(); // Vezmi data
0294: CALL 1EF
.................... Adr++; // Posun adresu
0295: INCF 29,F
0296: BTFSC 03.2
0297: INCF 2A,F
.................... if (Data==ENDOFDATA) return; // Konec dat
0298: INCFSZ 2B,W
0299: GOTO 29F
029A: MOVF 2C,W
029B: SUBLW 3F
029C: BTFSS 03.2
029D: GOTO 29F
029E: GOTO 2DF
.................... if ((Data&MASKBEGIN)==DATABEGIN) return; // Zacatek dalsi skladby
029F: MOVF 2B,W
02A0: ANDLW 00
02A1: MOVWF 61
02A2: MOVF 2C,W
02A3: ANDLW 38
02A4: MOVWF 62
02A5: MOVF 61,F
02A6: BTFSS 03.2
02A7: GOTO 2AD
02A8: MOVF 62,W
02A9: SUBLW 20
02AA: BTFSS 03.2
02AB: GOTO 2AD
02AC: GOTO 2DF
.................... if ((Data&MASKTEMPO)==DATATEMPO) Tempo=Data&~DATATEMPO; // Paramter TEMPO
02AD: MOVF 2B,W
02AE: ANDLW 00
02AF: MOVWF 61
02B0: MOVF 2C,W
02B1: ANDLW 38
02B2: MOVWF 62
02B3: MOVF 61,F
02B4: BTFSS 03.2
02B5: GOTO 2BF
02B6: MOVF 62,W
02B7: SUBLW 28
02B8: BTFSS 03.2
02B9: GOTO 2BF
02BA: MOVF 2B,W
02BB: MOVWF 2E
02BC: MOVF 2C,W
02BD: ANDLW D7
02BE: MOVWF 2F
.................... if ((Data&MASKPAUSE)==DATAPAUSE) Pause=Data&~DATAPAUSE; // Parametr PAUSE
02BF: MOVF 2B,W
02C0: ANDLW 00
02C1: MOVWF 61
02C2: MOVF 2C,W
02C3: ANDLW 38
02C4: MOVWF 62
02C5: MOVF 61,F
02C6: BTFSS 03.2
02C7: GOTO 2D1
02C8: MOVF 62,W
02C9: SUBLW 30
02CA: BTFSS 03.2
02CB: GOTO 2D1
02CC: MOVF 2B,W
02CD: MOVWF 30
02CE: MOVF 2C,W
02CF: ANDLW CF
02D0: MOVWF 31
.................... if ((Data&MASKNOTE)==0) // Nota
02D1: MOVF 2B,W
02D2: ANDLW 00
02D3: MOVWF 61
02D4: MOVF 2C,W
02D5: ANDLW 20
02D6: MOVWF 62
02D7: MOVF 61,F
02D8: BTFSS 03.2
02D9: GOTO 2DE
02DA: MOVF 62,F
02DB: BTFSS 03.2
02DC: GOTO 2DE
.................... {
.................... PlayData(); // Zahraj notu
02DD: CALL 237
.................... }
.................... }
02DE: GOTO 28C
02DF: RETLW 00
.................... }
....................
....................
.................... // Vycisli cislo z bufferu, posune ukazovatko na prvni nezpracovany znak, preskakuje mezery
.................... int16 Number(char line[], int *a, len)
.................... {
.................... int16 Data;
.................... char c;
....................
.................... while((line[*a]==' ')&(*a<len)) // Vynech mezery na zacatku
*
0190: MOVF 62,W
0191: MOVWF 04
0192: MOVF 61,W
0193: ADDWF 00,W
0194: MOVWF 04
0195: MOVF 00,W
0196: SUBLW 20
0197: BTFSC 03.2
0198: GOTO 19B
0199: MOVLW 00
019A: GOTO 19C
019B: MOVLW 01
019C: MOVWF 69
019D: MOVF 62,W
019E: MOVWF 04
019F: MOVF 63,W
01A0: SUBWF 00,W
01A1: BTFSS 03.0
01A2: GOTO 1A5
01A3: MOVLW 00
01A4: GOTO 1A6
01A5: MOVLW 01
01A6: ANDWF 69,W
01A7: XORLW 00
01A8: BTFSC 03.2
01A9: GOTO 1AE
.................... (*a)++; // Posouvej ukazovatko
01AA: MOVF 62,W
01AB: MOVWF 04
01AC: INCF 00,F
01AD: GOTO 190
....................
.................... Data=0;
01AE: CLRF 65
01AF: CLRF 64
.................... while (1)
.................... {
.................... if (*a>=len) return Data; // Konec retezce
01B0: MOVF 62,W
01B1: MOVWF 04
01B2: MOVF 63,W
01B3: SUBWF 00,W
01B4: BTFSS 03.0
01B5: GOTO 1BB
01B6: MOVF 64,W
01B7: MOVWF 78
01B8: MOVF 65,W
01B9: MOVWF 79
01BA: GOTO 1EE
.................... c=line[*a]; // Vezmi znak z pole
01BB: MOVF 62,W
01BC: MOVWF 04
01BD: MOVF 61,W
01BE: ADDWF 00,W
01BF: MOVWF 04
01C0: MOVF 00,W
01C1: MOVWF 66
.................... if ((c<'0')|(c>'9')) return Data; // Koncime pokud znak neni cislice
01C2: MOVF 66,W
01C3: SUBLW 2F
01C4: BTFSC 03.0
01C5: GOTO 1C8
01C6: MOVLW 00
01C7: GOTO 1C9
01C8: MOVLW 01
01C9: MOVWF 67
01CA: MOVF 66,W
01CB: SUBLW 39
01CC: BTFSS 03.0
01CD: GOTO 1D0
01CE: MOVLW 00
01CF: GOTO 1D1
01D0: MOVLW 01
01D1: IORWF 67,W
01D2: XORLW 00
01D3: BTFSC 03.2
01D4: GOTO 1DA
01D5: MOVF 64,W
01D6: MOVWF 78
01D7: MOVF 65,W
01D8: MOVWF 79
01D9: GOTO 1EE
.................... Data = Data * 10 + (c-'0'); // Pouzij cislici
01DA: MOVF 65,W
01DB: MOVWF 69
01DC: MOVF 64,W
01DD: MOVWF 68
01DE: CLRF 6B
01DF: MOVLW 0A
01E0: MOVWF 6A
01E1: CALL 17B
01E2: MOVLW 30
01E3: SUBWF 66,W
01E4: ADDWF 78,W
01E5: MOVWF 64
01E6: MOVF 79,W
01E7: MOVWF 65
01E8: BTFSC 03.0
01E9: INCF 65,F
.................... (*a)++; // Dalsi znak
01EA: MOVF 62,W
01EB: MOVWF 04
01EC: INCF 00,F
.................... }
01ED: GOTO 1B0
01EE: RETLW 00
.................... }
....................
....................
.................... // Vyhledej klicove slovo a vrat jeho zkraceny kod
.................... // Pokud slovo neexistuje vraci -1
.................... // Format definice - retezec ukonceny nulou + zastupny znak, na konci prazdny retezec (nula)
.................... const char KeyWords[] =
.................... {
.................... 'P','L','A','Y',0, 'P',
.................... 'E','R','A','S','E',0, 'E',
.................... 'T','E','M','P','O',0, 't',
.................... 'P','A','U','S','E',0, 'p',
.................... 'B','E','G','I','N',0, 'B',
.................... 'T','E','S','T',0, 'b',
.................... 'E','N','D',0, 'Z',
.................... 'C',0. SOUND_C,
.................... 'C','I','S',0, SOUND_Cis,
.................... 'D',0, SOUND_D,
.................... 'D','I','S',0, SOUND_Dis,
.................... 'E',0, SOUND_E,
.................... 'F',0, SOUND_F,
.................... 'F','I','S',0, SOUND_Fis,
.................... 'G',0, SOUND_G,
.................... 'G','I','S',0, SOUND_Gis,
.................... 'A',0, SOUND_A,
.................... 'A','I','S',0, SOUND_Ais,
.................... 'H',0, SOUND_H,
.................... 'S','P','A','C','E',0, SOUND_Space
.................... };
*
0051: BCF 0A.0
0052: BCF 0A.1
0053: BCF 0A.2
0054: ADDWF 02,F
0055: RETLW 50
0056: RETLW 4C
0057: RETLW 41
0058: RETLW 59
0059: RETLW 00
005A: RETLW 50
005B: RETLW 45
005C: RETLW 52
005D: RETLW 41
005E: RETLW 53
005F: RETLW 45
0060: RETLW 00
0061: RETLW 45
0062: RETLW 54
0063: RETLW 45
0064: RETLW 4D
0065: RETLW 50
0066: RETLW 4F
0067: RETLW 00
0068: RETLW 74
0069: RETLW 50
006A: RETLW 41
006B: RETLW 55
006C: RETLW 53
006D: RETLW 45
006E: RETLW 00
006F: RETLW 70
0070: RETLW 42
0071: RETLW 45
0072: RETLW 47
0073: RETLW 49
0074: RETLW 4E
0075: RETLW 00
0076: RETLW 42
0077: RETLW 54
0078: RETLW 45
0079: RETLW 53
007A: RETLW 54
007B: RETLW 00
007C: RETLW 62
007D: RETLW 45
007E: RETLW 4E
007F: RETLW 44
0080: RETLW 00
0081: RETLW 5A
0082: RETLW 43
0083: RETLW 00
0084: RETLW 00
0085: RETLW 43
0086: RETLW 49
0087: RETLW 53
0088: RETLW 00
0089: RETLW 01
008A: RETLW 44
008B: RETLW 00
008C: RETLW 02
008D: RETLW 44
008E: RETLW 49
008F: RETLW 53
0090: RETLW 00
0091: RETLW 03
0092: RETLW 45
0093: RETLW 00
0094: RETLW 04
0095: RETLW 46
0096: RETLW 00
0097: RETLW 05
0098: RETLW 46
0099: RETLW 49
009A: RETLW 53
009B: RETLW 00
009C: RETLW 06
009D: RETLW 47
009E: RETLW 00
009F: RETLW 07
00A0: RETLW 47
00A1: RETLW 49
00A2: RETLW 53
00A3: RETLW 00
00A4: RETLW 08
00A5: RETLW 41
00A6: RETLW 00
00A7: RETLW 09
00A8: RETLW 41
00A9: RETLW 49
00AA: RETLW 53
00AB: RETLW 00
00AC: RETLW 0A
00AD: RETLW 48
00AE: RETLW 00
00AF: RETLW 0B
00B0: RETLW 53
00B1: RETLW 50
00B2: RETLW 41
00B3: RETLW 43
00B4: RETLW 45
00B5: RETLW 00
00B6: RETLW 0C
.................... signed int Word(char line[], unsigned int8 *a, len)
.................... {
.................... unsigned int8 i; // Index do pole klicovych slov
.................... unsigned int8 j; // index do zpracovavane radky
....................
.................... while((line[*a]==' ')&(*a<len)) // Vynech mezery na zacatku
*
03A6: MOVF 62,W
03A7: MOVWF 04
03A8: MOVF 61,W
03A9: ADDWF 00,W
03AA: MOVWF 04
03AB: MOVF 00,W
03AC: SUBLW 20
03AD: BTFSC 03.2
03AE: GOTO 3B1
03AF: MOVLW 00
03B0: GOTO 3B2
03B1: MOVLW 01
03B2: MOVWF 68
03B3: MOVF 62,W
03B4: MOVWF 04
03B5: MOVF 63,W
03B6: SUBWF 00,W
03B7: BTFSS 03.0
03B8: GOTO 3BB
03B9: MOVLW 00
03BA: GOTO 3BC
03BB: MOVLW 01
03BC: ANDWF 68,W
03BD: XORLW 00
03BE: BTFSC 03.2
03BF: GOTO 3C4
.................... (*a)++; // Posouvej ukazovatko
03C0: MOVF 62,W
03C1: MOVWF 04
03C2: INCF 00,F
03C3: GOTO 3A6
....................
.................... for (i=0;i<sizeof(KeyWords);) // Slova ze slovniku
03C4: CLRF 64
03C5: MOVF 64,W
03C6: SUBLW 61
03C7: BTFSS 03.0
03C8: GOTO 430
.................... {
.................... for (j=*a;(j<len)&(KeyWords[i]!=0)&(KeyWords[i]==line[j]);i++,j++) // Znaky ze slova
03C9: MOVF 62,W
03CA: MOVWF 04
03CB: MOVF 00,W
03CC: MOVWF 65
03CD: MOVF 63,W
03CE: SUBWF 65,W
03CF: BTFSS 03.0
03D0: GOTO 3D3
03D1: MOVLW 00
03D2: GOTO 3D4
03D3: MOVLW 01
03D4: MOVWF 66
03D5: MOVF 64,W
03D6: CALL 051
03D7: XORLW 00
03D8: BTFSS 03.2
03D9: GOTO 3DC
03DA: MOVLW 00
03DB: GOTO 3DD
03DC: MOVLW 01
03DD: ANDWF 66,W
03DE: MOVWF 68
03DF: MOVF 64,W
03E0: CALL 051
03E1: MOVWF 69
03E2: MOVF 61,W
03E3: ADDWF 65,W
03E4: MOVWF 04
03E5: MOVF 00,W
03E6: SUBWF 69,W
03E7: BTFSC 03.2
03E8: GOTO 3EB
03E9: MOVLW 00
03EA: GOTO 3EC
03EB: MOVLW 01
03EC: ANDWF 68,W
03ED: XORLW 00
03EE: BTFSC 03.2
03EF: GOTO 3F4
.................... {
.................... }
03F0: MOVF 64,W
03F1: INCF 64,F
03F2: INCF 65,F
03F3: GOTO 3CD
.................... if ((KeyWords[i]==0)&((line[j]==' ')|(j==len)))
03F4: MOVF 64,W
03F5: CALL 051
03F6: XORLW 00
03F7: BTFSC 03.2
03F8: GOTO 3FB
03F9: MOVLW 00
03FA: GOTO 3FC
03FB: MOVLW 01
03FC: MOVWF 67
03FD: MOVF 61,W
03FE: ADDWF 65,W
03FF: MOVWF 04
0400: MOVF 00,W
0401: SUBLW 20
0402: BTFSC 03.2
0403: GOTO 406
0404: MOVLW 00
0405: GOTO 407
0406: MOVLW 01
0407: MOVWF 69
0408: MOVF 63,W
0409: SUBWF 65,W
040A: BTFSC 03.2
040B: GOTO 40E
040C: MOVLW 00
040D: GOTO 40F
040E: MOVLW 01
040F: IORWF 69,W
0410: ANDWF 67,W
0411: XORLW 00
0412: BTFSC 03.2
0413: GOTO 426
.................... {
.................... if (j>=len) j=len-1; // Korekce abychom se nedostali za konec retezce
0414: MOVF 63,W
0415: SUBWF 65,W
0416: BTFSS 03.0
0417: GOTO 41B
0418: MOVLW 01
0419: SUBWF 63,W
041A: MOVWF 65
.................... *a=j+1; // Posun ukazovatko za zpracovane slovo
041B: MOVF 62,W
041C: MOVWF 04
041D: MOVLW 01
041E: ADDWF 65,W
041F: MOVWF 00
....................
.................... return KeyWords[i+1]; // Vrat zastupnou hodnotu z tabulky klicovych slov
0420: MOVLW 01
0421: ADDWF 64,W
0422: CALL 051
0423: MOVWF 78
0424: MOVWF 78
0425: GOTO 432
.................... }
.................... while(KeyWords[i]!=0) i++; // Preskoc zbytek slova v tabulce
0426: MOVF 64,W
0427: CALL 051
0428: XORLW 00
0429: BTFSC 03.2
042A: GOTO 42D
042B: INCF 64,F
042C: GOTO 426
.................... i++; // Preskoc oddelovac
042D: INCF 64,F
.................... i++; // Preskoc polozku se zastupnou hodnotou
042E: INCF 64,F
.................... }
042F: GOTO 3C5
.................... return -1; // Prosli jsme cely slovnik a nedoslo ke shode
0430: MOVLW FF
0431: MOVWF 78
.................... }
....................
....................
.................... // Programovani pres RS232
.................... #define LINELEN 40 // Delka radky pro RS232
.................... #define CR 0x0D // Odradkovani
.................... #define BS 0x08 // Back Space
....................
.................... #separate
.................... void Download()
.................... {
.................... char line[LINELEN]; // Buffer na radku
.................... unsigned char c; // Znak
.................... unsigned int8 a; // Ukazovatko do bufferu
.................... unsigned int8 len; // Delka retezce v radce
.................... unsigned int8 Oct; // Cislo oktavy u noty
....................
.................... output_low(POWER_386); // Zapni napajeni zesilovace
*
034B: BSF 03.5
034C: BCF 05.4
034D: BCF 03.5
034E: BCF 05.4
.................... SoundNote(SOUND_Space,3,10); // Mezera
034F: MOVLW 0C
0350: MOVWF 69
0351: MOVLW 03
0352: MOVWF 6A
0353: CLRF 6C
0354: MOVLW 0A
0355: MOVWF 6B
0356: CALL 0E2
.................... Beep=SoundPGM;
0357: MOVLW 03
0358: MOVWF 33
.................... Error=0;
0359: BCF 2D.1
.................... SpecBeep(); // Pipni na znameni vstupu do programovani
035A: CALL 13B
....................
.................... Tempo=100; // Default hodnoty
035B: CLRF 2F
035C: MOVLW 64
035D: MOVWF 2E
.................... Pause=100;
035E: CLRF 31
035F: MOVWF 30
.................... Octava=0;
0360: CLRF 32
.................... Mode=0; // Mod hrani
0361: BCF 2D.0
.................... Oct=0;
0362: CLRF 60
.................... a=0; // Na zacatku je radka prazdna
0363: CLRF 5E
....................
.................... for(;input(POWER_PIC)==0;) // Opakuj vse dokud je PGM rezim
0364: BSF 03.5
0365: BSF 05.3
0366: MOVLW 00
0367: BCF 03.5
0368: BTFSC 05.3
0369: MOVLW 01
036A: XORLW 00
036B: BTFSS 03.2
036C: GOTO 594
.................... {
.................... Loop:
.................... c=Getc(); // Vezmi znak ze seriovky
036D: CALL 153
036E: MOVF 78,W
036F: MOVWF 5D
.................... if (c>=0x80) goto Loop; // Ignoruj znaky nad ASCII
0370: MOVF 5D,W
0371: SUBLW 7F
0372: BTFSC 03.0
0373: GOTO 375
0374: GOTO 36D
.................... if (c>=0x60) c=c-0x20; // Preved velka pismena na velka pismena
0375: MOVF 5D,W
0376: SUBLW 5F
0377: BTFSC 03.0
0378: GOTO 37B
0379: MOVLW 20
037A: SUBWF 5D,F
.................... if ((c==CR)|(c=='/')) // Konec radky nebo komentar
037B: MOVF 5D,W
037C: SUBLW 0D
037D: BTFSC 03.2
037E: GOTO 381
037F: MOVLW 00
0380: GOTO 382
0381: MOVLW 01
0382: MOVWF 61
0383: MOVF 5D,W
0384: SUBLW 2F
0385: BTFSC 03.2
0386: GOTO 389
0387: MOVLW 00
0388: GOTO 38A
0389: MOVLW 01
038A: IORWF 61,W
038B: XORLW 00
038C: BTFSC 03.2
038D: GOTO 560
.................... {
.................... while (c!=CR) c=Getc(); // Zpracuj znaky komentare
038E: MOVF 5D,W
038F: SUBLW 0D
0390: BTFSC 03.2
0391: GOTO 396
0392: CALL 153
0393: MOVF 78,W
0394: MOVWF 5D
0395: GOTO 38E
.................... len=a; // Zapamatuj si delku radky
0396: MOVF 5E,W
0397: MOVWF 5F
.................... a=0; // Postav se na zacatek radky
0398: CLRF 5E
.................... Beep=SoundEndOfLine; // Default zuk na konci radky
0399: MOVLW 01
039A: MOVWF 33
.................... // Zpracovani radky
.................... while(a<len)
039B: MOVF 5F,W
039C: SUBWF 5E,W
039D: BTFSC 03.0
039E: GOTO 55D
.................... {
.................... restart_wdt(); // Nuluj watchdog abychom se nezresetovali
039F: CLRWDT
.................... c=Word(line,&a,len);
03A0: MOVLW 35
03A1: MOVWF 61
03A2: MOVLW 5E
03A3: MOVWF 62
03A4: MOVF 5F,W
03A5: MOVWF 63
*
0432: MOVF 78,W
0433: MOVWF 5D
.................... if (c==-1) // Nezname klicove slovo
0434: MOVF 5D,W
0435: SUBLW FF
0436: BTFSS 03.2
0437: GOTO 46B
.................... {
.................... if (a<len) // Nejsme uz na konci radky ??
0438: MOVF 5F,W
0439: SUBWF 5E,W
043A: BTFSC 03.0
043B: GOTO 46A
.................... {
.................... if ((line[a]>='0')&(line[a]<='9')) // Stojime na cislici -> je to cislo
043C: MOVLW 35
043D: ADDWF 5E,W
043E: MOVWF 04
043F: MOVF 00,W
0440: SUBLW 2F
0441: BTFSS 03.0
0442: GOTO 445
0443: MOVLW 00
0444: GOTO 446
0445: MOVLW 01
0446: MOVWF 62
0447: MOVLW 35
0448: ADDWF 5E,W
0449: MOVWF 04
044A: MOVF 00,W
044B: SUBLW 39
044C: BTFSC 03.0
044D: GOTO 450
044E: MOVLW 00
044F: GOTO 451
0450: MOVLW 01
0451: ANDWF 62,W
0452: XORLW 00
0453: BTFSC 03.2
0454: GOTO 461
.................... {
.................... // Oct=Number(line,&a,len)&0x7; // tohle nefunguje protoze je chyba v prekladaci
.................... Oct=Number(line,&a,len); // prekladac prepoklada, z W obsahuje spodni bajt vysledku
0455: MOVLW 35
0456: MOVWF 61
0457: MOVLW 5E
0458: MOVWF 62
0459: MOVF 5F,W
045A: MOVWF 63
045B: CALL 190
045C: MOVF 78,W
045D: MOVWF 60
.................... Oct&=0x7; // ale k navratu pouziva RETLW 0 coz smaze W !
045E: MOVLW 07
045F: ANDWF 60,F
.................... }
.................... else // Stojime na pismenu nebo oddelovaci
0460: GOTO 46A
.................... {
.................... if (line[a]!=' ') Error=1; // Neni to oddelovac - chyba
0461: MOVLW 35
0462: ADDWF 5E,W
0463: MOVWF 04
0464: MOVF 00,W
0465: SUBLW 20
0466: BTFSC 03.2
0467: GOTO 469
0468: BSF 2D.1
.................... a++; // Preskocim 1 znak (a kdyz to nepomuze dostanu se zase sem)
0469: INCF 5E,F
.................... }
.................... }
.................... }
.................... else if (c=='P') // Play
046A: GOTO 55C
046B: MOVF 5D,W
046C: SUBLW 50
046D: BTFSS 03.2
046E: GOTO 47D
.................... {
.................... CisloSkladby=Number(line,&a,len);
046F: MOVLW 35
0470: MOVWF 61
0471: MOVLW 5E
0472: MOVWF 62
0473: MOVF 5F,W
0474: MOVWF 63
0475: CALL 190
0476: MOVF 78,W
0477: MOVWF 34
.................... Mode=0;
0478: BCF 2D.0
.................... Play();
0479: CALL 27D
.................... Beep=SoundPGM;
047A: MOVLW 03
047B: MOVWF 33
.................... }
.................... else if (c=='E') // Erase
047C: GOTO 55C
047D: MOVF 5D,W
047E: SUBLW 45
047F: BTFSS 03.2
0480: GOTO 4BB
.................... {
.................... Mode=0;
0481: BCF 2D.0
.................... Erase();
.................... Beep=SoundPGM;
*
04B8: MOVLW 03
04B9: MOVWF 33
.................... }
.................... else if (c=='t') // Tempo
04BA: GOTO 55C
04BB: MOVF 5D,W
04BC: SUBLW 74
04BD: BTFSS 03.2
04BE: GOTO 4DB
.................... {
.................... Tempo=Number(line,&a,len)&~MASKTEMPO;
04BF: MOVLW 35
04C0: MOVWF 61
04C1: MOVLW 5E
04C2: MOVWF 62
04C3: MOVF 5F,W
04C4: MOVWF 63
04C5: CALL 190
04C6: MOVF 78,W
04C7: MOVWF 2E
04C8: MOVF 79,W
04C9: ANDLW C7
04CA: MOVWF 2F
.................... if (Tempo==0) Tempo=100;
04CB: MOVF 2E,F
04CC: BTFSS 03.2
04CD: GOTO 4D4
04CE: MOVF 2F,F
04CF: BTFSS 03.2
04D0: GOTO 4D4
04D1: CLRF 2F
04D2: MOVLW 64
04D3: MOVWF 2E
.................... Data=Tempo|DATATEMPO;
04D4: MOVF 2E,W
04D5: MOVWF 2B
04D6: MOVF 2F,W
04D7: IORLW 28
04D8: MOVWF 2C
.................... WriteDataInc(); // Podmineny zapis do FLASH a posun na dalsi adresu
04D9: CALL 2E0
.................... }
.................... else if (c=='p') // Pause
04DA: GOTO 55C
04DB: MOVF 5D,W
04DC: SUBLW 70
04DD: BTFSS 03.2
04DE: GOTO 4FB
.................... {
.................... Pause=Number(line,&a,len)&~MASKPAUSE;
04DF: MOVLW 35
04E0: MOVWF 61
04E1: MOVLW 5E
04E2: MOVWF 62
04E3: MOVF 5F,W
04E4: MOVWF 63
04E5: CALL 190
04E6: MOVF 78,W
04E7: MOVWF 30
04E8: MOVF 79,W
04E9: ANDLW C7
04EA: MOVWF 31
.................... if (Pause==0) Pause=100;
04EB: MOVF 30,F
04EC: BTFSS 03.2
04ED: GOTO 4F4
04EE: MOVF 31,F
04EF: BTFSS 03.2
04F0: GOTO 4F4
04F1: CLRF 31
04F2: MOVLW 64
04F3: MOVWF 30
.................... Data=Pause|DATAPAUSE;
04F4: MOVF 30,W
04F5: MOVWF 2B
04F6: MOVF 31,W
04F7: IORLW 30
04F8: MOVWF 2C
.................... WriteDataInc(); // Podmineny zapis do FLASH a posun na dalsi adresu
04F9: CALL 2E0
.................... }
.................... else if (c=='B') // Begin
04FA: GOTO 55C
04FB: MOVF 5D,W
04FC: SUBLW 42
04FD: BTFSS 03.2
04FE: GOTO 512
.................... {
.................... CisloSkladby=~0; // Neplatne cislo skladby
04FF: MOVLW FF
0500: MOVWF 34
.................... Find(); // najde konec posledni skladby
0501: CALL 208
.................... Octava=Number(line,&a,len)&~MASKBEGIN;
0502: MOVLW 35
0503: MOVWF 61
0504: MOVLW 5E
0505: MOVWF 62
0506: MOVF 5F,W
0507: MOVWF 63
0508: CALL 190
0509: MOVF 78,W
050A: MOVWF 32
.................... Data=DATABEGIN|Octava; // Zacatecni znacka
050B: MOVF 32,W
050C: MOVWF 2B
050D: MOVLW 20
050E: MOVWF 2C
.................... Mode=1; // Mod zapisu do FLASH pameti
050F: BSF 2D.0
.................... WriteDataInc(); // Podmineny zapis do FLASH a posun na dalsi adresu
0510: CALL 2E0
.................... }
.................... else if (c=='b') // Test
0511: GOTO 55C
0512: MOVF 5D,W
0513: SUBLW 62
0514: BTFSS 03.2
0515: GOTO 521
.................... {
.................... Octava=Number(line,&a,len)&~MASKBEGIN;
0516: MOVLW 35
0517: MOVWF 61
0518: MOVLW 5E
0519: MOVWF 62
051A: MOVF 5F,W
051B: MOVWF 63
051C: CALL 190
051D: MOVF 78,W
051E: MOVWF 32
.................... Mode=0;
051F: BCF 2D.0
.................... }
.................... else if (c=='Z') // End
0520: GOTO 55C
0521: MOVF 5D,W
0522: SUBLW 5A
0523: BTFSS 03.2
0524: GOTO 527
.................... {
.................... Mode=0;
0525: BCF 2D.0
.................... }
.................... else // Nota
0526: GOTO 55C
.................... {
.................... Data=Number(line,&a,len); // Delka noty (nepovinna)
0527: MOVLW 35
0528: MOVWF 61
0529: MOVLW 5E
052A: MOVWF 62
052B: MOVF 5F,W
052C: MOVWF 63
052D: CALL 190
052E: MOVF 79,W
052F: MOVWF 2C
0530: MOVF 78,W
0531: MOVWF 2B
.................... Data&=0x3F; // Jen platny rozsah
0532: MOVLW 3F
0533: ANDWF 2B,F
0534: MOVLW 00
0535: ANDWF 2C,F
.................... if (Data==0) Data++; // Je-li nulova delka - dej jednotkovou
0536: MOVF 2B,F
0537: BTFSS 03.2
0538: GOTO 53F
0539: MOVF 2C,F
053A: BTFSS 03.2
053B: GOTO 53F
053C: INCF 2B,F
053D: BTFSC 03.2
053E: INCF 2C,F
.................... Data<<=7; // Delka
053F: RLF 2B,F
0540: RLF 2C,F
0541: RLF 2B,F
0542: RLF 2C,F
0543: RLF 2B,F
0544: RLF 2C,F
0545: RLF 2B,F
0546: RLF 2C,F
0547: RLF 2B,F
0548: RLF 2C,F
0549: RLF 2B,F
054A: RLF 2C,F
054B: RLF 2B,F
054C: RLF 2C,F
054D: MOVLW 80
054E: ANDWF 2B,F
.................... Data|=c; // Nota
054F: MOVF 5D,W
0550: IORWF 2B,F
.................... Data|=(Oct<<4); // Oktava
0551: SWAPF 60,W
0552: MOVWF 77
0553: MOVLW F0
0554: ANDWF 77,F
0555: MOVF 77,W
0556: IORWF 2B,F
.................... WriteDataInc(); // Podmineny zapis do FLASH a posun na dalsi adresu
0557: CALL 2E0
.................... if (~Mode)
0558: BTFSC 2D.0
0559: GOTO 55C
.................... {
.................... PlayData(); // Zahraj notu
055A: CALL 237
.................... Beep=0; // Po zahrani noty uz nepipej na konci radky
055B: CLRF 33
.................... }
.................... }
.................... }
055C: GOTO 39B
.................... a=0; // Radka zpracovana, nuluj jeji delku
055D: CLRF 5E
.................... SpecBeep(); // Pipni
055E: CALL 13B
.................... goto Loop;
055F: GOTO 36D
.................... }
.................... if ((c==BS)&(a>0)) {a--;goto Loop;} // Smaz znak
0560: MOVF 5D,W
0561: SUBLW 08
0562: BTFSC 03.2
0563: GOTO 566
0564: MOVLW 00
0565: GOTO 567
0566: MOVLW 01
0567: MOVWF 61
0568: MOVF 5E,F
0569: BTFSS 03.2
056A: GOTO 56D
056B: MOVLW 00
056C: GOTO 56E
056D: MOVLW 01
056E: ANDWF 61,W
056F: XORLW 00
0570: BTFSC 03.2
0571: GOTO 574
0572: DECF 5E,F
0573: GOTO 36D
.................... if ((c==',')|(c<=' ')) c=' '; // Vsechny ostatni ridici znaky i carka jsou oddelovac
0574: MOVF 5D,W
0575: SUBLW 2C
0576: BTFSC 03.2
0577: GOTO 57A
0578: MOVLW 00
0579: GOTO 57B
057A: MOVLW 01
057B: MOVWF 61
057C: MOVF 5D,W
057D: SUBLW 20
057E: BTFSC 03.0
057F: GOTO 582
0580: MOVLW 00
0581: GOTO 583
0582: MOVLW 01
0583: IORWF 61,W
0584: XORLW 00
0585: BTFSC 03.2
0586: GOTO 589
0587: MOVLW 20
0588: MOVWF 5D
.................... if (a<LINELEN) line[a++]=c; // Zapis znak do bufferu a posun ukazovatko
0589: MOVF 5E,W
058A: SUBLW 27
058B: BTFSS 03.0
058C: GOTO 593
058D: MOVF 5E,W
058E: INCF 5E,F
058F: ADDLW 35
0590: MOVWF 04
0591: MOVF 5D,W
0592: MOVWF 00
.................... }
0593: GOTO 364
0594: GOTO 5CB (RETURN)
.................... }
....................
....................
.................... // Tabulka pro prekodovani tlacitek
.................... const int8 KeyTranslate[16] = {0, 1, 2, 5, 3, 6, 8, 11, 4, 7, 9, 12, 10, 13, 14, 15};
*
00B7: BCF 0A.0
00B8: BCF 0A.1
00B9: BCF 0A.2
00BA: ADDWF 02,F
00BB: RETLW 00
00BC: RETLW 01
00BD: RETLW 02
00BE: RETLW 05
00BF: RETLW 03
00C0: RETLW 06
00C1: RETLW 08
00C2: RETLW 0B
00C3: RETLW 04
00C4: RETLW 07
00C5: RETLW 09
00C6: RETLW 0C
00C7: RETLW 0A
00C8: RETLW 0D
00C9: RETLW 0E
00CA: RETLW 0F
....................
.................... void main()
.................... {
*
0595: CLRF 04
0596: MOVLW 1F
0597: ANDWF 03,F
0598: MOVLW 07
0599: BSF 03.5
059A: MOVWF 1F
059B: BCF 05.0
059C: BCF 03.5
059D: BCF 05.0
.................... Start:
....................
.................... if (restart_cause()==WDT_FROM_SLEEP) // Osetreni probuzeni od WDT
059E: MOVF 03,W
059F: ANDLW 18
05A0: XORLW 00
05A1: BTFSS 03.2
05A2: GOTO 5A4
.................... {
.................... sleep();
05A3: SLEEP
.................... }
.................... // Inicializace WDT
.................... // setup_wdt(WDT_16MS); // nelze pouzit, zabira 15 instukci
.................... #asm
.................... bsf 0x03,5 // banka 1 nebo 3 aby se mohlo k OPTION registu
05A4: BSF 03.5
.................... bcf 0x81,3 // WDT primo tedy 16ms
.................... #endasm
05A5: BSF 03.5
05A6: BCF 01.3
....................
.................... // Inicializace
.................... port_b_pullups(TRUE); // Zapni pull-up odpory na portu B
05A7: BCF 01.7
.................... set_tris_a(0b00001000); // Nastav nepouzite vyvody jako vystupy
05A8: MOVLW 08
05A9: MOVWF 05
.................... set_tris_b(0b11110000); // 1 znamena vstup
05AA: MOVLW F0
05AB: MOVWF 06
.................... *0x9F = 6; // Vsechny vstupy jsou digitalni
05AC: MOVLW 06
05AD: MOVWF 1F
....................
.................... // Test na rezim programovani
.................... if ((input(POWER_PIC)==0)&(input(RXD)==0)) // Podminka programovani
05AE: BSF 05.3
05AF: MOVLW 00
05B0: BCF 03.5
05B1: BTFSC 05.3
05B2: MOVLW 01
05B3: XORLW 00
05B4: BTFSC 03.2
05B5: GOTO 5B8
05B6: MOVLW 00
05B7: GOTO 5B9
05B8: MOVLW 01
05B9: MOVWF 36
05BA: BSF 03.5
05BB: BSF 06.1
05BC: MOVLW 00
05BD: BCF 03.5
05BE: BTFSC 06.1
05BF: MOVLW 01
05C0: XORLW 00
05C1: BTFSC 03.2
05C2: GOTO 5C5
05C3: MOVLW 00
05C4: GOTO 5C6
05C5: MOVLW 01
05C6: ANDWF 36,W
05C7: XORLW 00
05C8: BTFSC 03.2
05C9: GOTO 5CB
.................... Download(); // Pripojen RS232 a propojka na PGM
05CA: GOTO 34B
....................
.................... // Zapnuti napajeni
.................... output_low(POWER_PIC); // Pripoj GND pro procesor
05CB: BSF 03.5
05CC: BCF 05.3
05CD: BCF 03.5
05CE: BCF 05.3
.................... SoundNote(SOUND_Space,3,10); // Mezera
05CF: MOVLW 0C
05D0: MOVWF 69
05D1: MOVLW 03
05D2: MOVWF 6A
05D3: CLRF 6C
05D4: MOVLW 0A
05D5: MOVWF 6B
05D6: CALL 0E2
.................... output_low(POWER_386); // Zapni napajeni zesilovace
05D7: BSF 03.5
05D8: BCF 05.4
05D9: BCF 03.5
05DA: BCF 05.4
.................... SoundNote(SOUND_Space,3,100); // Mezera (jinak se chybne detekuje tlacitko)
05DB: MOVLW 0C
05DC: MOVWF 69
05DD: MOVLW 03
05DE: MOVWF 6A
05DF: CLRF 6C
05E0: MOVLW 64
05E1: MOVWF 6B
05E2: CALL 0E2
....................
.................... // Cteni tlacitek
.................... #use FAST_IO(B)
.................... CisloSkladby=(input_b() >> 4) ^ 0xFF & 0xF; // Precti stav tlacitek
05E3: SWAPF 06,W
05E4: MOVWF 77
05E5: MOVLW 0F
05E6: ANDWF 77,F
05E7: MOVF 77,W
05E8: XORLW 0F
05E9: MOVWF 34
.................... #use STANDARD_IO(B)
.................... CisloSkladby=KeyTranslate[CisloSkladby]; // Prekoduj je do binarniho kodu
05EA: MOVF 34,W
05EB: CALL 0B7
05EC: MOVWF 78
05ED: MOVWF 34
....................
.................... // Prehrani skladby
.................... Play(); // Zahraj skladbu
05EE: CALL 27D
....................
.................... // Po odehrani usni a cekej na zmacknuti tlacitka
.................... #use FAST_IO(B)
.................... if (input_B()); // Precti stav portu B (vuci tomuto stavu se bude hlidat zmena)
05EF: MOVF 06,W
05F0: XORLW 00
05F1: BTFSC 03.2
05F2: GOTO 5F3
.................... #use STANDARD_IO(B)
.................... bit_clear(*0xB,0); // Nuluj priznak preruseni od zmeny stavu portu B
05F3: BCF 0B.0
.................... enable_interrupts(INT_RB); // Povol preruseni od zmeny stavu portu B
05F4: BSF 0B.3
....................
.................... output_high(POWER_386); // Vypni napajeni zesilovace
05F5: BSF 03.5
05F6: BCF 05.4
05F7: BCF 03.5
05F8: BSF 05.4
.................... output_float(POWER_PIC); // Odpoj GND
05F9: BSF 03.5
05FA: BSF 05.3
....................
.................... Sleep(); // Usni aby byla minimalni klidova spotreba
05FB: SLEEP
....................
.................... disable_interrupts(INT_RB); // Zakaz preruseni od portu
05FC: BCF 03.5
05FD: BCF 0B.3
.................... goto Start; // Po probuzeni skoc na zacatek
05FE: GOTO 59E
.................... }
....................
05FF: SLEEP
/Designs/MB01B/SW/1_01/SKLADBY/BednaOdWhisky.txt
0,0 → 1,126
// Pisnicka "Bedna od Whisky"
//
// Tato pisnicka je napsana ve formatu, ktery se da pouzit jak pro primy
// preklad do firmwaru melodickeho zvonku tak i pro dodatecne nahrani
 
BEGIN 2, // Zacatek skladby
TEMPO 100, // Delka nejkratsi noty v ms
PAUSE 100, // Delka mezery mezi notami
 
1 A 2,
2 C 2,
2 E 2,
2 A 2,
2 G 4,
2 E 2,
2 E 2,
2 A 2,
2 G 2,
2 E 2,
2 D 2,
2 E 4,
Space 4,
1 A 2,
2 C 2,
2 E 2,
2 A 2,
2 G 2,
2 G 2,
2 E 2,
2 E 2,
1 A 2,
2 E 2,
1 H 2,
2 E 2,
1 A 4,
Space 4,
1 A 2,
2 C 2,
2 E 2,
2 A 2,
2 G 2,
2 G 2,
2 E 4,
2 A 2,
2 G 2,
2 E 2,
2 D 2,
2 E 4,
Space 2,
2 E 2,
1 A 2,
2 C 2,
2 E 2,
2 A 2,
2 G 2,
2 E 4,
2 E 2,
2 A 2,
2 A 2,
2 GIS 2,
2 H 2,
2 A 4,
Space 8,
2 E 2,
2 A 2,
2 A 2,
2 A 2,
2 GIS 2,
2 FIS 2,
2 A 4,
2 A 2,
2 H 2,
2 H 2,
2 A 2,
2 H 2,
3 CIS 2,
2 A 4,
2 E 2,
2 A 2,
2 A 2,
2 A 2,
2 GIS 2,
2 FIS 2,
2 A 2,
2 A 2,
2 A 2,
2 H 2,
2 H 2,
2 A 2,
2 GIS 2,
2 A 4,
Space 2,
2 E 2,
2 A 2,
2 A 2,
2 A 2,
2 GIS 2,
2 FIS 2,
2 A 4,
2 A 2,
2 H 2,
2 H 2,
2 A 2,
2 H 2,
3 CIS 2,
2 A 4,
2 E 2,
2 A 2,
2 A 2,
2 A 2,
2 GIS 2,
2 FIS 2,
2 A 2,
Space 2,
2 A 2,
2 H 2,
2 H 2,
2 A 2,
2 GIS 2,
2 A 8,
2 G 2,
2 A 8,
2 G 2,
2 A 8,
 
END
/Designs/MB01B/SW/1_01/SKLADBY/KdyzMeBaliZaVojacka.txt
0,0 → 1,58
// Pisnicka "Kdyz me brali za vojacka"
//
// Tato pisnicka je napsana ve formatu, ktery se da pouzit jak pro primy
// preklad do firmwaru melodickeho zvonku tak i pro dodatecne nahrani
 
BEGIN 2, // Zacatek skladby
TEMPO 150, // Delka nejkratsi noty v ms
PAUSE 100, // Delka mezery mezi notami
 
1 A 1,
2 C 1,
2 E 1,
2 D 1,
2 C 1,
1 H 1,
2 C 2,
2 D 1,
2 E 2,
2 D 1,
2 G 1,
2 G 1,
2 G 1,
2 G 1,
2 A 1,
2 E 2,
Space 4,
2 D 1,
2 F 1,
2 A 1,
2 G 1,
2 F 1,
2 E 1,
2 E 1,
2 F 1,
2 E 1,
2 C 1,
1 A 2,
1 GIS 1,
1 H 1,
2 E 1,
2 D 1,
1 H 1,
2 C 1,
1 A 2,
Space 2,
1 H 2,
2 C 2,
Space 2,
2 D 2,
2 E 1,
2 E 1,
2 E 1,
2 D 1,
1 H 1,
2 C 1,
1 A 2,
 
END
/Designs/MB01B/SW/1_01/SKLADBY/Medvedi.txt
0,0 → 1,173
// Pisnicka "Medvedi"
//
// Tato pisnicka je napsana ve formatu, ktery se da pouzit jak pro primy
// preklad do firmwaru melodickeho zvonku tak i pro dodatecne nahrani
 
BEGIN 1, // Zacatek skladby
TEMPO 150, // Delka nejkratsi noty v ms
PAUSE 100, // Delka mezery mezi notami
 
1 C 1, // 1
1 C 1,
1 C 1,
1 E 1,
1 D 1,
0 G 1,
 
1 C 3, // 2
Space 4,
 
1 E 1, // 3
1 E 1,
1 E 1,
1 E 1,
1 D 1,
1 G 1,
 
1 E 2, // 4
Space 4,
 
1 G 1, // 5
1 G 1,
1 A 1,
1 G 1,
1 F 1,
1 E 1,
 
1 F 1, // 6
1 A 1,
1 G 1,
1 F 1,
1 E 1,
1 D 1,
 
1 C 1, // 7
0 H 1,
1 C 1,
1 E 1,
1 D 1,
0 G 1,
 
1 C 3, // 8
Space 4,
1 A 1, // 9
1 A 1,
1 A 1,
1 A 1,
1 H 1,
2 D 1,
 
2 C 4, // 10
Space 2,
 
2 E 1, // 11
2 E 1,
2 E 1,
2 E 1,
2 D 1,
2 G 1,
 
2 E 4, // 12
Space 2,
 
2 G 1, // 13
2 G 1,
2 A 1,
2 G 1,
2 F 1,
2 E 1,
 
2 F 1, // 14
2 A 1,
2 G 1,
2 F 1,
2 E 1,
2 D 1,
 
2 C 1, // 15
1 H 1,
2 C 1,
2 E 1,
2 D 1,
1 G 1,
 
2 C 4, // 16
Space 2,
 
1 C 6, // 1
0 G 2,
 
1 D 3, // 2
Space 3,
 
1 G 1, // 3
1 G 1,
1 Fis 1,
1 G 1,
1 A 1,
1 Fis 1,
 
1 G 2, // 4
Space 4,
 
1 G 1, // 5
1 G 1,
1 A 1,
1 G 1,
1 F 1,
1 E 1,
 
1 F 1, // 6
1 A 1,
1 G 1,
1 F 1,
1 E 1,
1 D 1,
 
1 C 6, // 7
1 E 2,
 
1 D 3, // 8
Space 3,
 
1 C 6, // 9
0 G 2,
 
1 D 3, // 10
Space 3,
 
1 G 1, // 11
1 G 1,
1 Fis 1,
1 G 1,
1 A 1,
1 Fis 1,
 
1 G 2, // 12
Space 4,
 
1 G 1, // 13
1 G 1,
1 A 1,
1 G 1,
1 F 1,
1 E 1,
 
1 F 1, // 14
1 A 1,
1 G 1,
1 F 1,
1 E 1,
1 D 1,
 
1 C 1, // 15
0 H 1,
1 C 1,
1 E 1,
1 D 1,
0 G 1,
 
1 C 2, // 16
Space 4,
 
END
/Designs/MB01B/SW/1_01/SKLADBY/Test.txt
0,0 → 1,27
// Testovaci posloupnost vsech not
//
// Tento soubor nelze vlozit do zdrojaku, da se jen natahnout po seriovce
// Nezapomente prosim, ze delka radky s notami je maximalne 40 znaku
 
BEGIN 0, // Zacatek skladby bez posunuti oktavy
TEMPO 2000, // Kazdy ton bude znit 2s aby se dala zmerit frekvence
PAUSE 100, // Delka mezery mezi notami
 
0 C Cis D Dis E F Fis G Gis A Ais H
Space
1 C Cis D Dis E F Fis G Gis A Ais H
Space
2 C Cis D Dis E F Fis G Gis A Ais H
Space
3 C Cis D Dis E F Fis G Gis A Ais H
Space
4 C Cis D Dis E F Fis G Gis A Ais H
Space
5 C Cis D Dis E F Fis G Gis A Ais H
Space
6 C Cis D Dis E F Fis G Gis A Ais H
Space
7 C Cis D Dis E F Fis G Gis A Ais H
Space
 
END
/Designs/MB01B/SW/1_01/SKLADBY/TheFinalSoundDown.txt
0,0 → 1,61
// Pisnicka "The Final Sound Down"
//
// Tato pisnicka je napsana ve formatu, ktery se da pouzit jak pro primy
// preklad do firmwaru melodickeho zvonku tak i pro dodatecne nahrani
 
BEGIN 3, // Zacatek skladby
TEMPO 100, // Delka nejkratsi noty v ms
PAUSE 100, // Delka mezery mezi notami
 
1 A 1,
1 G 1,
1 A 4,
1 D 4,
Space 2,
 
1 Ais 1,
1 A 1,
1 Ais 2,
1 A 2,
1 G 4,
Space 2,
 
1 Ais 1,
1 A 1,
1 Ais 4,
1 D 4,
Space 2,
 
1 G 1,
1 F 1,
1 G 2,
1 F 2,
1 E 2,
1 G 2,
1 F 4,
Space 2,
 
1 E 1,
1 F 1,
1 G 4,
Space 2,
 
1 F 1,
1 G 1,
1 A 2,
1 G 2,
1 F 2,
1 E 2,
1 D 4,
1 Ais 4,
1 A 4,
Space 2,
 
1 A 1,
1 Ais 1,
1 A 1,
1 G 1,
1 A 4,
Space 2,
 
END
/Designs/MB01B/SW/1_01/SOUND_T1.C
0,0 → 1,209
// Knihovna pro generovani hudebnich zvuku dane frekvence a delky nebo
// dane noty temperovaneho ladeni a delky.
//
// Pro gnerovani pouziva casovac T0, T1 a jednotku CCP1.
//
// POZOR -- POZOR -- POZOR
// Pri nizsi frekvenci XTALu (nez asi 5MHz) je rezie preruseni tak velka, ze spotrebuje
// veskery strojovy cas a uz nedojde k ukonceni rozehraneho tonu vyssi frekvence (z oktavy 7
// nebo nad cca 8KHz). Resenim je pouzit vlastni INT proceduru s minimalni rezii.
//
// (c)miho 2004, pefi 2004,
//
// Historie
// 1.00 Uvodni verze
// 1.01 Pridana podpora zapnuteho WDT
 
// Konfiguracni parametry
//#define SOUND_HI PIN_xx // Pozitivni vystup
//#define SOUND_LO PIN_xx // Komplementarni vystup
//#define SOUND_WDT 1 // Pokud je pouzit WDT
#ifndef SOUND_CLOCK
#define SOUND_CLOCK 4000000 // Frelvence krystalu v Hz
#endif
 
 
// Definice hudebnich tonu (not) pro proceduru SoundNote()
#define SOUND_C 0
#define SOUND_Cis 1
#define SOUND_D 2
#define SOUND_Dis 3
#define SOUND_E 4
#define SOUND_F 5
#define SOUND_Fis 6
#define SOUND_G 7
#define SOUND_Gis 8
#define SOUND_A 9
#define SOUND_Ais 10
#define SOUND_H 11
#define SOUND_Space 12 // Pomlka
 
 
// Prototypy verejnych procedur
 
void SoundBeep(unsigned int16 Frequency, unsigned int16 Duration);
// Predava se frekvence v Hz a doba trvani v ms (0 znamena ticho)
 
void SoundNote(unsigned int8 Note, Octave, unsigned int16 Duration);
// Predava se cislo noty (0 je C), posunuti v oktavach (0 nejnizsi ton,
// SOUND_Space je ticho), doba trvani v ms
 
// Alternativni makra pro generovani konstatnich tonu
// SoundBeepMacro(Frequency, Duration) - frekvence nesmi byt 0
// SoundNoteMacro(Note, Octave, Duration) - nepodporuje SOUND_Space
// SoundSpaceMacro(Duration) - hraje ticho
 
// Privatni cast
 
 
#int_ccp1
void IntCCP1()
// Preruseni od jednotky CCP1 generuje vystup
{
volatile int1 Data; // Posledni stav vystupu
output_bit(SOUND_HI,Data); // Nastav vystup
output_bit(SOUND_LO,~Data);
Data=~Data; // Otoc stav vystupu
}
 
 
#if SOUND_CLOCK < (65535*32*4*2) // < 16.7 MHz
#define SOUND_PRESCALE 1
#elif SOUND_CLOCK < (65535*32*4*2*2) // < 33.6 MHz
#define SOUND_PRESCALE 2
#elif SOUND_CLOCK < (65535*32*4*2*4) // < 67.1 MHz
#define SOUND_PRESCALE 4
#elif SOUND_CLOCK < (65535*32*4*2*8) // < 134 MHz
#define SOUND_PRESCALE 8
#else
#error SOUND_CLOCK Frequency too high
#endif
#bit T0IF=0x0B.2
void SoundBeep(unsigned int16 Frequency, unsigned int16 Duration)
// Predava se frekvence v Hz a doba trvani v ms (0 znamena ticho)
// Rozumne frekvence jsou od 32Hz
{
unsigned int16 Time; // Pocitadlo zlomkoveho casu
 
// Inicializace casovace
if (Frequency!=0) // Frekvence 0 znamena ticho
{
setup_ccp1(CCP_COMPARE_RESET_TIMER);
set_timer1(0);
(int16)CCP_1=SOUND_CLOCK/SOUND_PRESCALE/4/2/Frequency;
#if SOUND_PRESCALE==1
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
#elif SOUND_PRESCALE==2
setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
#elif SOUND_PRESCALE==4
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
#elif SOUND_PRESCALE==8
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
#endif
enable_interrupts(int_ccp1);
enable_interrupts(global);
}
 
// Delka tonu merena casovacem T0 (bez preruseni)
Time=0;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
while (Duration)
{
#ifdef SOUND_WDT
restart_wdt(); // Nuluj watchdog abychom se nezresetovali
#endif
if (T0IF) // Preteceni T0 - kazdych (1/CLK)*4*256
{
T0IF = 0;
Time += (256*4*1000*2048+SOUND_CLOCK/2)/SOUND_CLOCK;
}
if (Time>>11)
{
Time -= 2048;
Duration--;
}
}
 
// Konec casovace
disable_interrupts(int_ccp1);
disable_interrupts(global);
}
 
 
// Definice casu pulperody pro nejnizsi oktavu, v kvantech casovace T1
// Pulperiody tonu v dalsich oktavach se ziskavaji rotaci vpravo
#define SOUND_Peri_C ((30578*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 30578us
#define SOUND_Peri_Cis ((28862*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 28862us
#define SOUND_Peri_D ((27242*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 27242us
#define SOUND_Peri_Dis ((25713*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 25713us
#define SOUND_Peri_E ((24270*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 24270us
#define SOUND_Peri_F ((22908*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 22908us
#define SOUND_Peri_Fis ((21622*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 21622us
#define SOUND_Peri_G ((20408*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 20408us
#define SOUND_Peri_Gis ((19263*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 19263us
#define SOUND_Peri_A ((18182*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 18182us
#define SOUND_Peri_Ais ((17161*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 17161us
#define SOUND_Peri_H ((16198*(SOUND_CLOCK/1000)/1000/4/2)/SOUND_PRESCALE) // Perioda 16198us
 
// Kontrola na delku konstanty (musi byt mensi nez delka citace)
#if SOUND_Peri_C > 65535
#error "SOUND_Peri_C too long (Note C requires delay > 65535 cycles)"
#endif
 
// Casove konstanty pro noty nejnizsi oktavy
const unsigned int16 Table[12] =
SOUND_Peri_C, SOUND_Peri_Cis, SOUND_Peri_D, SOUND_Peri_Dis,
SOUND_Peri_E, SOUND_Peri_F, SOUND_Peri_Fis, SOUND_Peri_G,
SOUND_Peri_Gis, SOUND_Peri_A, SOUND_Peri_Ais, SOUND_Peri_H;
 
 
void SoundNote(unsigned int8 Note, Octave, unsigned int16 Duration)
// Predava se cislo noty (0 je C), posunuti v oktavach (0 nejnizsi ton)
// doba trvani v ms (0 znamena ticho)
// Zahraje zadanou notu v zadane oktave dane delky
{
unsigned int16 Time; // Pocitadlo zlomkoveho casu
 
// Inicializace casovace
if (Note!=SOUND_Space) // Pokud se ma hrat spust hrani
{
setup_ccp1(CCP_COMPARE_RESET_TIMER);
set_timer1(0);
(int16)CCP_1=Table[Note]>>Octave;
#if SOUND_PRESCALE==1
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
#elif SOUND_PRESCALE==2
setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
#elif SOUND_PRESCALE==4
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
#elif SOUND_PRESCALE==8
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
#endif
enable_interrupts(int_ccp1);
enable_interrupts(global);
}
 
// Delka tonu merena casovacem T0 (bez preruseni)
Time=0;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
while (Duration)
{
if (T0IF) // Preteceni T0 - kazdych (1/CLK)*4*256
{
T0IF = 0;
Time += (256*4*1000*2048+SOUND_CLOCK/2)/SOUND_CLOCK;
}
if (Time>>11)
{
Time -= 2048;
Duration--;
}
#ifdef SOUND_WDT
restart_wdt(); // Nuluj watchdog abychom se nezresetovali
#endif
}
 
// Konec casovace
disable_interrupts(int_ccp1);
disable_interrupts(global);
}
/Designs/MB01B/SW/CCS/!____!.TXT
0,0 → 1,2
Tento DEVICES.DAT je vzaty z demoverze prekladace protoze obsahuje vice deifinic
procesoru.
/Designs/MB01B/SW/CCS/DEVICES.DAT
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property