These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!
DAC/Speaker/dac_speaker.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 | * @file dac_speaker.c |
frank26080115 | 0:bf7b9fba3924 | 3 | * @purpose This example used to test DAC peripheral through speaker |
frank26080115 | 0:bf7b9fba3924 | 4 | * @version 2.0 |
frank26080115 | 0:bf7b9fba3924 | 5 | * @date 21. May. 2010 |
frank26080115 | 0:bf7b9fba3924 | 6 | * @author NXP MCU SW Application Team |
frank26080115 | 0:bf7b9fba3924 | 7 | *--------------------------------------------------------------------- |
frank26080115 | 0:bf7b9fba3924 | 8 | * Software that is described herein is for illustrative purposes only |
frank26080115 | 0:bf7b9fba3924 | 9 | * which provides customers with programming information regarding the |
frank26080115 | 0:bf7b9fba3924 | 10 | * products. This software is supplied "AS IS" without any warranties. |
frank26080115 | 0:bf7b9fba3924 | 11 | * NXP Semiconductors assumes no responsibility or liability for the |
frank26080115 | 0:bf7b9fba3924 | 12 | * use of the software, conveys no license or title under any patent, |
frank26080115 | 0:bf7b9fba3924 | 13 | * copyright, or mask work right to the product. NXP Semiconductors |
frank26080115 | 0:bf7b9fba3924 | 14 | * reserves the right to make changes in the software without |
frank26080115 | 0:bf7b9fba3924 | 15 | * notification. NXP Semiconductors also make no representation or |
frank26080115 | 0:bf7b9fba3924 | 16 | * warranty that such application will be suitable for the specified |
frank26080115 | 0:bf7b9fba3924 | 17 | * use without further testing or modification. |
frank26080115 | 0:bf7b9fba3924 | 18 | **********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 19 | #include "lpc17xx_dac.h" |
frank26080115 | 0:bf7b9fba3924 | 20 | #include "lpc17xx_libcfg.h" |
frank26080115 | 0:bf7b9fba3924 | 21 | #include "lpc17xx_pinsel.h" |
frank26080115 | 0:bf7b9fba3924 | 22 | #include "debug_frmwrk.h" |
frank26080115 | 0:bf7b9fba3924 | 23 | |
frank26080115 | 0:bf7b9fba3924 | 24 | /* Example group ----------------------------------------------------------- */ |
frank26080115 | 0:bf7b9fba3924 | 25 | /** @defgroup DAC_Speaker Speaker |
frank26080115 | 0:bf7b9fba3924 | 26 | * @ingroup DAC_Examples |
frank26080115 | 0:bf7b9fba3924 | 27 | * @{ |
frank26080115 | 0:bf7b9fba3924 | 28 | */ |
frank26080115 | 0:bf7b9fba3924 | 29 | |
frank26080115 | 0:bf7b9fba3924 | 30 | /*-------------------------MAIN FUNCTION------------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 31 | /*********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 32 | * @brief c_entry: Main DAC program body |
frank26080115 | 0:bf7b9fba3924 | 33 | * @param[in] None |
frank26080115 | 0:bf7b9fba3924 | 34 | * @return int |
frank26080115 | 0:bf7b9fba3924 | 35 | **********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 36 | int c_entry(void) |
frank26080115 | 0:bf7b9fba3924 | 37 | { |
frank26080115 | 0:bf7b9fba3924 | 38 | PINSEL_CFG_Type PinCfg; |
frank26080115 | 0:bf7b9fba3924 | 39 | uint32_t time; |
frank26080115 | 0:bf7b9fba3924 | 40 | float rate =0; |
frank26080115 | 0:bf7b9fba3924 | 41 | |
frank26080115 | 0:bf7b9fba3924 | 42 | /* |
frank26080115 | 0:bf7b9fba3924 | 43 | * Init DAC pin connect |
frank26080115 | 0:bf7b9fba3924 | 44 | * AOUT on P0.26 |
frank26080115 | 0:bf7b9fba3924 | 45 | */ |
frank26080115 | 0:bf7b9fba3924 | 46 | PinCfg.Funcnum = 2; |
frank26080115 | 0:bf7b9fba3924 | 47 | PinCfg.OpenDrain = 0; |
frank26080115 | 0:bf7b9fba3924 | 48 | PinCfg.Pinmode = 0; |
frank26080115 | 0:bf7b9fba3924 | 49 | PinCfg.Pinnum = 26; |
frank26080115 | 0:bf7b9fba3924 | 50 | PinCfg.Portnum = 0; |
frank26080115 | 0:bf7b9fba3924 | 51 | PINSEL_ConfigPin(&PinCfg); |
frank26080115 | 0:bf7b9fba3924 | 52 | |
frank26080115 | 0:bf7b9fba3924 | 53 | /* init DAC structure to default |
frank26080115 | 0:bf7b9fba3924 | 54 | * Maximum current is 700 uA |
frank26080115 | 0:bf7b9fba3924 | 55 | * First value to AOUT is 0 |
frank26080115 | 0:bf7b9fba3924 | 56 | */ |
frank26080115 | 0:bf7b9fba3924 | 57 | DAC_Init(LPC_DAC); |
frank26080115 | 0:bf7b9fba3924 | 58 | |
frank26080115 | 0:bf7b9fba3924 | 59 | // main loop |
frank26080115 | 0:bf7b9fba3924 | 60 | while (1) |
frank26080115 | 0:bf7b9fba3924 | 61 | { |
frank26080115 | 0:bf7b9fba3924 | 62 | for(time = 1; time < 0x3FF; time++) |
frank26080115 | 0:bf7b9fba3924 | 63 | { |
frank26080115 | 0:bf7b9fba3924 | 64 | DAC_UpdateValue ( LPC_DAC,(uint32_t)(time*rate)); |
frank26080115 | 0:bf7b9fba3924 | 65 | } |
frank26080115 | 0:bf7b9fba3924 | 66 | |
frank26080115 | 0:bf7b9fba3924 | 67 | rate += 0.001; |
frank26080115 | 0:bf7b9fba3924 | 68 | |
frank26080115 | 0:bf7b9fba3924 | 69 | if(rate >= 1) |
frank26080115 | 0:bf7b9fba3924 | 70 | { |
frank26080115 | 0:bf7b9fba3924 | 71 | rate = 0; |
frank26080115 | 0:bf7b9fba3924 | 72 | } |
frank26080115 | 0:bf7b9fba3924 | 73 | } |
frank26080115 | 0:bf7b9fba3924 | 74 | |
frank26080115 | 0:bf7b9fba3924 | 75 | return 1; |
frank26080115 | 0:bf7b9fba3924 | 76 | } |
frank26080115 | 0:bf7b9fba3924 | 77 | /* With ARM and GHS toolsets, the entry point is main() - this will |
frank26080115 | 0:bf7b9fba3924 | 78 | allow the linker to generate wrapper code to setup stacks, allocate |
frank26080115 | 0:bf7b9fba3924 | 79 | heap area, and initialize and copy code and data segments. For GNU |
frank26080115 | 0:bf7b9fba3924 | 80 | toolsets, the entry point is through __start() in the crt0_gnu.asm |
frank26080115 | 0:bf7b9fba3924 | 81 | file, and that startup code will setup stacks and data */ |
frank26080115 | 0:bf7b9fba3924 | 82 | int main(void) |
frank26080115 | 0:bf7b9fba3924 | 83 | { |
frank26080115 | 0:bf7b9fba3924 | 84 | return c_entry(); |
frank26080115 | 0:bf7b9fba3924 | 85 | } |
frank26080115 | 0:bf7b9fba3924 | 86 | |
frank26080115 | 0:bf7b9fba3924 | 87 | #ifdef DEBUG |
frank26080115 | 0:bf7b9fba3924 | 88 | /******************************************************************************* |
frank26080115 | 0:bf7b9fba3924 | 89 | * @brief Reports the name of the source file and the source line number |
frank26080115 | 0:bf7b9fba3924 | 90 | * where the CHECK_PARAM error has occurred. |
frank26080115 | 0:bf7b9fba3924 | 91 | * @param[in] file Pointer to the source file name |
frank26080115 | 0:bf7b9fba3924 | 92 | * @param[in] line assert_param error line source number |
frank26080115 | 0:bf7b9fba3924 | 93 | * @return None |
frank26080115 | 0:bf7b9fba3924 | 94 | *******************************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 95 | void check_failed(uint8_t *file, uint32_t line) |
frank26080115 | 0:bf7b9fba3924 | 96 | { |
frank26080115 | 0:bf7b9fba3924 | 97 | /* User can add his own implementation to report the file name and line number, |
frank26080115 | 0:bf7b9fba3924 | 98 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
frank26080115 | 0:bf7b9fba3924 | 99 | |
frank26080115 | 0:bf7b9fba3924 | 100 | /* Infinite loop */ |
frank26080115 | 0:bf7b9fba3924 | 101 | while(1); |
frank26080115 | 0:bf7b9fba3924 | 102 | } |
frank26080115 | 0:bf7b9fba3924 | 103 | #endif |
frank26080115 | 0:bf7b9fba3924 | 104 | |
frank26080115 | 0:bf7b9fba3924 | 105 | /* |
frank26080115 | 0:bf7b9fba3924 | 106 | * @} |
frank26080115 | 0:bf7b9fba3924 | 107 | */ |