📄 ad7982.c
字号:
#include<stdio.h>
#include<aduc841.h>
/******************************************************************
DEFINE CONTROL PINS OF ADUC841 FOR THE PURPOSE OF AD7982 CONTROL.
Customers should define the pins according to their design.
******************************************************************/
sbit SCK=0x0A3;
sbit CNV=0x0A0;
sbit SDO=0x0A2;
sbit SDI=0x0A1;
unsigned char DataRead[3];
void ReadData(unsigned char nByte);
void Delay(unsigned int Time)
{
while(Time)
{
Time--;
}
}
void main()
{
/* Set up UART */
T3CON = 0x086;
T3FD = 0x08;
SCON = 0x052;
SDI=1;
SDO=1;
SCK=0;
while(1) // CS Mode,3-Wire Without Busy Indicator
{
CNV=0;
Delay(30);
CNV=1;
Delay(3000);
CNV=0;
ReadData(3);
printf("Data: %02BX %02BX %02BX\r\n", DataRead[0],DataRead[1],DataRead[2]);
}
}
void ReadData(unsigned char nByte) // nByte is the number of bytes which need to be read
{
int i,j,l;
unsigned char temp;
temp=0;
for(i=0; i<nByte; i++)
{
if (i==0)l=2;
for(j=0; j<l; j++)
{
SCK=0;
Delay(50);
SCK=1;
if(SDO==0)
{
temp=temp<<1;
}
else
{
temp=temp<<1;
temp=temp+0x01;
}
Delay(50);
}
l=8;
DataRead[i]=temp;
temp=0;
}
SCK=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -