/*
***********************************************************************************
* Innov-Tech
* Baohe Tunxi Road HF
* HeFei, 230009
* China
*
* (c) Copyright Alexander.Schu, Innov-Tech, HeFei
*
* All rights reserved. Innov-Tech¡¯s source code is an unpublished work and the
* use of a copyright notice does not imply otherwise. This source code contains
* confidential, trade secret material of Innov-Tech. Any attempt or participation
* in deciphering, decoding, reverse engineering or in any way altering the source
* code is strictly prohibited, unless the prior written consent of Innov-Tech
* is obtained.
*
* Filename : max1416.c
* Programmer(s): Alexander.Schu(CN)
* Modified : 2009/08/08
* Description :
***********************************************************************************
*/
//#include "project.h"
/*
// ------ Register Macro ------ //
#define CMM_R 0x00 // communication register,bidirectional,write to it to initial your operations
#define SET_R 0x10 // setup register,bidirectional,write to it to config your conversion
#define CLK_R 0x20 // clock register,bidirectional,write to it to config your conversion clock
#define DAT_R 0x30 // data register,read only,16 bits,hold the result of conversion
#define TST_R 0x40 // test register
#define OFS_R 0x60 // offset register
#define GAN_R 0x70 // gain register
// ------ Extern Functions ------ //
extern void MAX1416Init (void); // MAX1416 initial funcation
extern void MAX1416WrCmd (unsigned char reg_addr,
unsigned char op_mod,
unsigned char chip); // write cmd to MAX1416,to select the very register on the very chip,config operation
extern void MAX1416WrDat (unsigned char dat,
unsigned char chip); // write data to MAX1416
extern unsigned int MAX1416RdDat (unsigned char reg_type,
unsigned char chip); // read data from MAX1416,select the right register
extern void MAX1416WrByte(unsigned char dat); // write one byte,it's the basic write operation
*/
/*-=================================================-*\
*
* Name : MAX1416WrByte
* Argument : unsigned char dat
* Return : None
* Description £ºwrite a byte data to max1416
*
\*-=================================================-*/
void MAX1416WrByte(unsigned char dat)
{
unsigned char index_i;
for (index_i = 0; index_i < 8; index_i++)
{
CLK = 0;
if (dat & 0x80) DIN = 1;
else DIN = 0;
dat <<= 1;
CLK = 1;
}
}
/*-=================================================-*\
*
* Name : MAX1416WrDat
* Argument : unsigned char dat
* unsigned char chip
* Return : None
* Description £ºwrite the "dat" to the very "chip"
*
\*-=================================================-*/
void MAX1416WrDat(unsigned char dat,
unsigned char chip)
{
switch (chip)
{
case 1:
MAX1416_CS_1 = 0;
break;
case 2:
MAX1416_CS_2 = 0;
break;
case 3:
MAX1416_CS_3 = 0;
break;
case 4:
MAX1416_CS_4 = 0;
break;
default:
break;
}
MAX1416WrByte(dat);
switch (chip)
{
case 1:
MAX1416_CS_1 = 1;
break;
case 2:
MAX1416_CS_2 = 1;
break;
case 3:
MAX1416_CS_3 = 1;
break;
case 4:
MAX1416_CS_4 = 1;
break;
default:
break;
}
}
/*-=================================================-*\
*
* Name : MAX1416WrDat
* Argument : unsigned char reg_type
* unsigned char chip
* Return : unsigned int
* Description £ºread dat from the register of the
* right chip
*
\*-=================================================-*/
unsigned int MAX1416RdDat(unsigned char reg_type,
unsigned char chip)
{
unsigned char index_i;
unsigned int dat;
dat = 0x0000;
if (DAT_R == reg_type)
index_i = 16;
else index_i = 8;
switch (chip)
{
case 1:
MAX1416_CS_1 = 0;
break;
case 2:
MAX1416_CS_2 = 0;
break;
case 3:
MAX1416_CS_3 = 0;
break;
case 4:
MAX1416_CS_4 = 0;
break;
default:
break;
}
/* first notch,must have this notch for the start flag */
CLK = 1;
;
;
;
CLK = 0;
;
;
;
CLK = 1;
for (; index_i > 0; index_i--)
{
CLK = 1;
dat <<= 1;
dat |= MAX1416_DOUT;
CLK = 0;
}
switch (chip)
{
case 1:
MAX1416_CS_1 = 1;
break;
case 2:
MAX1416_CS_2 = 1;
break;
case 3:
MAX1416_CS_3 = 1;
break;
case 4:
MAX1416_CS_4 = 1;
break;
default:
break;
}
return (dat);
}
/*-=================================================-*\
*
* Name : MAX1416WrCmd
* Argument : unsigned char reg_addr
* unsigned char op_mod
* unsigned char chip
* Return : None
* Description £ºwrite a cmd to the communication reg
* -ister on the right "chip",and config
* the operation modle of the next regis
* -ter.
* op_mod == 1,for "read"
* op_mod == 0,for "write"
*
\*-=================================================-*/
void MAX1416WrCmd(unsigned char reg_addr,
unsigned char op_mod,
unsigned char chip)
{
unsigned char operation;
unsigned char cmd;
if (1 == op_mod) operation = 0x08;
else operation = 0x00;
cmd = (operation | reg_addr);
switch (chip)
{
case 1:
MAX1416_CS_1 = 0;
break;
case 2:
MAX1416_CS_2 = 0;
break;
case 3:
MAX1416_CS_3 = 0;
break;
case 4:
MAX1416_CS_4 = 0;
break;
default:
break;
}
MAX1416WrByte(cmd);
switch (chip)
{
case 1:
MAX1416_CS_1 = 1;
break;
case 2:
MAX1416_CS_2 = 1;
break;
case 3:
MAX1416_CS_3 = 1;
break;
case 4:
MAX1416_CS_4 = 1;
break;
default:
break;
MAX1416驱动代码
3星 · 超过75%的资源 需积分: 10 194 浏览量
2009-10-09
18:37:55
上传
评论
收藏 3KB RAR 举报
Yur_syf
- 粉丝: 0
- 资源: 6
最新资源
- 默写49个过程、查看工具与技术
- (资源包名是松下不必介意实际是台达)台达PLC例程源码污水处理(台达PLC+触摸屏程序)
- 开唛K歌(沫沫VIP会员版)无限唱_2.1.5_新稳定版.apk
- (资源包名是松下不必介意实际是台达)台达PLC例程源码台达与丹佛斯fc51modbus通信程序带注解
- (资源包名是松下不必介意实际是台达)台达PLC例程源码台达霓虹灯循环程序
- 多种液体自动混合系统.mwp
- (资源包名是松下不必介意实际是台达)台达PLC例程源码台达例程序
- (资源包名是松下不必介意实际是台达)台达PLC例程源码台达程序
- (资源包名是松下不必介意实际是台达)台达PLC例程源码台达PLC与英威腾变频器的通讯控制
- 微服务开发各种注册中心对比
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