These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!
EMAC/Easy_Web/ADC.c@0:bf7b9fba3924, 2011-03-20 (annotated)
- Committer:
- frank26080115
- Date:
- Sun Mar 20 05:38:56 2011 +0000
- Revision:
- 0:bf7b9fba3924
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
frank26080115 | 0:bf7b9fba3924 | 1 | /*---------------------------------------------------------------------------- |
frank26080115 | 0:bf7b9fba3924 | 2 | * Name: ADC.c |
frank26080115 | 0:bf7b9fba3924 | 3 | * Purpose: MCB1700 low level ADC functions |
frank26080115 | 0:bf7b9fba3924 | 4 | * Version: V1.00 |
frank26080115 | 0:bf7b9fba3924 | 5 | * Note(s): |
frank26080115 | 0:bf7b9fba3924 | 6 | *---------------------------------------------------------------------------- |
frank26080115 | 0:bf7b9fba3924 | 7 | * This file is part of the uVision/ARM development tools. |
frank26080115 | 0:bf7b9fba3924 | 8 | * This software may only be used under the terms of a valid, current, |
frank26080115 | 0:bf7b9fba3924 | 9 | * end user licence from KEIL for a compatible version of KEIL software |
frank26080115 | 0:bf7b9fba3924 | 10 | * development tools. Nothing else gives you the right to use this software. |
frank26080115 | 0:bf7b9fba3924 | 11 | * |
frank26080115 | 0:bf7b9fba3924 | 12 | * This software is supplied "AS IS" without warranties of any kind. |
frank26080115 | 0:bf7b9fba3924 | 13 | * |
frank26080115 | 0:bf7b9fba3924 | 14 | * Copyright (c) 2009 Keil - An ARM Company. All rights reserved. |
frank26080115 | 0:bf7b9fba3924 | 15 | *---------------------------------------------------------------------------- |
frank26080115 | 0:bf7b9fba3924 | 16 | * History: |
frank26080115 | 0:bf7b9fba3924 | 17 | * V1.00 Initial Version |
frank26080115 | 0:bf7b9fba3924 | 18 | *----------------------------------------------------------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 19 | |
frank26080115 | 0:bf7b9fba3924 | 20 | #include "LPC17xx.h" /* LPC17xx definitions */ |
frank26080115 | 0:bf7b9fba3924 | 21 | #include "ADC.h" |
frank26080115 | 0:bf7b9fba3924 | 22 | |
frank26080115 | 0:bf7b9fba3924 | 23 | /*---------------------------------------------------------------------------- |
frank26080115 | 0:bf7b9fba3924 | 24 | initialize ADC Pins |
frank26080115 | 0:bf7b9fba3924 | 25 | *----------------------------------------------------------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 26 | void ADC_init (void) { |
frank26080115 | 0:bf7b9fba3924 | 27 | #ifdef MCB_LPC_1768 |
frank26080115 | 0:bf7b9fba3924 | 28 | /* Using MCB1700 board : |
frank26080115 | 0:bf7b9fba3924 | 29 | * ADC channel 2 is available |
frank26080115 | 0:bf7b9fba3924 | 30 | */ |
frank26080115 | 0:bf7b9fba3924 | 31 | LPC_PINCON->PINSEL1 &= ~(3<<18); /* P0.25 is GPIO */ |
frank26080115 | 0:bf7b9fba3924 | 32 | LPC_PINCON->PINSEL1 |= (1<<18); /* P0.25 is AD0.2 */ |
frank26080115 | 0:bf7b9fba3924 | 33 | |
frank26080115 | 0:bf7b9fba3924 | 34 | LPC_SC->PCONP |= (1<<12); /* Enable power to ADC block */ |
frank26080115 | 0:bf7b9fba3924 | 35 | |
frank26080115 | 0:bf7b9fba3924 | 36 | LPC_ADC->ADCR = (1<< 2) | /* select AD0.2 pin */ |
frank26080115 | 0:bf7b9fba3924 | 37 | (1<< 8) | |
frank26080115 | 0:bf7b9fba3924 | 38 | (1<<21); /* enable ADC */ |
frank26080115 | 0:bf7b9fba3924 | 39 | #elif defined(IAR_LPC_1768) |
frank26080115 | 0:bf7b9fba3924 | 40 | /* Using IAR LPC1768 KickStart board |
frank26080115 | 0:bf7b9fba3924 | 41 | * ADC channel 5 is available |
frank26080115 | 0:bf7b9fba3924 | 42 | */ |
frank26080115 | 0:bf7b9fba3924 | 43 | LPC_PINCON->PINSEL3 |= (3<<30); /* P1.31 is AD0.5 */ |
frank26080115 | 0:bf7b9fba3924 | 44 | |
frank26080115 | 0:bf7b9fba3924 | 45 | LPC_SC->PCONP |= (1<<12); /* Enable power to ADC block */ |
frank26080115 | 0:bf7b9fba3924 | 46 | |
frank26080115 | 0:bf7b9fba3924 | 47 | LPC_ADC->ADCR = (1<<5) | /* select AD0.5 pin */ |
frank26080115 | 0:bf7b9fba3924 | 48 | (1<< 8) | |
frank26080115 | 0:bf7b9fba3924 | 49 | (1<<21); /* enable ADC */ |
frank26080115 | 0:bf7b9fba3924 | 50 | #endif |
frank26080115 | 0:bf7b9fba3924 | 51 | } |
frank26080115 | 0:bf7b9fba3924 | 52 | |
frank26080115 | 0:bf7b9fba3924 | 53 | |
frank26080115 | 0:bf7b9fba3924 | 54 | /*---------------------------------------------------------------------------- |
frank26080115 | 0:bf7b9fba3924 | 55 | start ADC Conversion |
frank26080115 | 0:bf7b9fba3924 | 56 | *----------------------------------------------------------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 57 | void ADC_startCnv (void) { |
frank26080115 | 0:bf7b9fba3924 | 58 | LPC_ADC->ADCR &= ~(7<<24); /* stop conversion */ |
frank26080115 | 0:bf7b9fba3924 | 59 | LPC_ADC->ADCR |= (1<<24); /* start conversion */ |
frank26080115 | 0:bf7b9fba3924 | 60 | } |
frank26080115 | 0:bf7b9fba3924 | 61 | |
frank26080115 | 0:bf7b9fba3924 | 62 | |
frank26080115 | 0:bf7b9fba3924 | 63 | /*---------------------------------------------------------------------------- |
frank26080115 | 0:bf7b9fba3924 | 64 | stop ADC Conversion |
frank26080115 | 0:bf7b9fba3924 | 65 | *----------------------------------------------------------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 66 | void ADC_stopCnv (void) { |
frank26080115 | 0:bf7b9fba3924 | 67 | LPC_ADC->ADCR &= ~(7<<24); /* stop conversion */ |
frank26080115 | 0:bf7b9fba3924 | 68 | } |
frank26080115 | 0:bf7b9fba3924 | 69 | |
frank26080115 | 0:bf7b9fba3924 | 70 | |
frank26080115 | 0:bf7b9fba3924 | 71 | /*---------------------------------------------------------------------------- |
frank26080115 | 0:bf7b9fba3924 | 72 | get converted ADC value |
frank26080115 | 0:bf7b9fba3924 | 73 | *----------------------------------------------------------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 74 | uint32_t ADC_getCnv (void) { |
frank26080115 | 0:bf7b9fba3924 | 75 | uint32_t adGdr; |
frank26080115 | 0:bf7b9fba3924 | 76 | |
frank26080115 | 0:bf7b9fba3924 | 77 | while (!(LPC_ADC->ADGDR & (1UL<<31))); /* Wait for Conversion end */ |
frank26080115 | 0:bf7b9fba3924 | 78 | adGdr = LPC_ADC->ADGDR; |
frank26080115 | 0:bf7b9fba3924 | 79 | return((adGdr >> 4) & ADC_VALUE_MAX); /* read converted value */ |
frank26080115 | 0:bf7b9fba3924 | 80 | } |