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
pic18f4685 mp3 palyer help
General discussion on mikroC.
Author
Message
-
- 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);
Spi_Init_Advanced(MASTER_OSC_DIV8, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH);
Jump to
- NECTO Studio
- ↳ IDE
- ↳ IDE General
- ↳ IDE Beta Testing
- ↳ IDE Wish List
- ↳ ARM AI Compilers
- ↳ mikroC AI for ARM
- ↳ mikroC AI for ARM General
- ↳ mikroC AI for ARM Beta Testing
- ↳ mikroC AI for ARM Wish List
- ↳ PIC AI compilers
- ↳ mikroC AI for PIC
- ↳ mikroC AI for PIC General
- ↳ mikroC AI for PIC Beta Testing
- ↳ mikroC AI for PIC Wish List
- ↳ PIC32 AI Compilers
- ↳ mikroC AI for PIC32
- ↳ mikroC AI for PIC32 General
- ↳ mikroC AI for PIC32 Beta Testing
- ↳ mikroC AI for PIC32 Wish List
- ↳ dsPIC AI Compilers
- ↳ mikroC AI for dsPIC
- ↳ mikroC AI for dsPIC General
- ↳ mikroC AI for dsPIC Beta Testing
- ↳ mikroC AI for dsPIC Wish List
- ↳ AVR AI Compilers
- ↳ mikroC AI for AVR
- ↳ mikroC AI for AVR General
- ↳ mikroC AI for AVR Beta Testing
- ↳ mikroC AI for AVR Wish List
- ↳ Additional Software
- ↳ Visual TFT AI
- ↳ Visual TFT AI General
- ↳ Visual TFT AI Beta Testing
- ↳ Visual TFT AI Wish List
- PRO Compilers
- ↳ PIC PRO Compilers
- ↳ PIC Compilers General
- ↳ mikroC PRO for PIC
- ↳ mikroC PRO for PIC General
- ↳ mikroC PRO for PIC Beta Testing
- ↳ mikroC PRO for PIC Wish List
- ↳ mikroBasic PRO compiler for PIC
- ↳ mikroBasic PRO for PIC General
- ↳ mikroBasic PRO for PIC Beta Testing
- ↳ mikroBasic PRO for PIC Wish List
- ↳ mikroPascal PRO for PIC
- ↳ mikroPascal PRO for PIC General
- ↳ mikroPascal PRO for PIC Beta Testing
- ↳ mikroPascal PRO for PIC Wish List
- ↳ dsPIC PRO Compilers
- ↳ dsPIC Compilers General
- ↳ mikroC PRO for dsPIC30/33 and PIC24
- ↳ mikroC PRO for dsPIC30/33 and PIC24 General
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 General
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 General
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Wish List
- ↳ PIC32 PRO Compilers
- ↳ PIC32 Compilers General
- ↳ mikroC PRO for PIC32
- ↳ mikroC PRO for PIC32 General
- ↳ mikroC PRO for PIC32 Beta Testing
- ↳ mikroC PRO for PIC32 Wish List
- ↳ mikroBasic PRO for PIC32
- ↳ mikroBasic PRO for PIC32 General
- ↳ mikroBasic PRO for PIC32 Beta Testing
- ↳ mikroBasic PRO for PIC32 Wish List
- ↳ mikroPascal PRO for PIC32
- ↳ mikroPascal PRO for PIC32 General
- ↳ mikroPascal PRO for PIC32 Beta Testing
- ↳ mikroPascal PRO for PIC32 Wish List
- ↳ AVR PRO Compilers
- ↳ AVR Compilers General
- ↳ mikroC PRO for AVR
- ↳ mikroC PRO for AVR General
- ↳ mikroC PRO for AVR Beta Testing
- ↳ mikroC PRO for AVR Wish List
- ↳ mikroBasic PRO compiler for AVR
- ↳ mikroBasic PRO for AVR General
- ↳ mikroBasic PRO for AVR Beta Testing
- ↳ mikroBasic PRO for AVR Wish List
- ↳ mikroPascal PRO for AVR
- ↳ mikroPascal PRO for AVR General
- ↳ mikroPascal PRO for AVR Beta Testing
- ↳ mikroPascal PRO for AVR Wish List
- ↳ FT90x PRO Compilers
- ↳ FT90x Compilers General
- ↳ mikroC PRO for FT90x
- ↳ mikroC PRO for FT90x General
- ↳ mikroC PRO for FT90x Beta Testing
- ↳ mikroC PRO for FT90x Wish List
- ↳ mikroBasic PRO compiler for FT90x
- ↳ mikroBasic PRO for FT90x General
- ↳ mikroBasic PRO for FT90x Beta Testing
- ↳ mikroBasic PRO for FT90x Wish List
- ↳ mikroPascal PRO for FT90x
- ↳ mikroPascal PRO for FT90x General
- ↳ mikroPascal PRO for FT90x Beta Testing
- ↳ mikroPascal PRO for FT90x Wish List
- ↳ 8051 PRO Compilers
- ↳ 8051 Compilers General
- ↳ mikroC PRO for 8051
- ↳ mikroC PRO for 8051 General
- ↳ mikroC PRO for 8051 Beta Testing
- ↳ mikroC PRO for 8051 Wish List
- ↳ mikroBasic PRO compiler for 8051
- ↳ mikroBasic PRO for 8051 General
- ↳ mikroBasic PRO for 8051 Beta Testing
- ↳ mikroBasic PRO for 8051 Wish List
- ↳ mikroPascal PRO for 8051
- ↳ mikroPascal PRO for 8051 General
- ↳ mikroPascal PRO for 8051 Beta Testing
- ↳ mikroPascal PRO for 8051 Wish List
- ↳ ARM PRO Compilers
- ↳ ARM Compilers General
- ↳ mikroC PRO for ARM
- ↳ mikroC PRO for ARM General
- ↳ mikroC PRO for ARM Beta Testing
- ↳ mikroC PRO for ARM Wish List
- ↳ mikroBasic PRO for ARM
- ↳ mikroBasic PRO for ARM General
- ↳ mikroBasic PRO for ARM Beta Testing
- ↳ mikroBasic PRO for ARM Wish List
- ↳ mikroPascal PRO for ARM
- ↳ mikroPascal PRO for ARM General
- ↳ mikroPascal PRO for ARM Beta Testing
- ↳ mikroPascal PRO for ARM Wish List
- ↳ Older versions of Compilers
- ↳ Older versions of mikroC Compilers
- ↳ mikroC for PIC
- ↳ mikroC General
- ↳ mikroC Beta Testing
- ↳ mikroC Wish List
- ↳ mikroC for dsPIC30/33 and PIC24
- ↳ mikroC for dsPIC30/33 and PIC24 General
- ↳ mikroC for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC for dsPIC30/33 and PIC24 Wish List
- ↳ RSC-4x mikroC
- ↳ RSC-4x mikroC General
- ↳ RSC-4x mikroC Wish List
- ↳ mikroC Beta testing
- ↳ Older versions of mikroBasic Compilers
- ↳ mikroBasic compiler for PIC
- ↳ mikroBasic General
- ↳ mikroBasic Beta Testing
- ↳ mikroBasic Wish List
- ↳ mikroBasic compiler for dsPIC30/33 and PIC24
- ↳ mikroBasic for dsPIC30/33 and PIC24 General
- ↳ mikroBasic for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroBasic compiler for AVR
- ↳ mikroBasic for AVR General
- ↳ mikroBasic for AVR Wish List
- ↳ mikroBasic Beta testing
- ↳ Older versions of mikroPascal Compilers
- ↳ mikroPascal compiler for PIC
- ↳ mikroPascal FAQ
- ↳ mikroPascal General
- ↳ mikroPascal Beta Testing
- ↳ mikroPascal Wish List
- ↳ mikroPascal Bug List
- ↳ mikroPascal compiler for dsPIC30/33 and PIC24
- ↳ mikroPascal for dsPIC30/33 and PIC24 General
- ↳ mikroPascal for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroPascal compiler for AVR
- ↳ mikroPascal for AVR General
- ↳ mikroPascal for AVR Wish List
- ↳ mikroPascal Beta testing
- ↳ Library Development Discussion
- ↳ Code Requests
- Additional Software
- ↳ Visual TFT Software
- ↳ Visual TFT General
- ↳ Visual TFT Beta Testing
- ↳ Visual TFT Wish List
- ↳ Visual GLCD Software
- ↳ Visual GLCD General
- ↳ Visual GLCD Beta Testing
- ↳ Visual GLCD Wish List
- ↳ Package Manager Software
- ↳ Package Manager General
- ↳ Package Manager Beta Testing
- ↳ Package Manager Wishlist
- ↳ GLCD Font Creator Software
- ↳ SpeakUp Software
- ↳ Timer Calculator
- ↳ CAN Calculator
- ↳ mikroBootloader
- Hardware
- ↳ Development Boards
- ↳ CODEGRIP programmer and debugger
- ↳ Mikromedia
- ↳ mikroProg™ programmer and debugger
- ↳ Development Boards Wishlist
- ↳ Review
- ↳ Click Boards release
- ↳ Hexiwear
- Website & Forums
- ↳ Libstock Discussion
- ↳ Product Announcements
- ↳ Website & Forums General Discussion
- ↳ Website & Forums Wishlist
- ↳ User Projects