/*----File Description----
- File Name : TLC5615.H
- Functions : 初使化:TLC1543_init(void)
读ADC :uint16 ReadADC_TLC1543(uchar ain)
- Description : 先调用初使化函数,再调用读ADC函数,形参ain
为模拟通道,其值为 0 ~ 10. 注意:返回值为
上一次转换结果。
- Author : Mason 别名:小菜
- Create Date : 2013/7/26
- Performance : Finished
- Global Variable : None
- File static Variable : None
- -------------------------------------------
- Revision History
- No. Date Revised by Item Description
-
-------------------------------------------------------------------------*/
/*----------------------------Head---------------------------------------*/
#include <reg52.h>
#include "TLC1543.h"
#include "MICRO.h"
#include "delay.h"
/*----------------------------Code---------------------------------------*/
void TLC1543_init(void)
{
CS_1543 = 1;
SCLK_1543 = 0;
}
/*----Important Function Description----
- Function Name : uint16 ReadADC_TLC1543(uchar ain)
- Description : None
- Author : Mason 别名:小菜
- Create Date : 2013/7/27
- Parameters/Arguments : uchar ain :下一次转换选通的ADC通道。
- Return Code : uint16 adc_value:上一次ADC转换的结果。
- Global Variable : None
- static Variable : None
- -------------------------------------------
- Revision History
- No. Date Revised by Item Description
-
-------------------------------------------------------------------------*/
uint16 ReadADC_TLC1543(uchar ain)
{
uchar temp;
uint16 adc_value = 0;
ain <<= 4;
CS_1543 = 0;
for(temp = 0;temp < 10;temp ++) // 将判断语句改为 temp<12
{ // 程序可移殖至 TLC2543.
adc_value <<= 1;
ain <<= 1;
ADDR_1543 = CY;
if(DOUT_1543) adc_value += 1;
SCLK_1543 = 1;
delayus(1);
SCLK_1543 = 0;
}
CS_1543 = 1;
return adc_value;
}
/*TLC2543驱动程序(dhd0)*/
/**************************************
TLC2543驱动程序
*************************************/
#include <reg51.h>
#include <intrins.h>
/**************************************
2543控制引脚宏定义
*************************************/
#define CLOCK p17 /*2543时钟*/
#define D_IN p16 /*2543输入*/
#define D_OUT p14 /*2543输出*/
#define _CS p15 /*2543片选*/
#define uint unsigned int
#define uchar unsigned char
/**************************************
名称:delay
功能:延时模块
输入参数:n要延时的周期数
输出参数:无
*************************************/
void delay(uchar n)
{
uchar i;
for(i=0;i<n;i++)
{
_nop_();
}
}
/**************************************
名称:read2543
功能:TLC2543驱动模块
输入参数:port通道号
输出参数:ad转换值
*************************************/
uint read2543(uchar port)
{
uint ad=0,i;
CLOCK=0;
_CS=0;
port<<=4;
for(i=0;i<12;i++)
{
if(D_OUT) ad|=0x01;
D_IN=(bit)(port&0x80);
CLOCK=1;
delay(3);
CLOCK=0;
delay(3);
port<<=1;
ad<<=1;
}
_CS=1;
ad>>=1;
return(ad);
}
/**************************************
名称:main
功能:主函数
输入参数:无
输出参数:无
*************************************/
void main()
{uint ad;
while(1)
{
ad=read2543(0);
}
}