adc.c
来自「最新版IAR FOR ARM(EWARM)5.11中的代码例子」· C语言 代码 · 共 76 行
C
76 行
/*************************************************************************
*
* Used with ICCARM and AARM.
*
* (c) Copyright IAR Systems 2007
*
* File name : adc.c
* Description : Main file
*
* History :
* 1. Date : August 2, 2007
* Author : Stanimir Bonev
* Description : Create
*
* This example project shows how to use the IAR Embedded Workbench for ARM
* to develop code for the Samsung-S3F4A0K evaluation board. It shows
* basic use of I/O and ADC.
* It printing all ADC channels voltage in IO windows
*
* Jumpers:
* All jumpers are in default position regarding board's manual
*
* $Revision: 18083 $
**************************************************************************/
#include <samsung\ios3f4a0k.h>
#include <stdio.h>
#include "arm_comm.h"
#include "board.h"
/*************************************************************************
* Function Name: main
* Parameters: none
* Return: none
*
* Description: Main
*
*************************************************************************/
void main (void)
{
Flo32 Tmp;
// Configure I/Os for analog functions - ANAIN0 to ANAIN15
IOCONF_MR11_bit.PIO3_0_F3EN = IOCONF_MR11_bit.PIO3_1_F3EN =\
IOCONF_MR11_bit.PIO3_2_F3EN = IOCONF_MR11_bit.PIO3_3_F3EN =\
IOCONF_MR11_bit.PIO3_4_F3EN = IOCONF_MR11_bit.PIO3_5_F3EN =\
IOCONF_MR11_bit.PIO3_6_F3EN = IOCONF_MR11_bit.PIO3_7_F3EN =\
IOCONF_MR12_bit.PIO3_8_F3EN = IOCONF_MR12_bit.PIO3_9_F3EN =\
IOCONF_MR12_bit.PIO3_10_F3EN = IOCONF_MR12_bit.PIO3_11_F3EN =\
IOCONF_MR12_bit.PIO3_12_F3EN = IOCONF_MR12_bit.PIO3_13_F3EN =\
IOCONF_MR12_bit.PIO3_14_F3EN = IOCONF_MR12_bit.PIO3_15_F3EN = 1;
// Initialize ADC - Max. ADC clock = 2.5MHz
ADC_ECR = 1<<1; // enable ADC clock
ADC_CR = 1; // software reset
ADC_MR_bit.PRLVAL = 8; // ADC_CLK <= 2.5MHz
ADC_MR_bit.IES = 0; // Internal start
ADC_MR_bit.NBRCH = 0; // 1 conversion
ADC_MR_bit.CONTCV = 0; // no continuous conversion
ADC_CR = 1<<1; // ADC enable
for(Int32U i = 0; i < 16; ++i)
{
// Set channel to convert
ADC_CMR0_bit.CV1 = i;
// Wait for ADC ready
while(!ADC_SR_bit.READY);
// Start conversion
ADC_CR = 1<<3;
// Wait for end of conversion
while(!ADC_SR_bit.EOC);
// Printing result
Tmp = ADC_DR;
printf("Ch %d - %.2f mV\n",i,Tmp*5000.0/1024.0);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?