These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frank26080115 0:bf7b9fba3924 1 /***********************************************************************//**
frank26080115 0:bf7b9fba3924 2 * @file systick_stclk.c
frank26080115 0:bf7b9fba3924 3 * @purpose This example describes how to configure System Tick to use
frank26080115 0:bf7b9fba3924 4 * with external clock source STCLK
frank26080115 0:bf7b9fba3924 5 * @version 2.0
frank26080115 0:bf7b9fba3924 6 * @date 21. May. 2010
frank26080115 0:bf7b9fba3924 7 * @author NXP MCU SW Application Team
frank26080115 0:bf7b9fba3924 8 *---------------------------------------------------------------------
frank26080115 0:bf7b9fba3924 9 * Software that is described herein is for illustrative purposes only
frank26080115 0:bf7b9fba3924 10 * which provides customers with programming information regarding the
frank26080115 0:bf7b9fba3924 11 * products. This software is supplied "AS IS" without any warranties.
frank26080115 0:bf7b9fba3924 12 * NXP Semiconductors assumes no responsibility or liability for the
frank26080115 0:bf7b9fba3924 13 * use of the software, conveys no license or title under any patent,
frank26080115 0:bf7b9fba3924 14 * copyright, or mask work right to the product. NXP Semiconductors
frank26080115 0:bf7b9fba3924 15 * reserves the right to make changes in the software without
frank26080115 0:bf7b9fba3924 16 * notification. NXP Semiconductors also make no representation or
frank26080115 0:bf7b9fba3924 17 * warranty that such application will be suitable for the specified
frank26080115 0:bf7b9fba3924 18 * use without further testing or modification.
frank26080115 0:bf7b9fba3924 19 **********************************************************************/
frank26080115 0:bf7b9fba3924 20 #include "lpc17xx_libcfg.h"
frank26080115 0:bf7b9fba3924 21 #include "lpc17xx_gpio.h"
frank26080115 0:bf7b9fba3924 22 #include "lpc17xx_systick.h"
frank26080115 0:bf7b9fba3924 23 #include "lpc17xx_pinsel.h"
frank26080115 0:bf7b9fba3924 24 #include "lpc17xx_timer.h"
frank26080115 0:bf7b9fba3924 25
frank26080115 0:bf7b9fba3924 26 /* Example group ----------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 27 /** @defgroup SysTick_STCLK STCLK
frank26080115 0:bf7b9fba3924 28 * @ingroup SysTick_Examples
frank26080115 0:bf7b9fba3924 29 * @{
frank26080115 0:bf7b9fba3924 30 */
frank26080115 0:bf7b9fba3924 31
frank26080115 0:bf7b9fba3924 32 /************************** PRIVATE VARIABLES *************************/
frank26080115 0:bf7b9fba3924 33 FunctionalState Cur_State = ENABLE;
frank26080115 0:bf7b9fba3924 34 Bool IO_State = FALSE;
frank26080115 0:bf7b9fba3924 35
frank26080115 0:bf7b9fba3924 36 /************************** PRIVATE FUNCTIONS *************************/
frank26080115 0:bf7b9fba3924 37 void SysTick_Handler(void);
frank26080115 0:bf7b9fba3924 38
frank26080115 0:bf7b9fba3924 39 /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
frank26080115 0:bf7b9fba3924 40 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 41 * @brief SysTick interrupt handler
frank26080115 0:bf7b9fba3924 42 * @param None
frank26080115 0:bf7b9fba3924 43 * @return None
frank26080115 0:bf7b9fba3924 44 ***********************************************************************/
frank26080115 0:bf7b9fba3924 45 void SysTick_Handler(void)
frank26080115 0:bf7b9fba3924 46 {
frank26080115 0:bf7b9fba3924 47 //Clear System Tick counter flag
frank26080115 0:bf7b9fba3924 48 SYSTICK_ClearCounterFlag();
frank26080115 0:bf7b9fba3924 49 //toggle P0.0
frank26080115 0:bf7b9fba3924 50 if (Cur_State == ENABLE)
frank26080115 0:bf7b9fba3924 51 {
frank26080115 0:bf7b9fba3924 52 //pull-down pin
frank26080115 0:bf7b9fba3924 53 GPIO_ClearValue(0, (1<<0));
frank26080115 0:bf7b9fba3924 54 Cur_State = DISABLE;
frank26080115 0:bf7b9fba3924 55 }
frank26080115 0:bf7b9fba3924 56 else
frank26080115 0:bf7b9fba3924 57 {
frank26080115 0:bf7b9fba3924 58 GPIO_SetValue(0, (1<<0));
frank26080115 0:bf7b9fba3924 59 Cur_State = ENABLE;
frank26080115 0:bf7b9fba3924 60 }
frank26080115 0:bf7b9fba3924 61 }
frank26080115 0:bf7b9fba3924 62
frank26080115 0:bf7b9fba3924 63
frank26080115 0:bf7b9fba3924 64 /*-------------------------MAIN FUNCTION------------------------------*/
frank26080115 0:bf7b9fba3924 65 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 66 * @brief c_entry: Main program body
frank26080115 0:bf7b9fba3924 67 * @param[in] None
frank26080115 0:bf7b9fba3924 68 * @return int
frank26080115 0:bf7b9fba3924 69 **********************************************************************/
frank26080115 0:bf7b9fba3924 70 int c_entry (void)
frank26080115 0:bf7b9fba3924 71 {
frank26080115 0:bf7b9fba3924 72 PINSEL_CFG_Type PinCfg;
frank26080115 0:bf7b9fba3924 73 TIM_TIMERCFG_Type TIM_ConfigStruct;
frank26080115 0:bf7b9fba3924 74 TIM_MATCHCFG_Type TIM_MatchConfigStruct;
frank26080115 0:bf7b9fba3924 75
frank26080115 0:bf7b9fba3924 76 // Conifg P1.28 as MAT0.0
frank26080115 0:bf7b9fba3924 77 PinCfg.Funcnum = 3;
frank26080115 0:bf7b9fba3924 78 PinCfg.OpenDrain = 0;
frank26080115 0:bf7b9fba3924 79 PinCfg.Pinmode = 0;
frank26080115 0:bf7b9fba3924 80 PinCfg.Portnum = 1;
frank26080115 0:bf7b9fba3924 81 PinCfg.Pinnum = 28;
frank26080115 0:bf7b9fba3924 82 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 83
frank26080115 0:bf7b9fba3924 84 /* P3.26 as STCLK */
frank26080115 0:bf7b9fba3924 85 PinCfg.Funcnum = 1;
frank26080115 0:bf7b9fba3924 86 PinCfg.OpenDrain = 0;
frank26080115 0:bf7b9fba3924 87 PinCfg.Pinmode = 0;
frank26080115 0:bf7b9fba3924 88 PinCfg.Portnum = 3;
frank26080115 0:bf7b9fba3924 89 PinCfg.Pinnum = 26;
frank26080115 0:bf7b9fba3924 90 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 91
frank26080115 0:bf7b9fba3924 92 // Initialize timer 0, prescale count time of 10uS
frank26080115 0:bf7b9fba3924 93 TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
frank26080115 0:bf7b9fba3924 94 TIM_ConfigStruct.PrescaleValue = 10;
frank26080115 0:bf7b9fba3924 95
frank26080115 0:bf7b9fba3924 96 // use channel 0, MR0
frank26080115 0:bf7b9fba3924 97 TIM_MatchConfigStruct.MatchChannel = 0;
frank26080115 0:bf7b9fba3924 98 // Disable interrupt when MR0 matches the value in TC register
frank26080115 0:bf7b9fba3924 99 TIM_MatchConfigStruct.IntOnMatch = TRUE;
frank26080115 0:bf7b9fba3924 100 //Enable reset on MR0: TIMER will reset if MR0 matches it
frank26080115 0:bf7b9fba3924 101 TIM_MatchConfigStruct.ResetOnMatch = TRUE;
frank26080115 0:bf7b9fba3924 102 //Stop on MR0 if MR0 matches it
frank26080115 0:bf7b9fba3924 103 TIM_MatchConfigStruct.StopOnMatch = FALSE;
frank26080115 0:bf7b9fba3924 104 //Toggle MR0.0 pin if MR0 matches it
frank26080115 0:bf7b9fba3924 105 TIM_MatchConfigStruct.ExtMatchOutputType =TIM_EXTMATCH_TOGGLE;
frank26080115 0:bf7b9fba3924 106 // Set Match value, count value of 10 (10 * 10uS = 100uS --> 10KHz)
frank26080115 0:bf7b9fba3924 107 TIM_MatchConfigStruct.MatchValue = 10;
frank26080115 0:bf7b9fba3924 108
frank26080115 0:bf7b9fba3924 109 TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct);
frank26080115 0:bf7b9fba3924 110 TIM_ConfigMatch(LPC_TIM0,&TIM_MatchConfigStruct);
frank26080115 0:bf7b9fba3924 111 TIM_Cmd(LPC_TIM0,ENABLE);
frank26080115 0:bf7b9fba3924 112
frank26080115 0:bf7b9fba3924 113 GPIO_SetDir(0, (1<<0), 1); //Set P0.0 as output
frank26080115 0:bf7b9fba3924 114
frank26080115 0:bf7b9fba3924 115 //Use P0.0 to test System Tick interrupt
frank26080115 0:bf7b9fba3924 116 /* Initialize System Tick with 10ms time interval
frank26080115 0:bf7b9fba3924 117 * Frequency input = 10kHz /2 = 5kHz
frank26080115 0:bf7b9fba3924 118 * Time input = 10ms
frank26080115 0:bf7b9fba3924 119 */
frank26080115 0:bf7b9fba3924 120 SYSTICK_ExternalInit(5000, 10);
frank26080115 0:bf7b9fba3924 121 //Enable System Tick interrupt
frank26080115 0:bf7b9fba3924 122 SYSTICK_IntCmd(ENABLE);
frank26080115 0:bf7b9fba3924 123 //Enable System Tick Counter
frank26080115 0:bf7b9fba3924 124 SYSTICK_Cmd(ENABLE);
frank26080115 0:bf7b9fba3924 125
frank26080115 0:bf7b9fba3924 126 while(1);
frank26080115 0:bf7b9fba3924 127 return 1;
frank26080115 0:bf7b9fba3924 128 }
frank26080115 0:bf7b9fba3924 129
frank26080115 0:bf7b9fba3924 130
frank26080115 0:bf7b9fba3924 131 /* With ARM and GHS toolsets, the entry point is main() - this will
frank26080115 0:bf7b9fba3924 132 allow the linker to generate wrapper code to setup stacks, allocate
frank26080115 0:bf7b9fba3924 133 heap area, and initialize and copy code and data segments. For GNU
frank26080115 0:bf7b9fba3924 134 toolsets, the entry point is through __start() in the crt0_gnu.asm
frank26080115 0:bf7b9fba3924 135 file, and that startup code will setup stacks and data */
frank26080115 0:bf7b9fba3924 136 int main(void)
frank26080115 0:bf7b9fba3924 137 {
frank26080115 0:bf7b9fba3924 138 return c_entry();
frank26080115 0:bf7b9fba3924 139 }
frank26080115 0:bf7b9fba3924 140
frank26080115 0:bf7b9fba3924 141 #ifdef DEBUG
frank26080115 0:bf7b9fba3924 142 /*******************************************************************************
frank26080115 0:bf7b9fba3924 143 * @brief Reports the name of the source file and the source line number
frank26080115 0:bf7b9fba3924 144 * where the CHECK_PARAM error has occurred.
frank26080115 0:bf7b9fba3924 145 * @param[in] file Pointer to the source file name
frank26080115 0:bf7b9fba3924 146 * @param[in] line assert_param error line source number
frank26080115 0:bf7b9fba3924 147 * @return None
frank26080115 0:bf7b9fba3924 148 *******************************************************************************/
frank26080115 0:bf7b9fba3924 149 void check_failed(uint8_t *file, uint32_t line)
frank26080115 0:bf7b9fba3924 150 {
frank26080115 0:bf7b9fba3924 151 /* User can add his own implementation to report the file name and line number,
frank26080115 0:bf7b9fba3924 152 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
frank26080115 0:bf7b9fba3924 153
frank26080115 0:bf7b9fba3924 154 /* Infinite loop */
frank26080115 0:bf7b9fba3924 155 while(1);
frank26080115 0:bf7b9fba3924 156 }
frank26080115 0:bf7b9fba3924 157 #endif
frank26080115 0:bf7b9fba3924 158
frank26080115 0:bf7b9fba3924 159 /*
frank26080115 0:bf7b9fba3924 160 * @}
frank26080115 0:bf7b9fba3924 161 */