Home > Back-end >  How to make use of single-chip microcomputer serial port (RS485) play music module control to post)
How to make use of single-chip microcomputer serial port (RS485) play music module control to post)

Time:12-06

How to make use of single-chip microcomputer serial port (RS485) play music module control (turn to stick)
Beginners MCU, MCU is intertek TC - 1 c (STC89C52), I use the USB serial port, connecting music module (DMK01FS) of RS485 communication port, according to the MODBUS communication protocol, send 06 00 03 01 00, 01 can normally broadcast (specify the music playback),
01: is the machine address, is the address of the music module
06: function code, said written instructions
00 0 x03 (3) : specifies the register to play songs, to write songs here code can
0001:1 # tracks (the same 2 #, 3 #... )
As is shown in



Well then, I use the TX - 1 c RS232 serial port, music via RS232 to RS485 mouth connection module, as shown:


To download a program in the single chip microcomputer, content is when S2 press, send a string of characters to the serial port (01 06 00 00 03 01) or (06 00 00 03 01 B8 0 01 a) B0 0 a is to simulate the MODBUS debugging assistant send 01 06 00 00 03 01 instruction, check their added,
Electricity, press S2, displayed on the serial debugging assistants as shown in figure:


Above receiving area command shows that received and MODBUS debugging assistant string, music module have no reaction, thank directly!!!!!!!!!!

C program to provide (intertek) :
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
"Intertek electronic" courtesy of
www.txmcu.com
www.txmcu.cn
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Function: to a serial port to send a byte of data (can be displayed through the super terminal or serial debugging assistant,
Super terminal baud rate selected as 9600),
Super terminal Settings, each press next S2, loosen after all can the super terminal
Displayed on a string of letters "abcdefg ha ha,"
Entrance parameters: d: bytes of data to be sent,
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

# include & lt; Reg52. H>
# define jingzhen 11059200 ul/* 22.1184 M */crystal
# define botelv 9600 baud rate is defined as 9600 */ul/*
Unsigned char zifuchuan []="01 06 00 00 03 01 B8 0 a";//to display character,
Volatile unsigned char sending;
Sbit s2=P3 ^ 4;

Void delay (unsigned char I)
{
Unsigned char j, k;
For (j=I; J> 0; J -)
For (k=90; K> 0; K -);
}
Void init (void)//serial port initialization
{
EA=0;//closed temporarily interrupt
TMOD&=0 x0f;//timer 1 mode control in high four
TMOD |=0 x20;//timer 1 work in mode 2, automatic reloading pattern
SCON=0x50;//serial port work in pattern 1
TH1=256 - jingzhen/(botelv * 12 * 16);//calculate timer reshipment value
TL1=256 - jingzhen/(botelv * 12 * 16);
PCON |=0 x80;//serial port baud rate double
ES=1;//serial interruption allows
TR1=1;//start the timer 1
REN=1;//allow receiving
EA=1;//allow the interrupt
}

Void the send (unsigned char d)//send a byte of data, the parameter d is the sent data,
{

SBUF=d;//the data written to the serial buffer
Sending=1;//set to send sign
While (sending);//wait for send out
}

Void sendc (unsigned char * pd)
{
While (pd) (*!='\ 0')//send a string, did not end until meet 0
{
Send (* pd);//send a character
Pd++;//move to the next character
}
}

Void main ()
{
init();
While (1)
{
If (s2==0)
{
Delay (20);
if(! S2)
{
while(! S2);
Sendc (zifuchuan);
}
}
}
}

Void uart interrupt (void) 4//serial port to send interrupt
{
If (RI)//received data
{
RI=0;//clear the interrupt request
}
The else//send a byte of data
{
TI=0;
Sending=0;//clear sign is sending
}
}

CodePudding user response:

You get USB485 and, taking the computer data see SCM data right, a lot of automatic switching to send and receive 232 turn 485 doesn't works

CodePudding user response:

Thanks brother upstairs, feel your approach is correct, it immediately, in order to more accurate, this time I can't answer the music module, MCU learning board - RS232 serial port receive "online 232 turn 485" with a twisted pair to "turn RS485 USB" return to the computer USB,
MCU power, open the serial debugging assistants, press the microcontroller on S2 (trigger), serial debugging assistants receive buffer has "01 06 00 00 03 01 B8 0 a" data, single-chip microcomputer correct issued instructions, where problems are likely to? Thank you again for the reply upstairs!!!!!

CodePudding user response:

Thank you upstairs to reply, I ask again, my method (ideas) are correct, that is to say, I as long as the microcontroller via RS485 interface, send music module "01 06 00 00 03 01" string, music module should play?

CodePudding user response:

Unsigned char zifuchuan []={0 x01, 0 x06, 0 x00 to 0 x03, 0 x00 to 0 x01, 0 xb8, 0 x0a};//to display character,

Just see, you are strings, you need to send this 8 bytes of data directly,