CS5532 C51驱动程序

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

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

//根据实际情况定义
//sbit SDI5532 = P2^1;
//sbit SDO5532 = P2^2;
//sbit CLK5532 = P2^3;
//sbit CS5532 = P2^0;

//sbit ACC7 = ACC^7;
//sbit ACC0 = ACC^0;

//#define BYTE unsigned char
//#define WORD unsigned int

#define Adjust5532Run 0
#define ReadSADC5532Run 1
#define ReadMADC5532Run 1

//The ADC results varibles define
struct{
          unsigned char top;
          unsigned char high;
          unsigned char mid;
          unsigned char low;
         }
RegDat;

//The CS5532-ASZ comm define
#define RegRead     0x08
#define RegWrite 0x00

//=== Offset Register ===
#define OffsetRS 0x09

//=== Gain Register ===
#define GainRS 0x0a

//=== Configuration Register ===
#define ConfigWrite 0x03  //write config
#define ConfigRead 0x0b  //read config

#define PSS 0x80        //Power Save Select
#define PDW 0x40       //Power Down Mode
#define RS     0x20        //Reset System
#define RV     0x10          //Reset Valid
#define IS     0x08         //Input Short
#define GB     0x04       //Guard Signal Bit
#define VRS 0x02       //Voltage Reference Select(Ref>2.5V,VRS=0)
#define A1     0x01
#define A0     0x80
#define OLS 0x40
#define OGS 0x10
#define FRS 0x08

//=== Channel Setup Register ===
#define SetupCH1 0x05
#define SetupCH2 0x15

//Channel Select Bits
#define CH1 0x00   //CS1=0,CS0=0
#define CH2 0x40   //CS1=0,CS0=1
//Gain Bits
#define Gain1     0x00
#define Gain2     0x08
#define Gain4     0x10
#define Gain8     0x18
#define Gain16 0x20
#define Gain32 0x28
#define Gain64 0x30

//=== Converter mode ===
#define SingleC 0x80
#define ContinC 0xC0
#define Setup1 0x00
#define Setup2 0x08
#define Setup3 0x10
#define Setup4 0x18
#define Setup5 0x20
#define Setup6 0x28
#define Setup7 0x30
#define Setup8 0x38

//The data(8bit) form MCU to CS5532
void SendByte5532(unsigned char Dat)
       {
        unsigned char i;
        CLK5532 = 0;
        for(i=8;i>0;i--)
           {
            SDI5532=(bit)(Dat & 0x80);
            CLK5532=1;
             _nop_();_nop_();
             _nop_();_nop_();
            CLK5532=0;
             _nop_();_nop_();
             _nop_();_nop_();
            Dat = Dat<<1;
           }
        SDI5532 = 1;
       }

//The Setup CS5532's register
void WriteReg5532(BYTE command,BYTE low,BYTE mid,BYTE high,BYTE top)
       {
        CS5532 = 0;
        SendByte5532(command);
        SendByte5532(low);
        SendByte5532(mid);
        SendByte5532(high);
        SendByte5532(top);
        CS5532 = 1;
       }

//The data(8bit) form CS5532 to MCU
unsigned char ReceiveByte5532(void)
       {
        unsigned char i;
        ACC=0;
        for(i=8;i>0;i--)
           {
            ACC=ACC<<1;
            ACC0=SDO5532;
            CLK5532=1;
             _nop_();_nop_();
             _nop_();_nop_();
            CLK5532=0;
             _nop_();_nop_();
             _nop_();_nop_();
           }
         return(ACC);
       }

//Receive ADC signal data form CS5532 to MCU
#if ReadSADC5532Run
void ReadSADC5532(unsigned char command)
       {
        CS5532 = 0;
        SendByte5532(command);
        do{_nop_();CLK5532=0;SDI5532=0;}while(SDO5532!=0);
        SendByte5532(0x00);              //8bit SCLK and SDI=0;
        RegDat.top = ReceiveByte5532();
        RegDat.high = ReceiveByte5532();
        RegDat.mid = ReceiveByte5532();
        RegDat.low = ReceiveByte5532();
        CS5532 = 1;
       }
#endif

#if ReadMADC5532Run
void ReadMADC5532(unsigned char command)
       {
        CS5532 = 0;
        do{_nop_();}while(SDO5532!=0);
       //SDO5532 = 1;
        SendByte5532(command);            //8bit SCLK and SDI=command;
        RegDat.top = ReceiveByte5532();
        RegDat.high = ReceiveByte5532();
        RegDat.mid = ReceiveByte5532();
        RegDat.low = ReceiveByte5532();
        CS5532 = 1;
       }
#endif

//Receive CS5532's Register from CS5532 to MCU
void ReadReg5532(unsigned char command)
       {
        CS5532 = 0;
        SendByte5532(command);
        RegDat.top = ReceiveByte5532();
        RegDat.high = ReceiveByte5532();
        RegDat.mid = ReceiveByte5532();
        RegDat.low = ReceiveByte5532();
        CS5532 = 1;
       }

#if Adjust5532Run
void Adjust5532(unsigned char command)
       {
        CS5532 = 0;
        SendByte5532(command);
        do{_nop_();}while(SDO5532!=0);
        SendByte5532(0x0a);
        RegDat.top = ReceiveByte5532();
        RegDat.high = ReceiveByte5532();
        RegDat.mid = ReceiveByte5532();
        RegDat.low = ReceiveByte5532();
        CS5532 = 1;
       }
