?? ad.c
字號:
/*""FILE COMMENT""*****************************************************
* M32R C Programming Rev. 1.00
* < Sample Program for AD converter >
*
* Copyright (c) 2003 Renesas Technology Corporation
* And Renesas Solutions Corporation
* All Rights Reserved
*********************************************************************/
/************************************************************************/
/* Include file */
/************************************************************************/
#include "..\inc\sfr32170_pragma.h"
/************************************************************************/
/* Function prototype declaration */
/************************************************************************/
unsigned short AD0exe( unsigned char ); /* Execute AD conversion */
/************************************************************************/
/* Define macro */
/************************************************************************/
/* 0123 4567 */
#define ADSIM0_ini (unsigned char)0x01 /* 0000 0001B */
/* |||| |||+---- AD conversion start */
/* |||| ||+----- No operation */
/* |||| |+------ don't care */
/* |||| +------- No DMA transfer request */
/* ||++--------- Software trigger */
/* ++----------- don't care */
/* 0123 4567 */
#define ADSIM1_ini (unsigned char)0x40 /* 0100 0000B */
/* |||| ++++---- AD0 selected */
/* |||+--------- don't care */
/* ||+---------- Analog extension unused */
/* |+----------- Double speed */
/* +------------ AD conversion mode */
/*""FUNC COMMENT""*******************************************************
* Function name: AD0exe()
*-----------------------------------------------------------------------
* Description : AD conversion using AD0
* : - Executes AD conversion on the channel specified with
* : the argument and returns the conversion result
*-----------------------------------------------------------------------
* Argument : unsigned char AD0ch AD0 converter channel number on which to convert
*-----------------------------------------------------------------------
* Returns : 10-bit AD conversion result
*-----------------------------------------------------------------------
* Notes : - Only the 4 low-order bits of the channel number are used
* : - More than 1 cycle of wait time (dummy wait cycles) is
* : required when starting AD conversion and reading out
* : the AD conversion-finished bit
* : - Wait until AD conversion finishes
*""FUNC COMMENT END""***************************************************/
unsigned short AD0exe( unsigned char AD0ch)
{
unsigned long j;
unsigned short *AdDtPtr;
AD0ch &= 0x0f; /* Use only the 4 low-order bits of channel number */
AdDtPtr = (unsigned short *)&AD0DT0; /* Start address of AD0 conversion result register */
AD0SIM1 = ADSIM1_ini | AD0ch; /* Select single mode and channel */
AD0SIM0 = ADSIM0_ini; /* Start AD conversion */
for( j = 0; j < 1; j++); /* Dummy wait cycle until reading out the AD conversion-finished bit */
while( !( AD0SIM0 & AD0SCMP)); /* Wait until AD conversion finishes */
return( *(AdDtPtr + AD0ch)); /* Read out conversion result */
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -