ADS1100的51单片机程序New.docx
《ADS1100的51单片机程序New.docx》由会员分享,可在线阅读,更多相关《ADS1100的51单片机程序New.docx(9页珍藏版)》请在冰豆网上搜索。
![ADS1100的51单片机程序New.docx](https://file1.bdocx.com/fileroot1/2023-7/26/7647c8be-ef39-4619-9be4-f3e537ad1d90/7647c8be-ef39-4619-9be4-f3e537ad1d901.gif)
ADS1100的51单片机程序New
ADS1100的51单片机程序_New
ADS1100的51单片机程序
ADS1100的51单片机程序
#include
#include
#defineuintunsignedint
#defineucharunsignedchar
/*****ADS1100****/
sbitSda=P3^0;
sbitScl=P3^1;
/****12864*****/
sbitrs=P2^0;
sbitrw=P2^1;
sbitpsb=P2^2;
sbite=P2^5;
sbitrst=P2^4;
sbitWEI=P2^7;//定义位选
voiddelay_xms(uintxms)
{
uinti,j;
for(i=xms;i>0;i--)
for(j=112;j>0;j--);
}
/***************12864display********************/
write_com(ucharcom)
{
rs=0;
rw=0;
delay_xms(5);
P0=com;
e=1;
delay_xms(5);
e=0;
}
write_date(uchardate)
{
rs=1;
rw=0;
delay_xms(5);
P0=date;
e=1;
delay_xms(5);
e=0;
}
voidinit_12864()
{
P0=0xff;
WEI=1;
WEI=0;
rs=0;
rw=0;
e=0;
psb=1;
rst=1;
delay_xms(50);
write_com(0X30);
delay_xms
(1);
write_com(0X30);
delay_xms
(1);
write_com(0X0C);
delay_xms
(1);
write_com(0X01);
delay_xms(15);
write_com(0X06);
delay_xms
(1);
}
/***************ADTRANSFER*********************/
/*------------------------------------------------
启动IIC总线
------------------------------------------------*/
voidstart(void)
{
Sda=1;
_nop_();
Scl=1;
_nop_();
Sda=0;
_nop_();
Scl=0;
}
/*------------------------------------------------
停止IIC总线
------------------------------------------------*/
voidstop(void)
{
Sda=0;
_nop_();
Scl=1;
_nop_();
Sda=1;
_nop_();
Scl=0;
}
/*------------------------------------------------
应答IIC总线
------------------------------------------------*/
voidack(void)
{
Sda=0;
_nop_();
Scl=1;
_nop_();
Scl=0;
_nop_();
}
/*------------------------------------------------
非应答IIC总线
------------------------------------------------*/
voidnoack(void)
{
Sda=1;
_nop_();
Scl=1;
_nop_();
Scl=0;
_nop_();
}
/*------------------------------------------------
发送一个字节
------------------------------------------------*/
voidsend(unsignedcharData)
{
unsignedcharBitCounter=8;
unsignedchartemp;
do
{
temp=Data;
Scl=0;
_nop_();
if((temp&0x80)==0x80)
Sda=1;
else
Sda=0;
Scl=1;
temp=Data<<1;
Data=temp;
BitCounter--;
}
while(BitCounter);
Scl=0;
}
/*------------------------------------------------
读入一个字节并返回
------------------------------------------------*/
unsignedcharread(void)
{
unsignedchartemp=0;
unsignedchartemp1=0;
unsignedcharBitCounter=8;
Sda=1;
do
{
Scl=0;
_nop_();
Scl=1;
_nop_();
if(Sda)
temp=temp|0x01;
else
temp=temp&0xfe;
if(BitCounter-1)
{
temp1=temp<<1;
temp=temp1;
}
BitCounter--;
}
while(BitCounter);
return(temp);
}
voiddisplay(longk)
{
unsignedinttemp;
unsignedlongintv;
v=3125*k;
v=v/2048;
temp=v/10000;
write_com(0x80);
write_date(0x30+temp);
temp=v/1000%10;
write_date(0x30+temp);
temp=v/100%10;
write_date(0x30+temp);
temp=v/10%10;
write_date(0x30+temp);
write_date(0x2e);
temp=v%10;
write_date(0x30+temp);
}
voidmain()
{
shortm,n;
longk;
init_12864();
while
(1)
{
start();
send(0x90);
ack();
send(0x8c);
ack();
stop();
start();
send(0x91);
ack();
m=read();
ack();
n=read();
noack();
stop();
k=(0x00ff&m)<<8|n;
display(k);
}
}