📄 fad.c
字号:
#include<reg52.h>
#include<absacc.h>
#include<string.h>
#include<intrins.h>
sbit CS=P0^3; //FAD管脚定义
sbit SI=P0^2;
sbit SO=P0^1;
sbit SCK=P0^0;
unsigned char S_data,t1,t2,t3,t4;
void write_onebyte(unsigned char qq);
unsigned char read_onebyte(void);
void DelayMs(unsigned int tt);
void main()
{
CS=0;
write_onebyte(0x5a);
//write_onebyte(0x01);
SI=0;
//DelayMs(5);
t1=read_onebyte();
DelayMs(5);
write_onebyte(0x5a);
t2=read_onebyte();
DelayMs(5);
t3=read_onebyte();
DelayMs(5);
t4=read_onebyte();
while(1);
}
void write_onebyte(unsigned char qq)
{
unsigned char i;
for(i=0;i<8;i++)
{
SCK=0;
SI=(bit)(qq&0x80); //发送8位数据,先送最高位
qq<<= 1;
SCK=1;
}
SCK=0;//SI=0;
}
//====================================================================
//函数原型:unsigned char read_onebyte(void)
//功 能:从FAD接收一个字节
//====================================================================
unsigned char read_onebyte(void)
{
unsigned char i;
S_data=0;SI=0;
for(i=0;i<8;i++)
{
S_data <<= 1; //接收8位数据,先接收最高位
SCK=0;
SCK=1;
if(SO)
S_data++;
}
return(S_data) ;
}
void DelayMs(unsigned int tt)
{
unsigned int p,delay0;
for(p=0;p<tt;p++)
for(delay0=0;delay0<1000;delay0++);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -