El DFPlayer, Hace algunos años atrás para poder reproducir un sonido o audio mp3 era necesario realizar un gran circuito complejo, eso no era práctico ya que implicaba tardar horas diseñando, ensamblando, etc. Tambien estan los circuitos integrados capaces de reproducir sonidos por no más de 30 segundos, previamente grabados y obviamente era siempre el mismo. Hoy en en día tenemos este grandioso módulo DFPlayer que nos ayuda a proporcionar a nuestros proyectos electrónicos la capacidad de reproducir audios MP3 de forma practica y fácil.
El módulo DFPlayer tan solo necesita pocos componentes externos para poder reproducir un audio, como son: botones, parlante y una batería. Tambien, es capaz de soportar una memoria micro SD de hasta 32gb. Además puede controlarse con cualquier microcontrolador que soporte comunicación UART, esto le permite controlar de manera digital características como: play, pause, stop, next, prev, volumen, etc.
CARACTERÍSTICAS DEL MÓDULO DFPLAYER
- Soporta frecuencias de muestreo (kHz): 8/11.025/12/16/22.05/24/32/44.1/48.
- 24 -bit DAC output, soporta un rango dinámico de 90dB.
- Sistemas de archivos FAT16 , FAT32 y tarjetas de hasta 32G.
- Se puede controlar por comandos seriales UART, señales TTL digitales.
- Organización de archivos por carpeta. Soporta hasta 100 directorios y 255 pistas por directorio.
- 30 niveles de volumen y 6 -niveles de ecualización EQ.
APLICACIONES
- Reproducción de audio en sistemas de navegación.
- Reproducción de sonidos pre grabados en sistemas automáticos como máquinas vendedoras, estación de buses.
- Sistemas de guía vehicular, retroceso, etc.
- Mensajes de bienvenida, atención al cliente.
- Sonidos para fallos de sistemas
- Alarmas de fuego y sistemas varios.
DESCRIPCIÓN DEL PINOUT
LISTA DE COMANDOS
CIRCUITO DE CONEXIÓN DFPLAYER CON PIC16F1829
EJEMPLO PIC16F1829 CON DFPLAYER MP3
En el siguiente ejemplo se muestra como controlar el módulo, que, básicamente funcionará como un reproductor mp3 y con las funciones: play, pause, next y prev. Todo ello a través del controlador PIC16F1829.
Código principal MAIN.
#define _XTAL_FREQ 32000000
#include
#include "fuses.h"
#include "uart.h"
#include "dfplayer.h"
char state_play_pause = 0;
void main(void) {
OSCCON = 0b11110010; // PLLEN=1(x4), IRCF=8Mhz, SCS=OSC_INTERNAL
ANSELA = 0;
uart_Config(9600);
__delay_ms(10);
dfplayer_Config(15);
TRISAbits.TRISA0 = 1;
TRISAbits.TRISA1 = 1;
TRISAbits.TRISA1 = 1;
while (1) {
if (!PORTAbits.RA0) {
__delay_ms(250);
dfplayer_Next();
} else if (!PORTAbits.RA1) {
__delay_ms(250);
if (state_play_pause == 0) {
dfplayer_Play();
state_play_pause = 1;
} else {
dfplayer_Pause();
state_play_pause = 0;
}
} else if (!PORTAbits.RA2) {
__delay_ms(250);
dfplayer_Prev();
}
}
return;
}
Librería DFPlayer.
#ifndef DFPLAYER_H
#define DFPLAYER_H
void dfplayer_Config(unsigned char);
void write_Comand(unsigned char*);
void dfplayer_Play(void);
void dfplayer_Pause(void);
void dfplayer_Next(void);
void dfplayer_Prev(void);
void dfplayer_Index(unsigned int);
void dfplayer_Stop(void);
void dfplayer_Volume(unsigned char);
unsigned char comandoDFplayer[10] = {0x7E, 0xFF, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF};
void dfplayer_Config(unsigned char vol) {
__delay_ms(250);
dfplayer_Volume(vol);
dfplayer_Index(1);
}
void dfplayer_Play(void) {
comandoDFplayer[3] = 0x0D;
write_Comand(comandoDFplayer);
}
void dfplayer_Pause(void) {
comandoDFplayer[3] = 0x0E;
write_Comand(comandoDFplayer);
}
void dfplayer_Stop(void) {
comandoDFplayer[3] = 0x16;
write_Comand(comandoDFplayer);
}
void dfplayer_Index(unsigned int index) {
comandoDFplayer[3] = 0x12;
comandoDFplayer[5] = (char) (index >> 8);
comandoDFplayer[6] = (char) index;
write_Comand(comandoDFplayer);
}
void dfplayer_Next(void) {
comandoDFplayer[3] = 0x01;
write_Comand(comandoDFplayer);
}
void dfplayer_Prev(void) {
comandoDFplayer[3] = 0x02;
write_Comand(comandoDFplayer);
}
void dfplayer_Volume(unsigned char volumen) {
comandoDFplayer[3] = 0x06;
comandoDFplayer[5] = 0x00;
comandoDFplayer[6] = (char) volumen;
write_Comand(comandoDFplayer);
}
void write_Comand(unsigned char *cmd) {
volatile static unsigned int checksum = 0;
volatile static unsigned char i = 0;
checksum = 0;
for (i = 1; i < 7; i++) {
checksum += cmd[i];
}
checksum = 0x1000 - checksum;
cmd[7] = (char) (checksum >> 8);
cmd[8] = (char) checksum;
for (i = 0; i < 10; i++) { //envia cmd
uart_Write(cmd[i]);
}
}
#endif /* DFPLAYER_H */
Librería UART.
#ifndef UART_H
#define UART_H
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 32000000
#endif
void uart_Config(unsigned long);
void uart_Write(unsigned char);
void uart_writeString(unsigned char*);
char uart_Read(void);
void uart_ReadString(unsigned char*, unsigned char);
void uart_Config(unsigned long baud) {
APFCON0bits.TXCKSEL = 1;
APFCON0bits.RXDTSEL = 1;
if (baud > 38400) {
TXSTAbits.BRGH = 1;
BAUDCONbits.BRG16 = 0;
SPBRG = (_XTAL_FREQ / (16 * baud)) - 1;
} else {
TXSTAbits.BRGH = 0;
BAUDCONbits.BRG16 = 0;
SPBRG = (_XTAL_FREQ / (64 * baud)) - 1;
}
TRISCbits.TRISC4 = 1;
TXSTAbits.TXEN = 1;
RCSTAbits.SPEN = 1;
RCSTAbits.CREN = 1;
TXSTAbits.SYNC = 0;
}
void uart_Write(unsigned char data) {
while (!TXSTAbits.TRMT);
TXREG = data;
}
void uart_WriteString(unsigned char *data) {
for (int i = 0; data[i] != '\0'; i++)
uart_Write(data[i]);
}
char uart_Read(void) {
while (!PIR1bits.RCIF);
unsigned char data = RCREG;
return data;
}
void uart_ReadString(unsigned char *data, unsigned char len) {
for (int i = 0; i < len; i++)
data[i] = uart_Read();
}
#endif /* UART_H */
Librería FUSES.
#ifndef FUSES_H
#define FUSES_H
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = ON // Flash Program Memory Code Protection (Program memory code protection is enabled)
#pragma config CPD = ON // Data Memory Code Protection (Data memory code protection is enabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON // Internal/External Switchover (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = ON // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled)
#endif /* FUSES_H */
Deja una respuesta
Lo siento, debes estar conectado para publicar un comentario.