Connect and program in microBasic to drive mp3 WTV020-SD-16P

General discussion on mikroElektronika website & forums.
Author
Message
leo73
Posts: 252
Joined: 09 Jan 2014 15:45

Re: Connect and program in microBasic to drive mp3 WTV020-SD

#16 Post by leo73 » 04 Feb 2015 16:39

This is ultimate Mikrobasic library, i tested it and it Work !!! thanks for your cooperation with Xmaspako.

=====================================================================
program WTV020TestXmaspako

' 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 commando as word)
dim mask as byte
'clock low level pulse
WTV020_CL=0
'initial delay
delay_ms(2)
for mask=15 to 0 step -1
'clock timing
delay_us(50)
'transfer command bit to das sbit ata pin
if ((commando>>mask) and %0001>0) then
WTV020_DA=1
else
WTV020_DA=0
end if
'clock timing
delay_us(50)
'clock high level pulse
WTV020_CL=1
'clock timing
delay_us(50)
if (mask>0) then WTV020_DA=0 'set data pin to low (till last bit)
else WTV020_DA=1 end if
delay_us(50) 'clock timing
if (mask>0) then WTV020_CL=0 'clock low level pulse (till last bit)
else WTV020_CL=1 end if
next mask
'busy active high from last das sbit ata bit las sbit atch
delay_ms(20)
end sub

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

'start playing song and return
sub procedure Wtv020_AsyncPlay(dim voiceNumber as word)
Wtv020_SendCommand(voiceNumber)
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)
if volume<8 then
Wtv020_SendCommand(_VOLUME_MIN+volume)
else
Wtv020_SendCommand(_VOLUME_MAX)
end if
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_AsyncPlay(i)
delay_ms(6000)
next i

'play second voice for 5 secs
'Wtv020_AsyncPlay(1)
'delay_ms(5000)
'pause play for 3 secs
'Wtv020_Pause()
'delay_ms(3000)
'setting volume to max
'Wtv020_Volume(7)
'resume play for 1 sec
'Wtv020_Pause()
'delay_ms(1000)
'Wtv020_Stop()
'play voice 0 till it ends
'Wtv020_Play(0)

end.
=========================================================================

Post Reply

Return to “Website & Forums General Discussion”