三通道12位模数转换MAX1241串口传输单片机C程序
#include
#define uchar unsigned char
#define uint unsigned int
#define High 1
#define Low0
int t1,t2,t3,t4,t5,t6,t7,t11,t12,t21,t22,t31,t32;
int t;
sbit cs=P2^7;
sbit sclk=P2^6;
sbit dout=P2^5;
sbit cs2=P2^4;
sbit sclk2=P2^3;
sbit dout2=P2^2;
sbit cs3=P2^1;
sbit sclk3=P2^0;
sbit dout3=P0^7;
uint dushuju() //定义为可以返回的参数
{
uint voltage_temp=0;
uchar ucloop=12;
cs=High;
sclk=Low;
cs=Low;
while(dout==0);//EOC信号为高表示转换结束
sclk=High;
sclk=Low;
while(ucloop--)
{
sclk=High;//上升沿数据稳定并读出
voltage_temp<=1;
if(dout==1)
voltage_temp+=1;
sclk=Low;
}
cs=High;
return voltage_temp; //返回数据
}
uint dushuju2() //定义为可以返回的参数
{
uint voltage_temp2=0;
uchar ucloop=12;
cs2=High;
sclk2=Low;
cs2=Low;
while(dout2==0);//EOC信号为高表示转换结束
sclk2=High;
sclk2=Low;
while(ucloop--)
{
sclk2=High;//上升沿数据稳定并读出
voltage_temp2<=1;
if(dout2==1)
voltage_temp2+=1;
sclk2=Low;
}
cs2=High;
return voltage_temp2; //返回数据
}
uint dushuju3() //定义为可以返回的参数
{
uint voltage_temp3=0;
uchar ucloop=12;
cs3=High;
sclk3=Low;
cs3=Low;
while(dout3==0);//EOC信号为高表示转换结束
sclk3=High;
sclk3=Low;
while(ucloop--)
{
sclk3=High;//上升沿数据稳定并读出
voltage_temp3<=1;
if(dout3==1)
voltage_temp3+=1;
sclk3=Low;
}
cs3=High;
return voltage_temp3; //返回数据
}
uint dushuju4() //定义为可以返回的参数
{
uint voltage_temp4=0;
uchar ucloop=12;
cs=High;
sclk=Low;
cs=Low;
while(dout==0);//EOC信号为高表示转换结束
sclk=High;
sclk=Low;
while(ucloop--)
{
sclk=High;//上升沿数据稳定并读出
voltage_temp4<=1;
if(dout==1)
voltage_temp4+=1;
sclk=Low;
}
cs=High;
return voltage_temp4; //返回数据
}
void shuju(void)
{
t4=dushuju();
t5=dushuju2();
t6=dushuju3();
t12=t4%256;//将数据转换为高8位和低8位
t11=t4/256%256;
t22=t5%256;
t21=t5/256%256;
t32=t6%256;
t31=t6/256%256;
}
void shujul(void)
{
t7=dushuju4();
}
void csh(void)
{
SM0=0;
SM1=1;
REN=1;
TI=0;
RI=0;
PCON=0;
TH1=0xF3;
TL1=0XF3;
TMOD=0X20;
EA=1;
ET1=0;
ES=1;
TR1=1;
TI=0;
SBUF=1;
while(!TI);
TI=0;
SBUF=t11;
while(!TI);
TI=0;
SBUF=t12;
while(!TI);
TI=0;
SBUF=2;
while(!TI);
TI=0;
SBUF=t21;
while(!TI);
TI=0;
SBUF=t22;
while(!TI);
TI=0;
SBUF=3;
while(!TI);
TI=0;
SBUF=t31;
while(!TI);
TI=0;
SBUF=t32;
while(!TI);
TI=0;
}
void main(void)
{
shuju();
csh();
loop:
shujul();
if ((t7-t4)>=10)
{
shuju();
csh();
goto loop ;
}
else
goto loop ;
}
三通道模数转换MAX1241串口传 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)