adc0832 C Program

Publisher:科技驿站Latest update time:2013-12-05 Keywords:adc0832 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

ADC0832 is an 8-bit resolution, dual-channel A/D conversion chip produced by National Semiconductor Corporation
. It is popular among microcontroller enthusiasts and enterprises due to its small size, strong compatibility and high cost performance
. It has a high penetration rate. Learning and using ADC0832 can help us understand the principle of A/D converter
and help improve our microcontroller technology level.

adc0832 C Program

//============================================
//2005-03-28...2005-03-29
//C51 program source file of ADC0834 module
//File Name=ADC083X.c
//#include 
#include "DELAY_S.h"
#include "ADC083X.h"

//Predefine external global variables

//***********************************************************
//Serial number:
// HD_ADC083X_S01
//Function: 
// Port initialization
//Input: 
// None
//Output: 
// None
//********************************************************
void adc083x_init(void)
{
SET_ADC083X_CS;
SET_ADC083X_DO;
CLR_ADC083X_CLK;

#if TYPE_VAL >=ADC0832
SET_ADC083X_DI;
#endif

#if TYPE_VAL >=ADC0834
SET_ADC083X_SARS;
#endif

}

//*******************************************************
//Serial number:
// HD_ADC083X_S02
//Function: 
// Read out AD data byte
//Input: 
// chanel channel number and single-ended or double-ended setting selection, its value is limited by type value!
// That is, the valid value is select to take the lowest 4, 3, 2 bits or not use
// For specific values, please refer to the pdf document!
//Output: 
// Result byte of AD conversion
//********************************************************
uchar adc083x_do_one_change(uchar chanel)
{
uchar data ad_val;
uchar data i;

//Initialization before conversion
SET_ADC083X_CS;
CLR_ADC083X_CLK;
SET_ADC083X_DO;

CLR_ADC083X_CS;

//SARS pins can be unused when not necessary to save pin resources!
#if (TYPE_VAL==ADC0838)
//chanel_.3 .2 .1 .0 =0000 channel 0+_channel 1-, 
=001 channel 2+_channel 3-,(dual-ended mode)
// SGL/DIF ODD/SIGN SELECT SELECT =0010 channel 4+_channel 5-, 
=011 channel 6+_channel 7-,(dual-ended mode)
// =0100 channel 0-_channel 1+, 
=0101 channel 2-_channel 3+,(dual-ended mode)
// =0110 channel 4-_channel 5+, 
=0111 channel 6-_channel 7+,(dual-ended mode)
// =1000 channel 0+, =1001 
channel 2+,(single-ended mode)
// =1010 channel 4+, =1011 
channel 6+,(single-ended mode)
// =1100 channel 1+, =1101 
channel 3+, (single-ended mode)
// =1110 channel 5+, =1111 
channel 7+, (single-ended mode)
//Pin /SE can be grounded and its output delay function of controlling the response byte is not used!

chanel |=0x10; //附加起始位
for(i=0; i<5; i++)
{
if( (chanel &0x10)!=0)
{
SET_ADC083X_DI;
}
else
{
CLR_ADC083X_DI;
}
SET_ADC083X_CLK;
CLR_ADC083X_CLK;
chanel <<=1;
}

#elif (TYPE_VAL==ADC0834)
//chanel_.2.1.0 =000 Channel 0+_Channel 1-, =001 Channel 2+
_Channel 3-, (dual-ended mode)
// SGL/DIF ODD/SIGN SELECT =010 Channel 0-_Channel 1+, =011 Channel 2-
_Channel 3+, (dual-ended mode)
// =100 Channel 0+, =101 Channel 2+,
(single-ended mode)
// =110 Channel 1+, =111 Channel 3+,
(single-ended mode)

chanel |=0x08; //附加起始位
for(i=0; i<4; i++)
{
if( (chanel &0x08)!=0)
{
SET_ADC083X_DI;
}
else
{
CLR_ADC083X_DI;
}
SET_ADC083X_CLK;
CLR_ADC083X_CLK;
chanel <<=1;
}

#elif (TYPE_VAL==ADC0832)
//chanel_.1.0 =00 channel 0+_channel 1-, =01 channel 0-_channel
1+, (dual-ended mode)
// SGL/DIF ODD/SIGN =10 channel 0+, =11 channel 1+, 
(single-ended mode)

chanel |=0x04; //附加起始位
for(i=0; i<3; i++)
{
if( (chanel &0x04)!=0)
{
SET_ADC083X_DI;
}
else
{
CLR_ADC083X_DI;
}
SET_ADC083X_CLK;
CLR_ADC083X_CLK;
chanel <<=1;
}

#else //Default is ADC0831

SET_ADC083X_CLK;
CLR_ADC083X_CLK;

#endif

SET_ADC083X_CLK; //Conversion bit before data reception
CLR_ADC083X_CLK;

for(ad_val=0, i=0; i<8; i++)
{
ad_val <<=1;
SET_ADC083X_CLK;
ad_val +=(JUDGE_ADC083X_DO ==1? 1:0);
CLR_ADC083X_CLK;

//For non-ADC0831 models, the subsequent waveforms are not used!

SET_ADC083X_CS;
return(ad_val);
}

//===================================
//End Of File

ADC0832 is an 8-bit resolution A/D conversion chip with a maximum resolution of 256 levels, which can meet
general analog conversion requirements. The multiplexing of its internal power input and reference voltage makes the analog
voltage input of the chip between 0 and 5V. The chip conversion time is only 32μS. It has dual data outputs that can be used as data
verification to reduce data errors. It has fast conversion speed and strong stability. Independent chip enable input makes multi-device connection and processor control more convenient. Through the DI data input terminal, the channel function selection
can be easily realized .

Keywords:adc0832 Reference address:adc0832 C Program

Previous article:Energy-efficient stepper motor driver solutions for office automation equipment applications
Next article:AD9851 schematic diagram and pin functions

Latest Analog Electronics Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号