' ========================================================================= ' ' File....... AP8_Test.BS2 ' Purpose.... AP-8 Interface Example ' Author..... Team EFX -- Copyright (C) 2005 Parallax, Inc. ' E-mail..... teamefx@parallax.com ' Started.... ' Updated.... 14 OCT 2005 ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' ' Demonstration program for the AP-8 Audio Player Board. All commands are ' send to the AP-8 through a serial link at 38.4 kBaud (open-true mode). ' The use of the open baudmode allows boards to be daisy-chained for up to ' 32 sounds from one I/O pin. ' ' Command syntax: "!AP8", address, cmd {, data} ' -- where 'address' is %00 to %11 ' -- 'cmd' is a single character ' -- optional 'data' is a byte ' ' Valid commands: ' ' "!AP8", address, "V" ' -- requests version string from AP-8 ' -- should be followed by SERIN to receive three-byte string ' ' "!AP8", address, "G" ' -- retrieves current AP-8 status ' -- should be followed by SERIN to receive one-byte status ' -- status byte is bit-mapped: ' * BIT7 : 1 = playing, 0 = idle ' * BIT6 : reserved ' * BIT5 : 1 = single-shot play, 0 = loop play ' * BIT4 : 1 = Record mode, 0 = Play mode ' * BIT3 : reserved ' * BIT2 : Segment switch 2 ' * BIT1 : Segment switch 1 ' * BIT0 : Segment switch 0 ' ' "!AP8", address, "P", segment ' -- plays selected segment (0 - 7) ' -- returns status (same as "G" command) -- may be ignored ' ' "!AP8", address, "X" ' -- stops AP-8 (if playing) at selected address ' -----[ Revision History ]------------------------------------------------ ' -----[ I/O Definitions ]------------------------------------------------- Sio PIN 0 ' -----[ Constants ]------------------------------------------------------- #SELECT $STAMP #CASE BS2, BS2E, BS2PE T2400 CON 396 T38K4 CON 6 #CASE BS2SX, BS2P T2400 CON 1021 T38K4 CON 45 #CASE BS2PX T2400 CON 1646 T38K4 CON 84 #ENDSELECT SevenBit CON $2000 Inverted CON $4000 Open CON $8000 Baud CON Open + T38K4 Addr CON %11 ' -----[ Variables ]------------------------------------------------------- id VAR Byte(3) status VAR Byte segment VAR Nib switches VAR Nib ' -----[ EEPROM Data ]----------------------------------------------------- ' -----[ Initialization ]-------------------------------------------------- Reset: DEBUG CLS ' -----[ Program Code ]---------------------------------------------------- Main: SEROUT Sio, Baud, ["!AP8", Addr, "V"] ' get version SERIN Sio, Baud, [STR id\3] ' receive ID string DEBUG "AP-8 Version ", STR id\3 ' display it PAUSE 2000 DEBUG CLS FOR segment = 0 TO 7 SEROUT Sio, Baud, ["!AP8", Addr, "P", segment] SERIN Sio, Baud, [status] ' clear auto status byte GOSUB Show_Status PAUSE 1000 NEXT DEBUG CLS, "Demo complete." END ' -----[ Subroutines ]----------------------------------------------------- Show_Status: SEROUT Sio, Baud, ["!AP8", Addr, "G"] ' get status SERIN Sio, Baud, [status] IF (status.BIT4 = 1) THEN DEBUG CLS, "AP-8 is set to Record mode; please", CR, "move PLAY/REC jumper to PLAY." END ENDIF switches = status & %00000111 ' isolate switch bits IF (switches <> %111) THEN DEBUG CLS, "Please set AP-8 segment select", CR, "switches to OPEN, then restart", CR, "the program." END ENDIF DEBUG HOME, "Segment #", DEC segment, CR, CR DEBUG "Status....... " IF (status.BIT7 = 1) THEN DEBUG "Playing", CLREOL, CR ELSE DEBUG "Idle", CLREOL, CR ENDIF DEBUG "Play Mode.... " IF (status.BIT5 = 1) THEN DEBUG "Single-shot", CLREOL, CR ELSE DEBUG "Looped", CLREOL, CR ENDIF DEBUG "Play / Rec... " IF (status.BIT4 = 1) THEN DEBUG "Record", CLREOL, CR ELSE DEBUG "Play", CLREOL, CR ENDIF DEBUG "Switches..... ", BIN3 switches IF (status.BIT7 = 1) THEN Show_Status ' allow to finish RETURN