找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2834|回复: 1
打印 上一主题 下一主题
收起左侧

sc5020b语音ic驱动

[复制链接]
跳转到指定楼层
楼主
ID:170352 发表于 2017-3-13 17:09 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

  1. /*
  2. *******************************************************************
  3. *                        file:sc5020b.c
  4. *                        
  5. *                        func:sc5020b sound chip driver
  6. *
  7. *                        time:2017.03.01
  8. *                        
  9. *                        auth:lzx
  10. *******************************************************************
  11. */

  12. /*file*/
  13. #include"is32u320a.h"                                        //the define of is32u320a register address
  14. #include"sc5020b.h"                                                //the extern interface
  15. #include"is32u320a_gpio.h"                                //the func of io_config library

  16. /*flag*/
  17. #define G_SC5020B_BUSY_DIRECTION  GPIO33                        //use GPIO33 to be the sc5020b_busy_direction
  18. #define G_SC5020B_SDA_DIRECTION   GPIO34                        //use GPIO34 to be the sc5020b_sda_direction
  19. #define G_SC5020B_BUSY_IS_NOBUSY  GPIODATA2&0X01        //make sure G_SC5020B_BUSY is busy or not

  20. /*
  21. *************************************
  22. *          name:void sc5020b_io_initial()
  23. *
  24. *          func:initiate the sc5020b_io
  25. *
  26. *          time:2017.03.01
  27. *                        
  28. *          auth:lzx
  29. *************************************
  30. */
  31. void sc5020b_io_initial(void)
  32. {
  33.         SetGpioXIn(G_SC5020B_BUSY_DIRECTION);                //G_SC5020B_BUSY is an input
  34.         SetGpioXOut(G_SC5020B_SDA_DIRECTION);                //G_SC5020B_SDA  is an output
  35. }

  36. /*
  37. *************************************
  38. *          name:void sc5020b_waitbusy(void)
  39. *
  40. *          func:wait until sc5020b free
  41. *
  42. *          time:2017.03.01
  43. *                        
  44. *          auth:lzx
  45. *************************************
  46. */
  47. void sc5020b_waitbusy(void)
  48. {
  49.     unsigned int times;
  50.     for(times=0;times<50;times++)                                        //the max time is 5 seconds,circle will be ended once more than max time
  51.     {
  52.        //sc5020b_delayms(100);                                                         //the time gap between each sound segment must be more than 100ms
  53.        if(G_SC5020B_BUSY_IS_NOBUSY) break;                                //when G_SC5020B_BUSY is free,the chip can be sent commond
  54.     }   
  55. }

  56. /*
  57. *************************************
  58. *          name:sc5020b_sendcommand(u8 dat)
  59. *
  60. *          func:send command to sc5020b
  61. *
  62. *          time:2017.03.01
  63. *                        
  64. *          auth:lzx
  65. *************************************
  66. */
  67. void sc5020b_sendcommand(unsigned char dat)
  68. {
  69.         char temp;                                        //be used to make sure the each bit value of dat
  70.         sc5020b_waitbusy();                        //wait until sc5020b free,static wait time is 100ms
  71.         //sc5020b_delayms(5);                        //wait for 5 micro second
  72.         for(temp=0;temp<8;temp++)
  73.         {
  74.                 SetGpioXHigh(G_SC5020B_SDA_DIRECTION);                 //pull up the G_SC5020B_SDA
  75.         if(dat&0x01)
  76.         {                                                //send 1:high/low=3:1
  77.           //sc5020b_delayus(1500);//delay1500us        
  78.           SetGpioXLow(G_SC5020B_SDA_DIRECTION);
  79.           //sc5020b_delayus(500); //delay500us
  80.         }
  81.        else
  82.        {                                                 //send 0:high/low=1:3
  83.           //sc5020b_delayus(500); //delay500us
  84.           SetGpioXLow(G_SC5020B_SDA_DIRECTION);
  85.           //sc5020b_delayus(1500);//delay1500us   
  86.        }
  87.        dat>>=1;
  88.         }
  89. }

复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:564486 发表于 2019-6-21 10:50 | 只看该作者
哥这哥音量怎么调节呀?手册上写的发E0-EF调,但是不管用
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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