pic18f4685 mp3 palyer help

General discussion on mikroC.
Post Reply
Author
Message
cocowest
Posts: 44
Joined: 18 Oct 2010 12:07

pic18f4685 mp3 palyer help

#1 Post by cocowest » 12 Dec 2010 22:15

i write this code for an mp3 player with a vs1011e and a pic18f4685 at 20 mhz clock (external)..
#include "built_in.h" //Libreria da icludere per le funzioni

//#define LED_GREEN PORTA.F2
//#define LED_RED PORTA.F3


#define RST PORTE.F0
#define CS PORTA.F2
#define DCS PORTA.F1
#define DREQ PORTA.F0
#define DCLK PORTA.F3
#define SDATA PORTA.F4
#define CLK 3 //pin di clock sul dec
#define SO 4 //pin si sul decoder

char txt[3], txt2[6], filename[12] = "PROVA00 MP3";
unsigned long i, size,k;
unsigned short loop, character, x, ctrl_vol=0;
unsigned int volume=0x6464, loop2;

//#include "Funzione.h"









void main() {

unsigned repeat=0;
OSCCON=0;
//OSCCON.RB1=0;
//OSCCON.RB7=1;
CMCON |= 0x07; // turn off comparators
ADCON1 |= 0x0F; // turn off analog inputs
//MEMCON.EBDIS = 1; // disable external memory bus


//sETTING PORTE

TRISA = 0x00;
TRISD=0;
//TRISC.RB0=0;
//TRISB.RB0=1;
TRISB.RB2=1;
TRISB.RB3=1;
TRISB.RB4=1;
TRISB.RB5=1;
TRISB.RB6=1;
trisc.rc3=0; //clock out hard
trisc.rc4=1; //data in hard
trisc.rc5=0; //data out hard
TRISC.RC6=0;
trise.re0=0;
TRISA.RA5=1;
TRISA.ra0=1; //dreq è in IN
//SETTING ITERRUPT
//UCFG=0x08;
INTCON=0;
// LED_GREEN = LED_RED = 1;

delay_ms(100); // Delay 100ms
Lcd_Config(&PORTD,4,5,6,3,2,1,0); // Configura LCD sui rispettivi pin
Lcd_Init(&PORTD);
Lcd_Cmd(LCD_CLEAR); // Clear display
Lcd_Cmd(LCD_CURSOR_OFF); // Turn cursor off
Lcd_Cmd(LCD_RETURN_HOME); // Cursor home
Lcd_Out(1, 1, "Ciao Grabeli");
Delay_ms(500);
Lcd_Cmd(LCD_CLEAR); // Clear display
//LED_GREEN = LED_RED = 0;
RST = 0;
CS = 0;
DCS = 0;

Spi_Init_Advanced(MASTER_OSC_DIV64, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH);

Soft_Spi_Config (&PORTA, 5, 4, 3);


delay_ms(200);

RST = 1;
delay_ms(100);
CS = 1;
DCS = 1;

Delay_ms(100);

while(DREQ == 0) {}
Lcd_Out(2, 1, "test beep");
// THIS IS BEEP TEST
for(i=0;i<1;i++)
{

CS = 0;
Soft_Spi_Write(0x02);
Soft_Spi_Write(0x00);
Soft_Spi_Write(0x08);
Soft_Spi_Write(0x20);
CS = 1;

DCS = 0;
Soft_Spi_Write(0x53);
Soft_Spi_Write(0xEF);
Soft_Spi_Write(0x6E);
Soft_Spi_Write(0x30);
Soft_Spi_Write(0x00);
Soft_Spi_Write(0x00);
Soft_Spi_Write(0x00);
Soft_Spi_Write(0x00);
DCS = 1;
Delay_ms(500);
//
DCS = 0;
Soft_Spi_Write(0x45);
Soft_Spi_Write(0x78);
Soft_Spi_Write(0x69);
Soft_Spi_Write(0x74);
Soft_Spi_Write(0x45);
Soft_Spi_Write(0x78);
Soft_Spi_Write(0x69);
Soft_Spi_Write(0x74);
DCS = 1;

Delay_ms(500);

}



RST = 1; //Hardware Reset logical level to 0-->1
CS = 1;
DCS = 1;
Delay_ms(100);

if (DREQ == 1){ //controllo che l'hardware reset è avvenuto bene
// LED_GREEN = 1;
Lcd_Cmd(LCD_CLEAR); // Clear display
// Cursor home
Lcd_Out(1, 1, "dreq=1");
Delay_ms(500);
CS = 0; //Enable Circuit Select for SCI
Soft_Spi_Write(0x02); //Command for write 0x(02)
Soft_Spi_Write(0x00); //ar register 0x00
Soft_Spi_Write(0x08); //Set mode register
Soft_Spi_Write(0x02); //is 16bit long
CS = 1; //disable Circuit Select for SCI
Delay_us(30); //attesa per l'esecuzione basta controllare lo stato di DREQ
CS = 0;
Soft_Spi_Write(0x02);
Soft_Spi_Write(0x03); //Set the register for the clock
Soft_Spi_Write(0x98); //I use a doubler PLL whit 12.288Mhz
Soft_Spi_Write(0x00);
CS = 1;
Delay_us(30);
// CS = 0;
// Soft_Spi_Write(0x02);
// Soft_Spi_Write(0x0B); //Set the volume at medium value
// Soft_Spi_Write(0x64);
// Soft_Spi_Write(0x64);
// CS = 1;
}

do{
//Controlla se la card è bloccata
if(!Mmc_Fat_Init(&PORTC,1)){ //Inizializza MMC/SD
Lcd_Out(1, 1, "Card OK");
Delay_ms(500);
Spi_Init_Advanced(MASTER_OSC_DIV16, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH);
Lcd_Cmd(LCD_CLEAR);
loop=5;
while (loop<50){ //Ciclo per leggere gli mp3 in sequenza
filename[5] = loop / 10 + 48; //Calcolo del nome del file
filename[6] = loop % 10 + 48;
// M_Open_File_Read(); //Chiamata a funzione
for (loop2=0; loop2<2048; loop2++){ //Invio di 2048 "0" per accertarsi la fine dell'mp3
DCS = 0;
Soft_Spi_Write(0x00);
DCS = 1;

}
while (DREQ==0){} //attesa su DREQ
CS = 0;
Lcd_Out(1, 1, "soft reset");
Delay_ms(1300);
Soft_Spi_Write(0x02); //Software reset
Soft_Spi_Write(0x00);
Soft_Spi_Write(0x08);
Soft_Spi_Write(0x06);
CS = 1;
Delay_us(100);
while (DREQ==0){}
CS = 0;
Lcd_Out(1, 1, "imposto clock");
Delay_ms(1300);
Soft_Spi_Write(0x02); //Imposto il clock
Soft_Spi_Write(0x03);
Soft_Spi_Write(0x98);
Soft_Spi_Write(0x00);
CS = 1;
loop++;
//M_Open_File_Read(); //Chiamata a funzione
Mmc_Fat_Assign(&filename, 0); //se il file viene trovato lo decodifica altrimenti

Lcd_Cmd(LCD_CLEAR); //passa al file successivo per un limite di 50
Lcd_Out(1, 1, filename);
Lcd_Out(2, 1, "Vol.");


Mmc_Fat_Reset(&size);

for(i=0;i<size;i++)
{

Mmc_Fat_Read(&character);
//for (k=0; k<=32;k++) {


DCS=0; //Enable Circuit select for SDI

while(DREQ == 0)
{
if (Button(&PORTB, 5, 1, 0)) //avanti
{
i=size;
}
}

asm{ //Codice in assembler perchè in C troppo lento

bcf PORTA,SO,0
btfsc _character,7,0
bsf PORTA,SO,0
bsf PORTA,CLK,0
bcf PORTA,CLK,0
bcf PORTA,SO,0
btfsc _character,6,0
bsf PORTA,SO,0
bsf PORTA,CLK,0
bcf PORTA,CLK,0
bcf PORTA,SO,0
btfsc _character,5,0
bsf PORTA,SO,0
bsf PORTA,CLK,0
bcf PORTA,CLK,0
bcf PORTA,SO,0
btfsc _character,4,0
bsf PORTA,SO,0
bsf PORTA,CLK,0
bcf PORTA,CLK,0
bcf PORTA,SO,0
btfsc _character,3,0
bsf PORTA,SO,0
bsf PORTA,CLK,0
bcf PORTA,CLK,0
bcf PORTA,SO,0
btfsc _character,2,0
bsf PORTA,SO,0
bsf PORTA,CLK,0
bcf PORTA,CLK,0
bcf PORTA,SO,0
btfsc _character,1,0
bsf PORTA,SO,0
bsf PORTA,CLK,0
bcf PORTA,CLK,0
bcf PORTA,SO,0
btfsc _character,0,0
bsf PORTA,SO,0
bsf PORTA,CLK,0
bcf PORTA,CLK,0
}


DCS=1; //Fine disable DCS


// }
// delay_ms(2);
}


}
}else{ //Inizializzazione fallita
Lcd_Out(1, 1, "CARD fallita");
Delay_ms(1000);
}

Lcd_Cmd(LCD_CLEAR);
Lcd_Out(1, 6, "FINE");
repeat=1;
Delay_ms(1000);


do{
Lcd_Out(1, 1, "Play to repeat");
if(Button(&PORTB, 5, 1, 0)){
repeat=0;
Lcd_Cmd(LCD_CLEAR);
}
if(Button(&PORTB, 4, 1, 0)){
Lcd_Cmd(LCD_CLEAR); // Clear display
Lcd_Out(1, 1, "See you");
Delay_ms(3000);
Lcd_Cmd(LCD_TURN_OFF);
while(1);
}
}
while(repeat==1);
}
while(1);

}//~!



but, when a sound file, it feels like the metallic voice of a robot, disturbed, but perfectly synchronized,
and after just 2-3 minutes after the streaming starting, the player not function...it's blocked...

I think the pic is slow, and I want to make it run at 40 MHz, using a 10MHz clock with hspll,what do you suggest?
you say it can be a power problem?
I use a 12v dc power supply to a router with a 7805 that tension in the pic and the display and a LM317 voltage that the sd and vs1011e..
please help me!!

thanks

Lord Lucan
Posts: 60
Joined: 09 Dec 2010 14:41

Re: pic18f4685 mp3 palyer help

#2 Post by Lord Lucan » 13 Dec 2010 14:27

Have you tried speeding up the SD card...

Spi_Init_Advanced(MASTER_OSC_DIV8, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH);

cocowest
Posts: 44
Joined: 18 Oct 2010 12:07

Re: pic18f4685 mp3 palyer help

#3 Post by cocowest » 18 Dec 2010 13:49

i tried this solution, but the problem is the same!! i try with 8 and 4...what can i do??

Post Reply

Return to “mikroC General”