标签:class blog code ext 2014 name
//========c51adc.h=============================================
#ifndef _C51ADC_H_
#define _C51ADC_H_
//ADC通道号定义
#define ADC_Chanel0 (0x00<<1)
#define ADC_Chanel1 (0x01<<1)
#define ADC_Chanel2 (0x02<<1)
#define ADC_Chanel3 (0x03<<1)
#define ADC_Chanel4 (0x04<<1)
#define ADC_Chanel5 (0x05<<1)
#define ADC_Chanel6 (0x06<<1)
#define ADC_Chanel7 (0x07<<1)
//AD通道使能
//#define ADC_CHANEL_ENABLE(Chanel) ADC_CSR = (ADC_CSR & 0XF0)|Chanel ;
extern void Init_AD(void) ;
extern void AdcSwitch(uint8 Chanel);
#endif
//========c51adc.c==============================================
#include "global.h"
#include "c51adc.h"
//*************************************
// 函数名称:Init_AD
// 函数功能:对AD初始化,开启或关闭ADC电路
// 入口参数:
// 出口参数:无
/***************************************/
void Init_AD(void)
{
// 0 1 2 3 4 5 6 7 对应转换时钟为
//Fsys/2 /4 /6 /8 /12 /16 /24 /32
Bank0;
ADCON = 0X80 ; //打开ADC模块
ADT = 0 ;
ADT |= (2<<5) ; //Fsys/6 转换时钟
ADT |= 5 ; //采样时间设置 0-15
}
//*************************************
// 函数名称:AdcSwitch
// 函数功能: 在单通道模式下转换某一通道的AD值
// 在(扫描模式下)连续转化1-Chanel的AD值
// 入口参数:要转换的AD通道号
// 出口参数:无
//***************************************
void AdcSwitch(uint8 Chanel)
{
Bank0;
ADCON = 0x80 | Chanel ; //选择通道
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
ADCON |= 0x01 ; //开始转换AD
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
while(ADCON & 0x01); //等待转换结束
return ;
}中颖SH79F1616 ADC初始化程序,布布扣,bubuko.com
标签:class blog code ext 2014 name
原文地址:http://blog.csdn.net/libiaojs/article/details/29411901