DFPlayer Mini MP3 Module Controlling Using AVR UART Codevision Sample: http://blog.allii.ir/2016/01/dfplayer-mini-mp3-module-control-avr-uart/
/************************************************************************************ | |
Run DFPlayer Mini Module With Atmega8 | |
DFPlayer Mini: http://blog.allii.ir/go/dfplayer-mini-main-wiki/ | |
For: http://blog.allii.ir/2016/01/dfplayer-mini-mp3-module-control-avr-uart/ | |
By: Alireza Dabiri Nejad | http://blog.allii.ir | |
Program: : Codevision | |
Chip type : ATmega8 | |
AVR Core Clock frequency: 8/001000 MHz | |
*************************************************************************************/ | |
/* MCU Define */ | |
#include <mega8.h> | |
/* Include I/o Functions */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
int default_buffer[10] = {0x7E , 0xFF , 0x06 , 0x00 , 0x00 , 0x00 , 0x00 , 0xEF}; // Default Buffer | |
int buffer_data[10] = {0x7E , 0xFF , 0x06 , 0x00 , 0x00 , 0x00 , 0x00 , 0xEF}; // Sending Buffer | |
// Send Buffer to UART TX Pin | |
void send_buffer(void) { | |
int i; | |
for( i=0; i< 10; i++){ | |
putchar(buffer_data[i]); | |
buffer_data[i] = default_buffer[i]; | |
} | |
} | |
// Set Volume And Send it's Serial Command | |
void set_volume( int volume ) { | |
buffer_data[3] = 0x06; | |
buffer_data[6] = volume; | |
send_buffer(); | |
} | |
// Set a Track (1-3000) to Play | |
void play_track(int track_id) { | |
buffer_data[3] = 0x03; | |
if(track_id < 256) { | |
buffer_data[6] = track_id; | |
} else { | |
buffer_data[5] = track_id / 256; | |
buffer_data[6] = track_id - 256 * buffer_data[6]; | |
} | |
send_buffer(); | |
} | |
// Set a Folder (1-255) and Track (1-255) to Play | |
void play_track(int folder_id, int track_id) { | |
buffer_data[3] = 0x0F; | |
buffer_data[5] = folder_id; | |
buffer_data[6] = track_id; | |
send_buffer(); | |
} | |
// Set a Track to Play Continuous | |
void play_current_track_continuous(void) { | |
buffer_data[3] = 0x08; | |
buffer_data[6] = current_track_number; | |
send_buffer(); | |
} | |
// Pause Current Playing Track | |
void pause_current_track() { | |
buffer_data[3] = 0x0E; | |
send_buffer(); | |
} | |
void main(void) | |
{ | |
// USART initialization | |
// Communication Parameters: 8 Data, 1 Stop, No Parity | |
// USART Receiver: Off | |
// USART Transmitter: On | |
// USART Mode: Asynchronous | |
// USART Baud Rate: 9600 | |
UCSRA=0x00; | |
UCSRB=0x08; | |
UCSRC=0x86; | |
UBRRH=0x00; | |
UBRRL=0x33; | |
while(1) { | |
} | |
} |
$S Ver. Number Command Feedback Param_MSB Param_LSB Check_MSB Check_LSB $O // UART Send Command Format | |
7E FF 06 09 00 00 02 FF F0 EF // Set microSD Command With Checksum | |
Checksum = ~(Ver.+Number+Command+Feedback+Param_MSB+Param_LSB) + 1 // Checksum Calculation Formula |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment