找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 7672|回复: 4
收起左侧

单片机MP3(PCB+原理图+代码)

  [复制链接]
ID:278081 发表于 2018-1-20 17:22 | 显示全部楼层 |阅读模式
练手项目,完整资料
Altium Designer画的原理图和PCB图如下:(51hei附件中可下载工程文件)
0.jpg 0.jpg
单片机源程序如下:
  1. #include <string.h>
  2. #include <STC12C5A.H>
  3. #include "VS1003.h"
  4. #include "debug.h"
  5. #include "SPI.h"
  6. #include "SD.h"
  7. #include "myfun.h"
  8. #include "PFatFS/pff.h"
  9. #include "12864.h"
  10. #include "menu_UI.c"

  11. FATFS fatfs;   ///定义一个文件系统对象
  12. FRESULT res;

  13. UINT8 Music_Vol=200;        //音量大小
  14. UINT16 code bitrate[2][16]={{0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,0},{0,32,40,48,56,64,80,96,112,128,160,192,224,256,320,0}}; //用于MP3比特率的判断
  15. UINT8 Time[6]={0,1,':',2,0,'\0'};
  16. UINT8 DispBitRate[]={0,0,0,'k','b','p','\/','s','\0'};
  17. UINT8 TxtBuffer[49]={0};
  18. UINT8 MusicVol[]={'0','0','0','\0'};//音量整形转为字符串类型
  19. UINT8 Doc_pos=0;                //文档菜单索引
  20. UINT8 old_Doc_pos=-1;        //按键之前文档菜单索引
  21. UINT8 mpos=0;                         //主菜单播索引值
  22. UINT8 oldmpos = 2;                //按键之前主菜单索引值
  23. UINT8 key=0;                        //当前按键值
  24. UINT8 MusicMax=0;                //读取音乐文件的个数
  25. UINT8 TxtMax=0;                        //读取文档文件的个数
  26. UINT8 flag_music=0;               
  27. LONG pMusic=0;
  28. WORD br,rc;
  29. FILINFO filinfo;//文件信息
  30. DIR dir;  

  31. //初始化所有设备
  32. void all_init()
  33. {
  34.         {P1M1 = 0X40; P1M0 = 0xbF;}   //硬件SPI必须!!!!!!!!!!!I/O口1模式控制器1
  35. //        P0M1 = 0Xff; P0M0 = 0xff;          //有上拉电阻的话就要该行  使其IO为弱  要是板子没有上拉电阻就可注释该句
  36.         SPI_Init();         //SPI初始化,默认最低速
  37.         UartInit();        //UART初始化
  38.         DB_SendString("\nSPI and uart init  ok............\n");
  39.         LCD_Init();

  40.         DB_SendString("LCD12864 init  ok............\n");
  41.        
  42. //         SD_Init();
  43. //         DB_SendString("SD init  ok............\n");          //下面的挂载其实已经初始化SD卡了,可不必重复

  44.         res = pf_mount(&fatfs);                                        //挂在文件系统
  45.     if(res == FR_OK)     DB_SendString("挂载成功!\n"); //如果返回1,则挂载失败,否则成功
  46.         else                 DB_SendString("挂载失败\n");
  47.                
  48.         VS1003_Reset();
  49.         //Change_SineTest(1);                //正弦测试       
  50.         DB_SendString("vs1003 init  ok............\n");
  51.        
  52.         SPI_SetSpeed(0);   //最高速
  53.         VS_XDCS=0;                    //打开数据片选,注意此时XCS(片选)为高电平,SDI有效
  54.         VS_XCS = 1;                    //关闭片选

  55. }



  56. void main()
  57. {
  58.         all_init();
  59.         Main_Menu();
  60.         DB_SendString("所有初始化成功............\r\n");

  61.         DB_SendInfo("VS_MODE = ",VS1003_ReadReg(VS_MODE));         //通过打印寄存器数值看VS1003是否初始化成功
  62.         DB_SendInfo("VS_CLOCKF = ",VS1003_ReadReg(VS_CLOCKF));
  63.        
  64.         Main_Oper();   //死循环
  65. }
复制代码

所有资料51hei提供下载:
MP3.zip (11.19 MB, 下载次数: 163)
回复

使用道具 举报

ID:105206 发表于 2018-1-22 06:39 | 显示全部楼层
看看,学习下。
回复

使用道具 举报

ID:251061 发表于 2019-7-11 22:32 | 显示全部楼层
好像编译不能通过,
SD.C(254): error C141: syntax error near '}', expected ';'
compiling main.c...
MENU_UI.C(24): error C202: 'dir': undefined identifier
MENU_UI.C(28): error C202: 'dir': undefined identifier
MENU_UI.C(45): error C202: 'dir': undefined identifier
MENU_UI.C(49): error C202: 'dir': undefined identifier
MENU_UI.C(60): error C202: 'dir': undefined identifier
MENU_UI.C(70): error C202: 'MusicMax': undefined identifier
MENU_UI.C(93): error C202: 'bitrate': undefined identifier
MENU_UI.C(94): error C202: 'bitrate': undefined identifier
MENU_UI.C(105): error C202: 'Time': undefined identifier
MENU_UI.C(106): error C202: 'Time': undefined identifier
MENU_UI.C(107): error C202: 'Time': undefined identifier
MENU_UI.C(108): error C202: 'Time': undefined identifier
MENU_UI.C(109): error C202: 'Time': undefined identifier
MENU_UI.C(115): error C202: 'DispBitRate': undefined identifier
MENU_UI.C(116): error C202: 'DispBitRate': undefined identifier
MENU_UI.C(117): error C202: 'DispBitRate': undefined identifier
MENU_UI.C(119): error C202: 'DispBitRate': undefined identifier
MENU_UI.C(148): error C202: 'pMusic': undefined identifier
MENU_UI.C(151): error C202: 'key': undefined identifier
MENU_UI.C(152): error C202: 'key': undefined identifier
MENU_UI.C(154): error C202: 'flag_music': undefined identifier
MENU_UI.C(159): error C202: 'rc': undefined identifier
MENU_UI.C(160): error C202: 'rc': undefined identifier
MENU_UI.C(161): error C202: 'pMusic': undefined identifier
MENU_UI.C(176): error C202: 'key': undefined identifier
MENU_UI.C(178): error C202: 'pMusic': undefined identifier
MENU_UI.C(180): error C202: 'pMusic': undefined identifier
MENU_UI.C(181): error C202: 'pMusic': undefined identifier
MENU_UI.C(184): error C202: 'key': undefined identifier
MENU_UI.C(184): error C202: 'flag_music': undefined identifier
MENU_UI.C(185): error C202: 'key': undefined identifier
MENU_UI.C(190): error C202: 'key': undefined identifier
MENU_UI.C(192): error C202: 'Music_Vol': undefined identifier
MENU_UI.C(195): error C202: 'Music_Vol': undefined identifier
MENU_UI.C(197): error C202: 'MusicVol': undefined identifier
MENU_UI.C(198): error C202: 'MusicVol': undefined identifier
MENU_UI.C(199): error C202: 'MusicVol': undefined identifier
MENU_UI.C(200): error C202: 'MusicVol': undefined identifier
MENU_UI.C(201): error C202: 'Music_Vol': undefined identifier
MENU_UI.C(209): error C202: 'key': undefined identifier
MENU_UI.C(211): error C202: 'Music_Vol': undefined identifier
MENU_UI.C(214): error C202: 'Music_Vol': undefined identifier
MENU_UI.C(216): error C202: 'MusicVol': undefined identifier
MENU_UI.C(217): error C202: 'MusicVol': undefined identifier
MENU_UI.C(218): error C202: 'MusicVol': undefined identifier
MENU_UI.C(219): error C202: 'MusicVol': undefined identifier
MENU_UI.C(220): error C202: 'Music_Vol': undefined identifier
MENU_UI.C(242): error C202: 'MusicMax': undefined identifier
MENU_UI.C(246): error C202: 'dir': undefined identifier
MENU_UI.C(248): error C202: 'dir': undefined identifier
MENU_UI.C(252): error C202: 'MusicMax': undefined identifier
MENU_UI.C(257): error C202: 'MusicMax': undefined identifier
MENU_UI.C(261): error C202: 'MusicMax': undefined identifier
MENU_UI.C(262): error C202: 'MusicMax': undefined identifier
MENU_UI.C(264): error C202: 'MusicMax': undefined identifier
MENU_UI.C(279): error C202: 'key': undefined identifier
MENU_UI.C(285): error C202: 'key': undefined identifier
MENU_UI.C(290): error C202: 'key': undefined identifier
MENU_UI.C(298): error C202: 'MusicMax': undefined identifier
MENU_UI.C(304): error C202: 'MusicMax': undefined identifier
MENU_UI.C(304): error C202: 'MusicMax': undefined identifier
MENU_UI.C(322): error C202: 'key': undefined identifier
MENU_UI.C(340): error C202: 'key': undefined identifier
MENU_UI.C(355): error C202: 'TxtMax': undefined identifier
MENU_UI.C(359): error C202: 'dir': undefined identifier
MENU_UI.C(361): error C202: 'dir': undefined identifier
MENU_UI.C(363): error C202: 'TxtMax': undefined identifier
MENU_UI.C(368): error C202: 'TxtMax': undefined identifier
MENU_UI.C(370): error C202: 'dir': undefined identifier
MENU_UI.C(372): error C202: 'TxtMax': undefined identifier
MENU_UI.C(374): error C202: 'dir': undefined identifier
MENU_UI.C(387): error C202: 'key': undefined identifier
MENU_UI.C(388): error C202: 'key': undefined identifier
MENU_UI.C(389): error C202: 'key': undefined identifier
MENU_UI.C(389): error C202: 'old_Doc_pos': undefined identifier
MENU_UI.C(389): error C202: 'Doc_pos': undefined identifier
MENU_UI.C(390): error C202: 'key': undefined identifier
MENU_UI.C(390): error C202: 'old_Doc_pos': undefined identifier
MENU_UI.C(390): error C202: 'Doc_pos': undefined identifier
MENU_UI.C(391): error C202: 'key': undefined identifier
MENU_UI.C(401): error C202: 'key': undefined identifier
MENU_UI.C(405): error C202: 'old_Doc_pos': undefined identifier
MENU_UI.C(407): error C202: 'old_Doc_pos': undefined identifier
MENU_UI.C(408): error C202: 'Doc_pos': undefined identifier
MENU_UI.C(422): error C202: 'key': undefined identifier
MENU_UI.C(423): error C202: 'key': undefined identifier
MENU_UI.C(424): error C202: 'key': undefined identifier
MENU_UI.C(426): error C202: 'Music_Vol': undefined identifier
MENU_UI.C(429): error C202: 'Music_Vol': undefined identifier
MENU_UI.C(431): error C202: 'MusicVol': undefined identifier
MENU_UI.C(432): error C202: 'MusicVol': undefined identifier
MENU_UI.C(433): error C202: 'MusicVol': undefined identifier
MENU_UI.C(434): error C202: 'MusicVol': undefined identifier
MENU_UI.C(435): error C202: 'Music_Vol': undefined identifier
MENU_UI.C(443): error C202: 'key': undefined identifier
MENU_UI.C(445): error C202: 'Music_Vol': undefined identifier
MENU_UI.C(448): error C202: 'Music_Vol': undefined identifier
MENU_UI.C(450): error C202: 'MusicVol': undefined identifier
MENU_UI.C(451): error C202: 'MusicVol': undefined identifier
MENU_UI.C(452): error C202: 'MusicVol': undefined identifier
MENU_UI.C(453): error C202: 'MusicVol': undefined identifier
MENU_UI.C(454): error C202: 'Music_Vol': undefined identifier
MENU_UI.C(462): error C202: 'key': undefined identifier
MENU_UI.C(466): error C202: 'key': undefined identifier
MENU_UI.C(490): error C202: 'key': undefined identifier
MENU_UI.C(491): error C202: 'key': undefined identifier
MENU_UI.C(492): error C202: 'key': undefined identifier
MENU_UI.C(492): error C202: 'oldmpos': undefined identifier
MENU_UI.C(492): error C202: 'mpos': undefined identifier
MENU_UI.C(493): error C202: 'key': undefined identifier
MENU_UI.C(493): error C202: 'oldmpos': undefined identifier
MENU_UI.C(493): error C202: 'mpos': undefined identifier
MENU_UI.C(494): error C202: 'key': undefined identifier
MENU_UI.C(496): error C202: 'mpos': undefined identifier
MENU_UI.C(533): error C202: 'key': undefined identifier
MENU_UI.C(535): error C202: 'oldmpos': undefined identifier
MENU_UI.C(537): error C202: 'oldmpos': undefined identifier
MENU_UI.C(538): error C202: 'mpos': undefined identifier
MENU_UI.C(542): error C202: 'mpos': undefined identifier
compiling myfun.c...
MYFUN.C(55): warning C291: not every exit path returns a value
compiling 12864.c...
compiling pff.c...
compiling diskio.c...
Target not created
回复

使用道具 举报

ID:517224 发表于 2019-7-22 09:42 | 显示全部楼层
看看,顺便练习一下
回复

使用道具 举报

ID:377382 发表于 2020-5-22 22:45 | 显示全部楼层
感谢分享
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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