#endif

//The initialization CS5532
void Init5532(void)
       {
        WriteReg5532(0xff,0xff,0xff,0xff,0xff);
        WriteReg5532(0xff,0xff,0xff,0xff,0xff);
        WriteReg5532(0xff,0xff,0xff,0xff,0xff);
        WriteReg5532(0xff,0xff,0xff,0xff,0xfe);
       }
//The CS5532-ASZ subpram end

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

转载于:https://www.cnblogs.com/GL-BBL/archive/2013/02/20/2918749.html

CS5532 C51驱动程序相关推荐

  1. ds12c887c语言程序,时钟芯片ds12c887的C51驱动程序

    文件名称:ds12c887.c 适用范围:时钟芯片ds12c887的驱动程序 ************************************************************* ...

  2. TM1638快速开发教程(基于正点原子mini板stm32f103rc)

    参加电赛,指导老师给了块TM1638模块,商家给的是C51驱动代码,改写成32驱动代码. tm1638.h文件 #ifndef __TM1638_H #define __TM1638_H#define ...

  3. 实验 键盘与LED实验

    实验 键盘与LED实验 一.实验要求 P0口接7段LED数码管,P1口接8个独立按钮,分别控制数码管显示数字0-7,画出原理电路图,编写驱动程序. 二.实验目的 1.熟练keil软件的基本操作: 2. ...

  4. C51单片机——红外遥控 驱动程序

    C51红外遥控驱动程序 驱动函数封装 IrReceive.h文件 IrReceive.c文件 测试实验 main.c文件 本文为学习HC6800-EM3 V2.2开发板的学习笔记汇总,本文所用 红外接 ...

  5. 12864汉字液晶显示驱动程序

    参考程序1 12864汉字液晶显示驱动程序 #include <reg51.h> #include <stdlib.h> #define uchar unsigned char ...

  6. 重力感应贪吃蛇(C51 MPU6050 8*8LED点阵)

    重力感应贪吃蛇(C51 MPU6050 8*8LED点阵) 本文讲述如何从无到有用C51做一个重力感应的贪吃蛇,包括元件选型.原理图PCB绘制和代码编写. 重力感应贪吃蛇(C51 MPU6050 8* ...

  7. 30、T5L 迪文屏 C51开发之 ADC模数转换

    T5L 迪文屏 C51开发之 ADC模数转换 1.介绍 2.例程功能介绍 3.GUI界面设计 4.C51程序设计 1.介绍   T5L 芯片内部的 ADC 模数转换外设,有一点需要注意的是此 ADC ...

  8. keil (MDK + C51) 安装

    MDK+C51安装教程 一. 下载 二. MDK安装 三. C51安装(不需要开发51的可跳过此安装) 四. C51注册 五. MDK注册 六. MDK芯片包安装 一. 下载 链接:https://p ...

  9. keil集成环境c语言总结,Keil C51单片机集成开发环境编程与调试教程

    同 VC 之类的通用 C 语言集成开发环境(IDE)一样,Keil 也采用"工程" (Project)的方式管理源代码及相关文件,这种管理方式为由多个源代码文件组 成的大型程序开发 ...

  10. python编程单片机_Python与C51单片机交互

    Python与C51单片机交互,嘿嘿,其实是在OSX下用串口交互了~~ 1.首先装上CH340/CH341 For Mac USB转串口驱动程序 2.安装Python串口模块 pip install ...

最新文章

  1. zookeeper脑裂
  2. 依然持有比特币,Roger Ver谈投资心经
  3. 原 水质监测系统解决方案
  4. JavaScript面试时候的坑洼沟洄——表达式与运算符
  5. canvas的简单实例集合
  6. linux oracle bad elf,oracle11g安装到red hat6.2 64位系统报错:/lib/ld-linux.so.2: bad ELF interpreter...
  7. 数组(ArrayList)底层怎样扩容
  8. js 短信验证码 6位数字
  9. IDEA 2020.3 连接mysql数据库报错解决
  10. 脚本化HTTP 取得响应 指定请求
  11. 【转】MySQL双主一致性架构优化
  12. 浙江富润拟12亿并购泰一指尚 跨界互联网及大数据
  13. (hdu step 6.3.3)Air Raid(最小路径覆盖:求用最少边把全部的顶点都覆盖)
  14. 【pandas】读取大型文件技巧
  15. linux 命令行 迅雷替代,linux下迅雷的替代
  16. MySQL开发者需要了解的12个技巧与窍门
  17. SSM项目tomcat启动失败-Multiple Contexts have a path of “/ssm-crud“
  18. 在天堂与地狱之间——清华浪子梦断中关村
  19. Android开发之仿QQ表情实现(下)
  20. 39-网上商城数据库-用户信息数据操作

热门文章

  1. TonglinkQ8基于linux 7.5的安装
  2. 食品进销存十大品牌排行榜新鲜出炉,来看看哪个最适合你
  3. 数据分析法、数据分析方法论总结
  4. Java初级程序员面试总结(二) --HashMap篇
  5. surface人脸识别摄像头不支持的情况解决方案
  6. 智慧路灯网关下的校园智慧路灯照明解决方案
  7. JAVA打包成EXE文件,能在没有jre环境的电脑上运行
  8. Java类和对象(重点详解)
  9. 利用python批量创建文件夹、批量创建文件、批量复制文件到指定文件夹
  10. AI新星丨普林斯顿陈丹琦