📄 ad.c
字号:
/*
*******************************************************************************
**
** This device driver was created by Applilet for the 78K0/KB2, 78K0/KC2,
** 78K0/KD2, 78K0/KE2 and 78K0/KF2 8-Bit Single-Chip Microcontrollers.
**
** Copyright(C) NEC Electronics Corporation 2002 - 2005
** All rights reserved by NEC Electronics Corporation.
**
** This program should be used on your own responsibility.
** NEC Electronics Corporation assumes no responsibility for any losses
** incurred by customers or third parties arising from the use of this file.
**
** Filename : ad.c
** Abstract : This file implements device driver for AD module.
** APIlib : NEC78K0KX2.lib V1.01 [09 Aug. 2005]
**
** Device : uPD78F0513(44-pin)
**
** Compiler : NEC/CC78K0
**
*******************************************************************************
*/
/*
*******************************************************************************
** Include files
*******************************************************************************
*/
#include "macrodriver.h"
#include "ad.h"
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function initializes A/D module.
**
** Parameters:
** None
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
void AD_Init( void )
{
ADPC = AD_ADPC;
ADS = AD_ADS;
ClrIORBit(ADM, 0x02); /* 2.7V<=AVref<=5.5V */
ADM = ADM & AD_ADM;
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function starts the A/D converter.
**
** Parameters:
** None
**
** Returns:
** MD_OK
**
**-----------------------------------------------------------------------------
*/
MD_STATUS AD_Start( void )
{
int delay = 200;
SetIORBit(ADM, 0x01); /* comparator operation */
while(delay--);
SetIORBit(ADM, 0x80);
return MD_OK;
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function can be called after an A/D conversion is completed,
** and returns the conversion result(s) in the buffer.
**
** Parameters:
** buffer The address where to write the conversion result.
**
** Returns:
** MD_OK
**
**-----------------------------------------------------------------------------
*/
MD_STATUS AD_Read( USHORT* buffer )
{
*buffer = (USHORT)( ADCR >> 6 );
return MD_OK;
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function stops the A/D converter.
**
** Parameters:
** None
**
** Returns:
** MD_OK
**
**-----------------------------------------------------------------------------
*/
MD_STATUS AD_Stop( void )
{
ClrIORBit(ADM, 0x81);
return MD_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -