TLC2543电压检测
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include
#include
#include
unsigned char data dispdata[3]={8,8,8};
unsigned char code disptab[]={0x80,0x40,0x20,0x20,x02,0x08,0x40,0x04};
unsigned char code xtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7 f,0x6f};
unsigned int data jzt;
sbit oe=P3^1;
sbit adcs=P2^0;
sbit adclk=P2^3;
sbit adin=P2^2;
sbit adout=P2^1;
//unsigned int data xin;
unsigned char data i;
void delay(int z)
{
int i,j;
for(i=z;i>0;i--)
for(j=124;j>0;j--);
}
unsigned int read_ad(unsigned char anx) {
unsigned int ad_v;
unsigned char an,i,j;
anx=anx<<4;
adclk=0;
adcs=1;
adcs=0;
for(i=0;i<1;i++)
{
an=anx;
ad_v=0;
for(j=0;j<12;j++)
{
adin=an&0x80;
an=an<<1;
adclk=1;
ad_v=ad_v<<1;
ACC=adout;
ad_v+=ACC;
adclk=0;
}
}
return(ad_v);
}
int adcj(unsigned char tdh)
{
unsigned int jg,sum=0,admin,admax; unsigned char i;
for(i=0;i<10;i++)
{
EA=0;
jg=read_ad(tdh);
EA=1;
sum+=jg;
if(i==0)
{
admin=jg;
admax=jg;
}
else
{
if(jg>admax)admax=jg;
if(jg } } sum=(sum-admin-admax)/8; return(sum); } void chaifen(unsigned int xin) { dispdata[0]=xin/100; dispdata[1]=xin%100/10; dispdata[2]=xin%10; } void display(void) interrupt 3 { oe=0; P0=xtab[dispdata[i]]; P2=P2&0x1f; P2=P2|disptab[i]; i++; jzt++; i%=3; if(i==1) { P0=xtab[dispdata[i]]|0X80;//小数点 } TH1=0xf7; TL1=0x30; TR1=1; } main() { unsigned int ad,ad0,u; double k=10.0/163.0;//k=5/(ad5-ad0); k=k*10; TH1=0xf8; TL1=0x30; TR1=1; TMOD =0x11; SP=0xd0; EA=1; ET1=1; oe=0; while(1) { ad=adcj(0x06); u=(ad-ad0)*k; chaifen(u); } }