求助,当伸手党,有没有CS5532 24位ADC芯片驱动程序

2020-01-10 19:45发布

求助,当伸手党,有没有CS5532 ADC芯片驱动程序。有的话,留一份,非常感谢。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
3条回答
OurWay
2020-01-10 23:36
很早以前写过一个,请无视英文注解,呵呵,供参考。

  1. //The program for CS5532-ASZ
  2. //This is a 24bit ADC and PGIA
  3. //Made by OurWay and 2006/03/21

  4. //#include <reg51.h>
  5. //#include <intrins.h>

  6. //根据实际情况定义
  7. //sbit SDI5532 = P2^1;
  8. //sbit SDO5532 = P2^2;
  9. //sbit CLK5532 = P2^3;
  10. //sbit CS5532 = P2^0;

  11. //sbit ACC7 = ACC^7;
  12. //sbit ACC0 = ACC^0;

  13. //#define BYTE unsigned char
  14. //#define WORD unsigned int
  15. #define Adjust5532Run 0
  16. #define ReadSADC5532Run 1
  17. #define ReadMADC5532Run 1

  18. //The ADC results varibles define
  19. struct{
  20.           unsigned char top;
  21.           unsigned char high;
  22.           unsigned char mid;
  23.           unsigned char low;
  24.          }
  25. RegDat;

  26. //The CS5532-ASZ comm define
  27. #define RegRead     0x08
  28. #define RegWrite 0x00

  29. //=== Offset Register ===
  30. #define OffsetRS 0x09

  31. //=== Gain Register ===
  32. #define GainRS 0x0a

  33. //=== Configuration Register ===
  34. #define ConfigWrite 0x03  //write config
  35. #define ConfigRead 0x0b  //read config

  36. #define PSS 0x80        //Power Save Select
  37. #define PDW 0x40       //Power Down Mode
  38. #define RS     0x20        //Reset System
  39. #define RV     0x10          //Reset Valid
  40. #define IS     0x08         //Input Short
  41. #define GB     0x04       //Guard Signal Bit
  42. #define VRS 0x02       //Voltage Reference Select(Ref>2.5V,VRS=0)
  43. #define A1     0x01
  44. #define A0     0x80
  45. #define OLS 0x40
  46. #define OGS 0x10
  47. #define FRS 0x08


  48. //=== Channel Setup Register ===
  49. #define SetupCH1 0x05
  50. #define SetupCH2 0x15

  51. //Channel Select Bits
  52. #define CH1 0x00   //CS1=0,CS0=0
  53. #define CH2 0x40   //CS1=0,CS0=1
  54. //Gain Bits
  55. #define Gain1     0x00
  56. #define Gain2     0x08
  57. #define Gain4     0x10
  58. #define Gain8     0x18
  59. #define Gain16 0x20
  60. #define Gain32 0x28
  61. #define Gain64 0x30

  62. //=== Converter mode ===
  63. #define SingleC 0x80
  64. #define ContinC 0xC0
  65. #define Setup1 0x00
  66. #define Setup2 0x08
  67. #define Setup3 0x10
  68. #define Setup4 0x18
  69. #define Setup5 0x20
  70. #define Setup6 0x28
  71. #define Setup7 0x30
  72. #define Setup8 0x38

  73. //The data(8bit) form MCU to CS5532
  74. void SendByte5532(unsigned char Dat)
  75.        {
  76.         unsigned char i;
  77.         CLK5532 = 0;
  78.         for(i=8;i>0;i--)
  79.            {
  80.             SDI5532=(bit)(Dat & 0x80);
  81.             CLK5532=1;
  82.              _nop_();_nop_();
  83.              _nop_();_nop_();
  84.             CLK5532=0;
  85.              _nop_();_nop_();
  86.              _nop_();_nop_();
  87.             Dat = Dat<<1;
  88.            }
  89.         SDI5532 = 1;
  90.        }

  91. //The Setup CS5532's register
  92. void WriteReg5532(BYTE command,BYTE low,BYTE mid,BYTE high,BYTE top)
  93.        {
  94.         CS5532 = 0;
  95.         SendByte5532(command);
  96.         SendByte5532(low);
  97.         SendByte5532(mid);
  98.         SendByte5532(high);
  99.         SendByte5532(top);
  100.         CS5532 = 1;
  101.        }

  102. //The data(8bit) form CS5532 to MCU
  103. unsigned char ReceiveByte5532(void)
  104.        {
  105.         unsigned char i;
  106.         ACC=0;
  107.         for(i=8;i>0;i--)
  108.            {
  109.             ACC=ACC<<1;
  110.             ACC0=SDO5532;
  111.             CLK5532=1;
  112.              _nop_();_nop_();
  113.              _nop_();_nop_();
  114.             CLK5532=0;
  115.              _nop_();_nop_();
  116.              _nop_();_nop_();
  117.            }
  118.          return(ACC);
  119.        }

  120. //Receive ADC signal data form CS5532 to MCU
  121. #if ReadSADC5532Run
  122. void ReadSADC5532(unsigned char command)
  123.        {
  124.         CS5532 = 0;
  125.         SendByte5532(command);
  126.         do{_nop_();CLK5532=0;SDI5532=0;}while(SDO5532!=0);
  127.         SendByte5532(0x00);              //8bit SCLK and SDI=0;
  128.         RegDat.top = ReceiveByte5532();
  129.         RegDat.high = ReceiveByte5532();
  130.         RegDat.mid = ReceiveByte5532();
  131.         RegDat.low = ReceiveByte5532();
  132.         CS5532 = 1;
  133.        }
  134. #endif

  135. #if ReadMADC5532Run
  136. void ReadMADC5532(unsigned char command)
  137.        {
  138.         CS5532 = 0;
  139.         do{_nop_();}while(SDO5532!=0);
  140.        //SDO5532 = 1;
  141.         SendByte5532(command);            //8bit SCLK and SDI=command;
  142.         RegDat.top = ReceiveByte5532();
  143.         RegDat.high = ReceiveByte5532();
  144.         RegDat.mid = ReceiveByte5532();
  145.         RegDat.low = ReceiveByte5532();
  146.         CS5532 = 1;
  147.        }
  148. #endif

  149. //Receive CS5532's Register from CS5532 to MCU
  150. void ReadReg5532(unsigned char command)
  151.        {
  152.         CS5532 = 0;
  153.         SendByte5532(command);
  154.         RegDat.top = ReceiveByte5532();
  155.         RegDat.high = ReceiveByte5532();
  156.         RegDat.mid = ReceiveByte5532();
  157.         RegDat.low = ReceiveByte5532();
  158.         CS5532 = 1;
  159.        }

  160. #if Adjust5532Run
  161. void Adjust5532(unsigned char command)
  162.        {
  163.         CS5532 = 0;
  164.         SendByte5532(command);
  165.         do{_nop_();}while(SDO5532!=0);
  166.         SendByte5532(0x0a);
  167.         RegDat.top = ReceiveByte5532();
  168.         RegDat.high = ReceiveByte5532();
  169.         RegDat.mid = ReceiveByte5532();
  170.         RegDat.low = ReceiveByte5532();
  171.         CS5532 = 1;
  172.        }
  173. #endif

  174. //The initialization CS5532
  175. void Init5532(void)
  176.        {
  177.         WriteReg5532(0xff,0xff,0xff,0xff,0xff);
  178.         WriteReg5532(0xff,0xff,0xff,0xff,0xff);
  179.         WriteReg5532(0xff,0xff,0xff,0xff,0xff);
  180.         WriteReg5532(0xff,0xff,0xff,0xff,0xfe);
  181.        }
  182. //The CS5532-ASZ subpram end

  183. //用的时间注意我定义的宏,这是个查询方式采集AD值的程序。
复制代码

一周热门 更多>