Agent36
- 27th September 2006, 21:46
Hi,
I have down loaded and modified the following code from MELABS samples so I can understand the coding.
I have changed the code so that I have three push buttons record, finish and play. The binary switch on porta selects the address to start playing the message . The problem is I can only play from address zero, if some one would be kind enough to check the code and point me in the right direction it would be a great help. I have spent four weeks on this with out progression.
Here is the code in full.
' Program to record and play multiple voice messages.
' Uses hardware SPI for 2-way communication to the voice device.
' Record messages in sequence by pressing the REC button.
' Then pressing the FINISH button to stop recording. The messages
' may be played back by selecting the address on the deciaml to binary
' switch and pressing the PLAY button.
@ DEVICE PIC16F819, INTRC_OSC_NOCLKOUT
' System Clock Options (Internal)
@ DEVICE PIC16F819, WDT_ON
' Watchdog Timer
@ DEVICE PIC16F819, PWRT_ON
' Power-On Timer
@ DEVICE PIC16F819, MCLR_OFF
' Master Clear Options (Internal)
@ DEVICE PIC16F819, BOD_OFF
' Brown-Out Detect
@ DEVICE PIC16F819, CPD_OFF
' Data Memory Code Protect
@ DEVICE PIC16F819, PROTECT_OFF
DEFINE OSC 8 ' Define for 8MHz crystal internal
OSCCON = $70 'set the clock to 8 Mhz, 60 for 4MHz
select_voice VAR PORTB.3 ' Chip select for voice recorder
serial_mcu_out VAR PORTB.2 ' SPI data output
serial_clk VAR PORTB.4 ' SPI clock pin
voice_int VAR PORTB.5 ' Interrupt signal from voice device
ADCON1 = 7 ' Set PORTA and PORTB to digital
' Define program variables
control VAR BYTE
address VAR WORD
isd_data_in VAR WORD
isd_data_out VAR WORD
message_loc VAR WORD[16]
i VAR BYTE
i = 0
message_loc[0]=0
' set up SPI port
BF VAR SSPSTAT.0 ' Alias Buffer Full flag
SSPSTAT = %01000000 ' Set SMP=0, CKE=1
SSPCON = %00100010 ' Set CKP=0, SPI master, clock = Fosc/64, Enable the port
TRISB = %11100011 ' Set data-direction to allow SPI on PortB
High select_voice
'portb.0 is Play
'portb.1 is MCU IN (SDI)
'portb.2 is MCU OUT (SDO)
'portb.3 is Select voice
'portb.4 is Serial clock (SCK)
'portb.5 is Voice int (SS)
'portb.6 is Record start
'portb.7 is Record Finish
TRISA = %00001111 'Bits 0-3 address select
Pause 1000 ' allows power to settle
loop:
IF PORTB.6 = 0 Then
address = message_loc[i] 'Sets address to begin recording
GoSub record
EndIF
IF PORTB.7 = 0 Then
GoSub finish
i = (i+1) & $0F
message_loc[i] = (isd_data_in >> 2) + 2 ' remove status bit
EndIF
IF PORTB.0 = 0 Then
Pause 500 'allow key to release
i = PORTA ' number selected plays corresponding message
i = i+$0F
address = message_loc[i] 'sets playback address
GoSub ply
EndIF
wait_for_int:
IF voice_int = 1 Then
GoTo wait_for_int 'loop here till finished
GoSub finish 'power down chip
EndIF
GoTo loop ' Do it forever
' ISD4003 Control Values:
power_up CON %00100000 ' Power up the device
set_play CON %11100000 ' Set the playback address
play CON %11110000 ' Start playback
set_rec CON %10100000 ' Set the record address
rec CON %10110000 ' Start recording
power_dwn CON %00010000 ' Stop playback or record and power down the device
record: 'Record a message
control = power_up ' Set control byte to power up
GoSub spi_send ' Send to device
Pause 100 ' Pause to let the device come up
control = set_rec ' Set control byte to set record address
GoSub spi_send ' Send to device
Return ' Return to main loop
ply:
control = power_up ' Set control byte to power up
GoSub spi_send ' Send to device
Pause 50 ' Pause to let the device come up
control = set_play ' Set control byte to set play address
GoSub spi_send ' Send to device
Return
finish:
control = power_dwn ' Set control byte to power down
GoSub spi_send ' Send to device
Return ' Return to main loop
spi_send: ' Use hardware SPI port to send and receive simultaneously
Low select_voice ' Select voice chip
address.highbyte = (address.highbyte & %00000111) | control ' Combine address and control data
isd_data_out = address REV 16 ' Reverse the bits for LSB first
SSPBUF = isd_data_out.highbyte ' Write the first byte to SSPBUF to initiate trasfer
GoSub spi_wait ' Wait for transfer to finish
isd_data_in.highbyte = SSPBUF ' Read the incoming data from SSPBUF
SSPBUF = isd_data_out.lowbyte ' Write the second byte to SSPBUF to initiate transfer
GoSub spi_wait ' Wait for transfer to finish
isd_data_in.lowbyte = SSPBUF ' Read the incoming data from SSPBUF
isd_data_in = isd_data_in REV 16 ' Reverse the bits of incoming data (received LSB first)
High select_voice ' Deselect voice chip
Return
spi_wait: ' Wait for transfer to finish
IF BF = 0 Then spi_wait ' If the flag is still zero, keep waiting
BF = 0 ' Reset the flag
Return
End
Thanks for your help and time
Kind regards
Nick
I have down loaded and modified the following code from MELABS samples so I can understand the coding.
I have changed the code so that I have three push buttons record, finish and play. The binary switch on porta selects the address to start playing the message . The problem is I can only play from address zero, if some one would be kind enough to check the code and point me in the right direction it would be a great help. I have spent four weeks on this with out progression.
Here is the code in full.
' Program to record and play multiple voice messages.
' Uses hardware SPI for 2-way communication to the voice device.
' Record messages in sequence by pressing the REC button.
' Then pressing the FINISH button to stop recording. The messages
' may be played back by selecting the address on the deciaml to binary
' switch and pressing the PLAY button.
@ DEVICE PIC16F819, INTRC_OSC_NOCLKOUT
' System Clock Options (Internal)
@ DEVICE PIC16F819, WDT_ON
' Watchdog Timer
@ DEVICE PIC16F819, PWRT_ON
' Power-On Timer
@ DEVICE PIC16F819, MCLR_OFF
' Master Clear Options (Internal)
@ DEVICE PIC16F819, BOD_OFF
' Brown-Out Detect
@ DEVICE PIC16F819, CPD_OFF
' Data Memory Code Protect
@ DEVICE PIC16F819, PROTECT_OFF
DEFINE OSC 8 ' Define for 8MHz crystal internal
OSCCON = $70 'set the clock to 8 Mhz, 60 for 4MHz
select_voice VAR PORTB.3 ' Chip select for voice recorder
serial_mcu_out VAR PORTB.2 ' SPI data output
serial_clk VAR PORTB.4 ' SPI clock pin
voice_int VAR PORTB.5 ' Interrupt signal from voice device
ADCON1 = 7 ' Set PORTA and PORTB to digital
' Define program variables
control VAR BYTE
address VAR WORD
isd_data_in VAR WORD
isd_data_out VAR WORD
message_loc VAR WORD[16]
i VAR BYTE
i = 0
message_loc[0]=0
' set up SPI port
BF VAR SSPSTAT.0 ' Alias Buffer Full flag
SSPSTAT = %01000000 ' Set SMP=0, CKE=1
SSPCON = %00100010 ' Set CKP=0, SPI master, clock = Fosc/64, Enable the port
TRISB = %11100011 ' Set data-direction to allow SPI on PortB
High select_voice
'portb.0 is Play
'portb.1 is MCU IN (SDI)
'portb.2 is MCU OUT (SDO)
'portb.3 is Select voice
'portb.4 is Serial clock (SCK)
'portb.5 is Voice int (SS)
'portb.6 is Record start
'portb.7 is Record Finish
TRISA = %00001111 'Bits 0-3 address select
Pause 1000 ' allows power to settle
loop:
IF PORTB.6 = 0 Then
address = message_loc[i] 'Sets address to begin recording
GoSub record
EndIF
IF PORTB.7 = 0 Then
GoSub finish
i = (i+1) & $0F
message_loc[i] = (isd_data_in >> 2) + 2 ' remove status bit
EndIF
IF PORTB.0 = 0 Then
Pause 500 'allow key to release
i = PORTA ' number selected plays corresponding message
i = i+$0F
address = message_loc[i] 'sets playback address
GoSub ply
EndIF
wait_for_int:
IF voice_int = 1 Then
GoTo wait_for_int 'loop here till finished
GoSub finish 'power down chip
EndIF
GoTo loop ' Do it forever
' ISD4003 Control Values:
power_up CON %00100000 ' Power up the device
set_play CON %11100000 ' Set the playback address
play CON %11110000 ' Start playback
set_rec CON %10100000 ' Set the record address
rec CON %10110000 ' Start recording
power_dwn CON %00010000 ' Stop playback or record and power down the device
record: 'Record a message
control = power_up ' Set control byte to power up
GoSub spi_send ' Send to device
Pause 100 ' Pause to let the device come up
control = set_rec ' Set control byte to set record address
GoSub spi_send ' Send to device
Return ' Return to main loop
ply:
control = power_up ' Set control byte to power up
GoSub spi_send ' Send to device
Pause 50 ' Pause to let the device come up
control = set_play ' Set control byte to set play address
GoSub spi_send ' Send to device
Return
finish:
control = power_dwn ' Set control byte to power down
GoSub spi_send ' Send to device
Return ' Return to main loop
spi_send: ' Use hardware SPI port to send and receive simultaneously
Low select_voice ' Select voice chip
address.highbyte = (address.highbyte & %00000111) | control ' Combine address and control data
isd_data_out = address REV 16 ' Reverse the bits for LSB first
SSPBUF = isd_data_out.highbyte ' Write the first byte to SSPBUF to initiate trasfer
GoSub spi_wait ' Wait for transfer to finish
isd_data_in.highbyte = SSPBUF ' Read the incoming data from SSPBUF
SSPBUF = isd_data_out.lowbyte ' Write the second byte to SSPBUF to initiate transfer
GoSub spi_wait ' Wait for transfer to finish
isd_data_in.lowbyte = SSPBUF ' Read the incoming data from SSPBUF
isd_data_in = isd_data_in REV 16 ' Reverse the bits of incoming data (received LSB first)
High select_voice ' Deselect voice chip
Return
spi_wait: ' Wait for transfer to finish
IF BF = 0 Then spi_wait ' If the flag is still zero, keep waiting
BF = 0 ' Reset the flag
Return
End
Thanks for your help and time
Kind regards
Nick