www.pudn.com > TLC549_89C52.rar > TLC549.c, change:2009-08-03,size:971b


/*************************************** 
 *TLC549串行数字电压表 
 *************************************** 
*/ 
#include<reg52.h> 
#include<absacc.h> 
#include"Adc_Temp.h" 
 
extern uchar DispBuf[8]; 
 
//定义TLC549的操作接口 
sbit CS=P3^3; 
sbit CLK=P3^4; 
sbit DAT=P3^5; 
 
unsigned char ReadAdc(); 
void AdcInit(); 
void DispVol(unsigned char v); 
 
unsigned char ReadAdc() 
{ 
 unsigned char d; 
 unsigned char n; 
 
 d=0; 
 CS=0; 
 n=5; 
 while(--n!=0);   //延时约大于1.4us 
 if(DAT) d=1; 
  
 for(n=1;n<=7;n++) 
 { 
  CLK=1; 
  CLK=0; 
  d<<=1; 
  if(DAT) d++; 
 } 
 
 CLK=1; 
 CLK=0; 
 CS=1; 
 return d; 
} 
 
void AdcInit() 
{ 
 CS=1; 
 CLK=0; 
 DAT=1; 
 ReadAdc(); 
} 
 
void DispVol(unsigned char v) 
{ 
 unsigned char x100,x10,x;   //临时变量 
 v=v*250/256;                //2.5v电压 
  
 x100=v/100;            //整数部分转换成显示数字 
 DispBuf[2]=x100; 
 x10=(v-x100*100)/10; 
 DispBuf[1]=x10; 
 x=(v-x100*100)%10; 
 DispBuf[0]=x; 
 
 DispBuf[2]|=0x80; 
}