ADC5513
一 C5513
u32 ADC5513_GetValue(void)
{
u32 ADValue,i;
bool data_bit = false;
C5513_SCK=0;
C5513_CS=0;
if(GPIO_BitRead(C5513_SDO)==0u)
{
for (i = 0; i < 24; i++)
{
C5513_SCK = 1;
data_bit = GPIO_BitRead(C5513_SDO);
C5513_SCK=0;
ADValue <<= 1;
if(data_bit > 0)
{
ADValue|=0x00000001;
}
else
{
ADValue&=~0x00000001;
}
}
ADValue &=~(1<<20) ;/*有效位数为19位*/
Vout=ADValue*2.0*10000/2^19 /*有效电压是2.0,不是2.5V因为内部放大了0.8倍*/
return ADValue;
}
else
{
return (0xffffffff);
}
}
- #include <reg52.h>
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit ADCS=P2^0;
- sbit ADCLK=P2^1;
- sbit ADDO=P2^2;
- unsigned long int ADConv(void)
- {
- uchar i;
- unsigned long int Result=0;
- ADCLK=0;
- ADCS=0;
- _nop_();
- _nop_();
- _nop_();
- ADCLK=0;
- while(ADDO);
- ADCLK=1;
- _nop_();
- for(i=0;i<3;i++){
- ADCLK=0;
- _nop_();
- ADCLK=1;
- }
- for (i=0;i<20;i++){
- ADCLK=0;
- Result=Result<<1;
- if (ADDO)
- Result=Result+1;
- ADCLK=1;
- }
- ADCS=1;
- Result &=~(1<<20) ;/*有效位数为19位*/
- Vout=Result*2.0*10000/2^19 /*有效电压是2.0,不是2.5V因为内部放大了0.8倍*/
- return Result;
- }