Pic 16f88 AD4 audio Player mikrobasic pro program.

Post your requests and ideas on the future development of mikroBasic PRO for PIC.
Author
Message
leo73
Posts: 252
Joined: 09 Jan 2014 15:45

Re: Pic 16f88 AD4 audio Player mikrobasic pro program.

#16 Post by leo73 » 10 Jun 2015 13:28

hi Fdapport
I don't understand why your code in my pic don't Work !!! it's necessary the Init Sub?
Could you give a look to my code and help me to understand where is the problems ????
thank you.

====================================================
program LettoreAD4WTV020


' ResetPin=ra1 OUTPUT
' ClockPin=ra2 OUTPUT
' DataPin=ra3 OUTPUT
' BusyPin=RA4 INPUT


' connections between WTV020 and MCU
dim WTV020_RS as sbit at RA1_bit
WTV020_CL as sbit at RA2_bit
WTV020_DA as sbit at RA3_bit
WTV020_BS as sbit at RA4_bit



WTV020_RS_Direction as sbit at TRISA1_bit
WTV020_CL_Direction as sbit at TRISA2_bit
WTV020_DA_Direction as sbit at TRISA3_bit
WTV020_BS_Direction as sbit at TRISA4_bit



const _PLAY_PAUSE as word = $FFFE
const _STOP as word = $FFFF
const _VOLUME_MIN as word = $FFF0
const _VOLUME_MAX as word = $FFF7

' WTV020 initializas sbit ation
sub procedure Wtv020_Init()
ADCON0=0 'ATTIVA IL CONVERTITORE ANALOGICO DIGITALE
ANSEL=0 ' CONFIGURA TUTTI I PIN ANALOGICI COME DIGITALI
CMCON=0x07 ' SPEGNE IL COMPARATORE
trisa=%00010001 ' Pone RA0 come Entrata,RA1..RA3 uscita,RA4 come Entrata
trisb=%00000011 ' Pone RB0,RB1 come Entrata RB3..RB7 come Uscita

'setting up direction
WTV020_CL_Direction=0 ' set line as output
WTV020_DA_Direction=0 ' set line as output
WTV020_RS_Direction=0 ' set line as output
WTV020_BS_Direction=1 ' set line as input
WTV020_CL=0
WTV020_RS=1
'reset pulse
WTV020_RS=0
delay_ms(100)
WTV020_RS=1
'reset idle to start bit
WTV020_CL=1
delay_ms(300)
end Sub

'send command to module
sub procedure Wtv020_SendCommand(dim addr as word)
dim bitnum as byte
dim addrW, addrX as word
WTV020_CL=0 ' Pin Clock BASSO
Delay_us(1950) ' Aspetto 1950 us (1.95ms)
For bitnum = 15 To 0 Step -1
WTV020_CL=0 ' Pone il pin clock a Livello Basso
Delay_us(50) ' Attesa 50us prima di inviare dati su dataPin
addrW = addr>>bitnum ' "Shifto" di Mask posizioni
addrX = (addrW and %0001) ' faccio un AND con la maschera %0001
If addrX >0 Then ' confronta bit per bit se c'e un 1 o uno 0 con in metodo dello schift e del AND
WTV020_DA=1 ' Spedisce in modo seriale livello DataPin Alto se uquale a 1
Else
WTV020_DA=0 ' Spedisce in modo seriale livello DataPin Basso se uquale a 0
End If
Delay_us(50) ' Attesa 50us prima di inviare dati su dataPin
WTV020_CL=1 ' metto alto il Clock
Delay_us(100) ' Attesa 100us
Next bitnum ' Ripeto
end sub

'play entire song and wait till song ends
sub procedure Wtv020_Play(dim voiceNumber as word)
while(WTV020_BS)=1
wend
delay_ms(10)
Wtv020_SendCommand(voiceNumber)
'wait 35ms for busy to be active
delay_ms(35)
'do nothing and wait while BUSY is high

end sub

'start playing song and return
sub procedure Wtv020_AsyncPlay(dim voiceNumber as word)
delay_ms(10)
Wtv020_SendCommand(voiceNumber)
delay_ms(35)
end sub

'stop playing song
sub procedure Wtv020_Stop()
Wtv020_SendCommand(_STOP)
end sub

'pause/resume song
sub procedure Wtv020_Pause()
Wtv020_SendCommand(_PLAY_PAUSE)
end sub

'mute sound
sub procedure Wtv020_Mute()
Wtv020_SendCommand(_VOLUME_MIN)
end sub

'set volume (from 0 to 7)
sub procedure Wtv020_Volume(dim volume as byte)
delay_ms(10)
if volume<8 then
Wtv020_SendCommand(_VOLUME_MIN+volume)
else
Wtv020_SendCommand(_VOLUME_MAX)
end if
delay_ms(35)
end sub

'==========MAIN PROGRAM==========
'=======for test purposes========
'================================
main:
dim i as word
Wtv020_Init
'setting volume to half
Wtv020_Volume(4)
for i=0 to 5
Wtv020_Play(i+ %0001)
next i

end.

===============================================

Post Reply

Return to “mikroBasic PRO for PIC Wish List”