📄 ad7416.c
字号:
#include <reg51.h>
#include <intrins.h>
#include <stdio.h>
sbit SDA =P1^0;
sbit SCL =P1^1;
sbit OTI =P1^2;
sbit AD0 =P0^0;
sbit AD1 =P0^1;
sbit AD2 =P0^2;
unsigned char Command;
void START()
{
SCL=1;
SDA=1;
_nop_();
_nop_();
_nop_();
_nop_();
SDA=0;
_nop_();
_nop_();
_nop_();
_nop_();
SCL=0;
}
void STOP()
{
SDA=0;
SCL=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SDA=1;
}
void WRCOM(unsigned char com)
{
unsigned char i;
Command=com;
for(i=0;i<8;i++)
{
SCL=0;
if(Command & 0x80 )
SDA=1;
else SDA=0;
_nop_();
_nop_();
Command=Command<<1;
_nop_();
SCL=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
SCL=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SDA=1;
}
char RDCOM()
{
unsigned char i;
char temp;
for(i=0;i<8;i++)
{
SCL=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SCL=1;
_nop_();
_nop_();
temp=temp<<1;
if(SDA==1) temp=temp | 0x01;
}
SCL=0;
_nop_();
_nop_();
SDA=1;
return(temp);
}
main()
{
unsigned char com;
char dat;
TMOD=0x20|TMOD;
TL1=0xfd;
TH1=0xfd;
TR1=1;
SCON=0x50;
TI=1;
P0=0XFF;
puts("the temp is:\r\n");
com=0x9E;
START();
WRCOM(com);
com=0x01;
WRCOM(com);
com=0x18;
WRCOM(com);
STOP();
START();
com=0x9e;
WRCOM(com);
com=0x03;
WRCOM(com);
com=0x30;
WRCOM(com);
STOP();
START();
com=0x9e;
WRCOM(com);
com=0x02;
WRCOM(com);
com=0x0a;
WRCOM(com);
STOP();
START();
com=0x9e;
WRCOM(com);
STOP();
START();
com=0x00;
WRCOM(com);
STOP();
START();
com=0x9f;
WRCOM(com);
while(1)
{
STOP();
START();
dat=RDCOM();
STOP();
printf("%d",dat);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -