找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1953|回复: 1
收起左侧

YS-M3A3串口语音播放模块 单片机源程序

[复制链接]
ID:305173 发表于 2020-4-29 11:52 | 显示全部楼层 |阅读模式
里面为YS-M3A3的串口语音串口模块的资源包含程序和接线图 51hei.png 51hei.png

单片机源程序如下:
  1. #include "reg51.h"
  2. #include "intrins.h"

  3. typedef unsigned char BYTE;
  4. typedef unsigned int WORD;

  5. #define FOSC 11059200L      //System frequency
  6. #define BAUD 9600           //UART baudrate

  7. bit busy;

  8. void SendData(BYTE dat);
  9. void SendString(char *s);

  10. unsigned int MP3data1[5]={0xfd,0x02,0x01,0xdf}  //播放
  11. unsigned int MP3data2[5]={0xfd,0x02,0x02,0xdf}  //暂停
  12. unsigned int MP3data3[6]={0xfd,0x04,0x41,0x00,0x01,0xdf}  //播放第一首歌

  13. sbit key1=P1^0; //定义按键1
  14. sbit key2=P1^0; //定义按键2


  15. void Delay20ms()                //@11.0592MHz
  16. {
  17.         unsigned char i, j;

  18.         i = 36;
  19.         j = 217;
  20.         do
  21.         {
  22.                 while (--j);
  23.         } while (--i);
  24. }


  25. void main()
  26. {
  27. unsigned int i;       

  28.     SCON = 0x50;            //8-bit variable UART
  29.     TMOD = 0x20;            //Set Timer1 as 8-bit auto reload mode
  30.     TH1 = TL1 = -(FOSC/12/32/BAUD); //Set auto-reload vaule
  31.     TR1 = 1;                //Timer1 start run
  32.     ES = 1;                 //Enable UART interrupt
  33.     EA = 1;                 //Open master interrupt switch

  34.     while(1)
  35.         {
  36.                 if(key1==0)
  37.                  {
  38.                         Delay20ms();
  39.                         if(key1==0)
  40.                         {
  41.                                 while(key1==0);
  42.                                 for(i=0;i<5;i++)
  43.                                 {
  44.                                   SendData(MP3data3[i]);//按下按键1 播放第一首歌曲               
  45.                                 }
  46.                         }       
  47.                   }       
  48.        
  49.          };
  50. }

  51. /*----------------------------
  52. UART interrupt service routine
  53. ----------------------------*/
  54. void Uart_Isr() interrupt 4 using 1
  55. {
  56.     if (RI)
  57.     {
  58.         RI = 0;             //Clear receive interrupt flag
  59.     }
  60.     if (TI)
  61.     {
  62.         TI = 0;             //Clear transmit interrupt flag
  63.         busy = 0;           //Clear transmit busy flag
  64.     }
  65. }

  66. /*----------------------------
  67. Send a byte data to UART
  68. Input: dat (data to be sent)
  69. Output:None
  70. ----------------------------*/
  71. void SendData(BYTE dat)
  72. {
  73.     while (busy);           //Wait for the completion of the previous data is sent
  74.     ACC = dat;              //Calculate the even parity bit P (PSW.0)
  75.     busy = 1;
  76.     SBUF = ACC;             //Send data to UART buffer
  77. }

  78. /*----------------------------
  79. Send a string to UART
  80. Input: s (address of string)
  81. Output:None
  82. ----------------------------*/
  83. void SendString(char *s)
  84. {
  85.     while (*s)              //Check the end of the string
  86.     {
  87.         SendData(*s++);     //Send current char and increment string ptr
  88.     }
  89. }
复制代码

所有资料51hei提供下载:
YS-M3A3串口语音播放模块--配套资料(20151011).zip (1.36 MB, 下载次数: 20)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:763304 发表于 2020-5-28 13:24 来自手机 | 显示全部楼层
你好,请问这个里面有YM-S3模块的内部电路图吗?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表