AD7705应用 C51源程序
#include
#include
#include
#include
sbit Number_BIT0 = P2^7;
sbit Number_BIT1 = P2^6;
sbit Number_BIT2 = P2^5;
sbit Number_BIT3 = P2^4;
sbit BUZZER = P2^3;
sbit AD7705_DATA=P3^0; // AD7705 input & output data
sbit AD7705_CLK=P3^1; // AD7705 CLK
sbit AD7705_DRDY=P1^2; // AD7705 data ready
sbit AD7705_CS =P1^3; // AD7705 CS
unsigned char Counter,dis_index,dis_digit;
unsigned intT_Voltage;
unsigned char MSB_Data,LSB_Data,temp0,temp1,temp2,temp3,temp4,temp5;
unsigned char code Display_code[11]=
//{0xa0,0xF9,0xc4,0xd0,0x99,0x92,0x82,0xF8,0x80,0x90,0xFF,};
{0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xFF};
void Delayms(unsigned char ms);
void AD7705_Start();
void AD7705_Read ();
void AD7705_Write_Reg(unsigned char Data_byte);
unsigned char AD7705_Read_Reg();
main()
{
TMOD = 0x11;
IT0 = 1;
PCON=0X00;
ET0 = 1;
TH1 = 0xFC;
TL1 = 0x17;
TR0 = 1;
EA = 1;
P0 = 0xff;P1 = 0xff;P2 = 0xf7;P3 = 0xff;
dis_digit = 0x77;
dis_index = 0;
Counter = 0;
AD7705_Start();
while(1)
{
while(AD7705_DRDY);
AD7705_Read();
Delayms(50);
}
}
void Delayms(unsigned char ms)
// relay ms
{unsigned char i;
while(ms--)
{
for(i = 0; i < 120; i++);
}
}
void AD7705_Start()
{
AD7705_Write_Reg(0x20);
AD7705_Write_Reg(0x0c);
AD7705_Write_Reg(0x10);
AD7705_Write_Reg(0x44);
}
void AD7705_Read()
{
AD7705_Write_Reg(0x38);
MSB_Data = AD7705_Read_Reg();
LSB_Data = AD7705_Read_Reg();
T_Voltage =(unsinged int)MSB_Data;
T_Voltage = T_Voltage<8;
T_Voltage = T_Voltage| (unsigned int)LSB_Data;
temp0 = T_Voltage/100000;
temp1 = ((T_Voltage-temp0*100000)/10000);
temp2 = ((T_Voltage-temp0*100000-temp1*10000)/1000);
temp3 = ((T_Voltage-temp0*100000-temp1*10000-temp2*1000)/100);
temp4 = (T_Voltage-temp0*100000-temp1*10000-temp2*1000-temp3*100)/10;
temp5 = (T_Voltage-temp0*100000-temp1*10000-temp2*1000-temp3*100-temp4*10);
}
void AD7705_Write_Reg(unsigned char Data_byte)
{
unsigned char i;
AD7705_CS = 0;
AD7705_CLK = 1;
_nop_();
_nop_();
for(i = 0; i < 8; i++)
{
AD7705_DATA = (bit)(Data_byte & 0x80);
AD7705_CLK = 0;
_nop_();
_nop_();
_nop_();
AD7705_CLK = 1;
Data_byte <= 1;
}
_nop_();
AD7705_CS = 1;
}
unsigned char AD7705_Read_Reg()
{
unsigned char i,Data_read;
AD7705_CS = 0;
AD7705_CLK = 1;
_nop_();
for(i = 0; i < 8; i++)
{
AD7705_CLK = 0;
_nop_();
_nop_();
Data_read <= 1;
Data_read |= (unsigned char)AD7705_DATA;
_nop_();
_nop_();
AD7705_CLK = 1;
_nop_();
_nop_();
}
_nop_();
AD7705_CS = 1;
AD7705_DRDY = 1;
return(Data_read);
}
void time0(void) interrupt 1
{
TR0 = 0;
P2 = dis_digit; //P2.7 --DS8
P0 = Display_code[dis_index];
TH0 = 0xFC;
TL0 = 0x17;
Counter++;
if(Counter==1)
{
dis_digit = 0x77;
dis_index = temp5;
}else if(Counter==2)
{
dis_digit = 0xb7;
dis_index = temp4;
}else if(Counter==3)
{
dis_digit = 0xd7;
dis_index = temp3;
}else if(Counter==4)
{
dis_digit = 0xe7;
dis_index = temp2;
Counter = 0;
}
TR0 = 1;
}
AD7705C51源程 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)