ad.c

来自「ucos-II2.51在S3C44B0X上的移植 开发环境:SDT2.50 」· C语言 代码 · 共 33 行

C
33
字号
/*
 *************************************************************************
 * Copyright (c) 2003, The Lab of Embedded System and Net Security,WHUT..
 * All rights reserved. 
 *
 * Filename:    ad.c
 * Discription: This file test ad converter.
 * 
 * version:            1.0
 * Author:             Qiu Yanfei <qyfhm@tom.com>
 * Accomplished Date:  2004/7/10 16:31:00
 *************************************************************************
*/
#include "..\cpu\44breg.h"

#include "ad.h"

void ad_init(void)
{
    rADCPSR = 20;           //sample rate 32 
    rADCCON = AD_SLEEP;     //enter sleep mode
}

U16 ad_convert(U8 line)
{    
    rADCCON = AD_ENABLE | (line<<2);       //Start A/D conversion
    
    while(rADCCON&AD_ENABLE);       //To avoid The first FLAG error case.
    
    while(!(rADCCON & AD_FLAG));    //Wait until conversion completed.
    
    return (U16)rADCDAT;
}

⌨️ 快捷键说明

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