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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers systick_stclk.c Source File

systick_stclk.c

Go to the documentation of this file.
00001 /***********************************************************************//**
00002  * @file        systick_stclk.c
00003  * @purpose     This example describes how to configure System Tick to use
00004  *              with external clock source STCLK
00005  * @version     2.0
00006  * @date        21. May. 2010
00007  * @author      NXP MCU SW Application Team
00008  *---------------------------------------------------------------------
00009  * Software that is described herein is for illustrative purposes only
00010  * which provides customers with programming information regarding the
00011  * products. This software is supplied "AS IS" without any warranties.
00012  * NXP Semiconductors assumes no responsibility or liability for the
00013  * use of the software, conveys no license or title under any patent,
00014  * copyright, or mask work right to the product. NXP Semiconductors
00015  * reserves the right to make changes in the software without
00016  * notification. NXP Semiconductors also make no representation or
00017  * warranty that such application will be suitable for the specified
00018  * use without further testing or modification.
00019  **********************************************************************/
00020 #include "lpc17xx_libcfg.h"
00021 #include "lpc17xx_gpio.h"
00022 #include "lpc17xx_systick.h"
00023 #include "lpc17xx_pinsel.h"
00024 #include "lpc17xx_timer.h"
00025 
00026 /* Example group ----------------------------------------------------------- */
00027 /** @defgroup SysTick_STCLK STCLK
00028  * @ingroup SysTick_Examples
00029  * @{
00030  */
00031 
00032 /************************** PRIVATE VARIABLES *************************/
00033 FunctionalState Cur_State = ENABLE;
00034 Bool IO_State = FALSE;
00035 
00036 /************************** PRIVATE FUNCTIONS *************************/
00037 void SysTick_Handler(void);
00038 
00039 /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
00040 /*********************************************************************//**
00041  * @brief       SysTick interrupt handler
00042  * @param       None
00043  * @return      None
00044  ***********************************************************************/
00045 void SysTick_Handler(void)
00046 {
00047     //Clear System Tick counter flag
00048     SYSTICK_ClearCounterFlag();
00049     //toggle P0.0
00050     if (Cur_State == ENABLE)
00051     {
00052         //pull-down pin
00053         GPIO_ClearValue(0, (1<<0));
00054         Cur_State = DISABLE;
00055     }
00056     else
00057     {
00058         GPIO_SetValue(0, (1<<0));
00059         Cur_State = ENABLE;
00060     }
00061 }
00062 
00063 
00064 /*-------------------------MAIN FUNCTION------------------------------*/
00065 /*********************************************************************//**
00066  * @brief       c_entry: Main program body
00067  * @param[in]   None
00068  * @return      int
00069  **********************************************************************/
00070 int c_entry (void)
00071 {
00072     PINSEL_CFG_Type PinCfg;
00073     TIM_TIMERCFG_Type TIM_ConfigStruct;
00074     TIM_MATCHCFG_Type TIM_MatchConfigStruct;
00075 
00076     // Conifg P1.28 as MAT0.0
00077     PinCfg.Funcnum = 3;
00078     PinCfg.OpenDrain = 0;
00079     PinCfg.Pinmode = 0;
00080     PinCfg.Portnum = 1;
00081     PinCfg.Pinnum = 28;
00082     PINSEL_ConfigPin(&PinCfg);
00083 
00084     /* P3.26 as STCLK */
00085     PinCfg.Funcnum = 1;
00086     PinCfg.OpenDrain = 0;
00087     PinCfg.Pinmode = 0;
00088     PinCfg.Portnum = 3;
00089     PinCfg.Pinnum = 26;
00090     PINSEL_ConfigPin(&PinCfg);
00091 
00092     // Initialize timer 0, prescale count time of 10uS
00093     TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
00094     TIM_ConfigStruct.PrescaleValue  = 10;
00095 
00096     // use channel 0, MR0
00097     TIM_MatchConfigStruct.MatchChannel = 0;
00098     // Disable interrupt when MR0 matches the value in TC register
00099     TIM_MatchConfigStruct.IntOnMatch   = TRUE;
00100     //Enable reset on MR0: TIMER will reset if MR0 matches it
00101     TIM_MatchConfigStruct.ResetOnMatch = TRUE;
00102     //Stop on MR0 if MR0 matches it
00103     TIM_MatchConfigStruct.StopOnMatch  = FALSE;
00104     //Toggle MR0.0 pin if MR0 matches it
00105     TIM_MatchConfigStruct.ExtMatchOutputType =TIM_EXTMATCH_TOGGLE;
00106     // Set Match value, count value of 10 (10 * 10uS = 100uS --> 10KHz)
00107     TIM_MatchConfigStruct.MatchValue   = 10;
00108 
00109     TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct);
00110     TIM_ConfigMatch(LPC_TIM0,&TIM_MatchConfigStruct);
00111     TIM_Cmd(LPC_TIM0,ENABLE);
00112 
00113     GPIO_SetDir(0, (1<<0), 1); //Set P0.0 as output
00114 
00115     //Use P0.0 to test System Tick interrupt
00116     /* Initialize System Tick with 10ms time interval
00117      * Frequency input = 10kHz /2 = 5kHz
00118      * Time input = 10ms
00119      */
00120     SYSTICK_ExternalInit(5000, 10);
00121     //Enable System Tick interrupt
00122     SYSTICK_IntCmd(ENABLE);
00123     //Enable System Tick Counter
00124     SYSTICK_Cmd(ENABLE);
00125 
00126     while(1);
00127     return 1;
00128 }
00129 
00130 
00131 /* With ARM and GHS toolsets, the entry point is main() - this will
00132    allow the linker to generate wrapper code to setup stacks, allocate
00133    heap area, and initialize and copy code and data segments. For GNU
00134    toolsets, the entry point is through __start() in the crt0_gnu.asm
00135    file, and that startup code will setup stacks and data */
00136 int main(void)
00137 {
00138     return c_entry();
00139 }
00140 
00141 #ifdef  DEBUG
00142 /*******************************************************************************
00143 * @brief        Reports the name of the source file and the source line number
00144 *               where the CHECK_PARAM error has occurred.
00145 * @param[in]    file Pointer to the source file name
00146 * @param[in]    line assert_param error line source number
00147 * @return       None
00148 *******************************************************************************/
00149 void check_failed(uint8_t *file, uint32_t line)
00150 {
00151     /* User can add his own implementation to report the file name and line number,
00152      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00153 
00154     /* Infinite loop */
00155     while(1);
00156 }
00157 #endif
00158 
00159 /*
00160  * @}
00161  */