tlc1543.c

来自「8051单片机访问外围器件的代码」· C语言 代码 · 共 54 行

C
54
字号
/**
 * @file
 * Driver of ADC chip TLC1543
 * 
 * TLC1543.c
 * Copyright(C) 2007 Agate Logic Corporation. All rights reserved.
 * This file is licensed under the terms of Agate Logic SDK License Agreement.
 * 
 * @author bxu@agatelogic.com.cn
*/

#define TLC1543_GLOBALS	///< define macro "TLC1543_GLOBALS" as empty
#include "tlc1543.h"

/**
 * @brief Initialize the interface of ADC chip.
 * 
 * The Function set the clock division register and initialize the interface of ADC chip.
 * 
 * @param clkdiv The clock division value to set.
 * 
 * @return N/A
*/
void	init_tlc1543(uchar clkdiv)
{
	TLC1543_CLKDIV = clkdiv;
}

/**
 * @brief Read the adc result of ADC chip at the specified channel.
 * 
 * The Function start a adc acquirement at the specified channel and then read back the ad convert result.
 * 
 * @param nextchannel The AD channel to acquire.
 * 
 * @return N/A
*/
uint	read_tlc1543(uchar nextchannel)
{
	uint ad_result=0;
	nextchannel&=0x0f;//set channel
	nextchannel|=0x80;//start ad acq
	TLC1543_CONTROL=nextchannel;
	do
	{
		nextchannel=TLC1543_CONTROL;
		ad_result++;
	}
	while(((nextchannel&0x40)==0x00)&&ad_result<1000);
	ad_result = TLC1543_DATAH & 0x03;
	ad_result <<= 8;
	ad_result += TLC1543_DATAL;
	return ad_result;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?