资源简介
ad5420 4-20mA 电流输出芯片 单片机开发必备
代码片段和文件信息
/***************************************************************************
Author : Neil Zhao - CAST
Date : Feb 23th 2009
File : ad5420driver_IO.c
Hardware : ADuC7026 and AD5420
Description : Use the GPIO to simulate the SPI communication of AD5420
***************************************************************************/
#include
#include “AD5420_IO.h“
#define SET_CLEAR() GP4DAT = (GP4DAT | 0x00040000) //P4.2->CLEAR
#define CLR_CLEAR() GP4DAT = (GP4DAT & 0xFFFBFFFF)
#define SET_LATCH() GP4DAT = (GP4DAT | 0x00080000) //P4.3->LATCH
#define CLR_LATCH() GP4DAT = (GP4DAT & 0xFFF7FFFF)
#define SET_SCL() GP4DAT = (GP4DAT | 0x00100000) //P4.4->SCLK
#define CLR_SCL() GP4DAT = (GP4DAT & 0xffefffff)
#define SET_SDO() GP4DAT = (GP4DAT | 0x00200000) //P4.5->SDIN
#define CLR_SDO() GP4DAT = (GP4DAT & 0xffdfffff)
void delay (int length)
{
while (length >0)
length--;
}
//---------------------------------
//void WriteToAD5420(unsigned char countunsigned char *Buf);
//---------------------------------
//Function that writes to the AD5420 via the SPI port.
//--------------------------------------------------------------------------------
void WriteToAD5420(unsigned char countunsigned char *Buf)
{
unsigned char ValueToWrite = 0;
unsigned char i = 0;
unsigned char j = 0;
CLR_LATCH();
for ( i=count;i>0;i-- )
{
ValueToWrite = *(Buf+i-1);
for (j=0; j<8; j++)
{
CLR_SCL();
if(0x80 == (ValueToWrite & 0x80))
{
SET_SDO(); //Send one to SDIN pin of AD5420
}
else
{
CLR_SDO(); //Send zero to SDIN pin of AD5420
}
delay(1);
SET_SCL();
delay(1);
ValueToWrite <<= 1; //Rotate data
}
}
CLR_SCL();
delay(1);
SET_LATCH();
delay(20);
}
//---------------------------------
//ReadFromAD5420();
//---------------------------------
//Function that reads from the AD5420 via the SPI port.
//--------------------------------------------------------------------------------
void ReadFromAD5420(unsigned char countunsigned char *buf)
{
unsigned char i = 0;
unsigned char j = 0;
unsigned int iTemp = 0;
unsigned char RotateData = 0;
CLR_LATCH();
for(j=count; j>0; j--)
{
for(i=0; i<8; i++)
{
CLR_SCL();
RotateData <<= 1; //Rotate data
delay(1);
CLR_SDO(); //write a nop condition when read the data.
iTemp = GP0DAT; //Read SDO of AD5420
SET_SCL();
if(0x00000020 == (iTemp & 0x00000020))
{
RotateData |= 1;
}
delay(1);
}
*(buf+j-1)= RotateData;
}
CLR_SCL();
delay(1);
SET_LATCH();
delay(20);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 32010 2009-03-24 13:02 AD5420\AD5420
文件 6687 2009-03-24 13:02 AD5420\AD5420.elf
文件 3135 2009-03-24 13:02 AD5420\AD5420.hex
文件 154 2009-03-24 13:02 AD5420\AD5420.lnp
文件 4084 2009-03-24 13:02 AD5420\AD5420.MAP
文件 1260 2009-08-25 14:15 AD5420\AD5420.Opt
文件 182 2009-08-25 14:15 AD5420\AD5420.plg
文件 12438 2009-03-24 13:02 AD5420\AD5420.SBR
文件 2092 2009-03-04 16:15 AD5420\AD5420.Uv2
文件 2753 2009-03-24 12:58 AD5420\ad5420_IO.c
文件 1871 2009-03-24 12:58 AD5420\ad5420_IO.h
文件 19579 2009-03-24 13:02 AD5420\ad5420_IO.LST
文件 28526 2009-03-24 13:02 AD5420\ad5420_IO.OBJ
文件 1260 2009-03-24 13:03 AD5420\AD5420_Opt.Bak
文件 2055 2009-03-04 16:14 AD5420\AD5420_Uv2.Bak
文件 2724 2009-03-24 12:55 AD5420\main.c
文件 17942 2009-03-24 13:02 AD5420\main.LST
文件 24378 2009-03-24 13:02 AD5420\main.OBJ
文件 24804 2009-03-24 13:02 AD5420\startup.LST
文件 6414 2009-03-24 13:02 AD5420\startup.OBJ
文件 15818 2005-10-04 12:04 AD5420\startup.s
评论
共有 条评论