#ifdef __USE_CMSIS #include "LPC17xx.h" #endif #include <cr_section_macros.h> #include <NXP/crp.h> // #define PLL0CFG_Val 0x00090063 ensure this is the case in CMISvp00_17xx under system_LPCxx.c for now // see user manual section 4.5 for more information on how to get 100MHz __CRP const unsigned int CRP_WORD = CRP_NO_CRP ; // Function to initialize GPIO to access LED2 void led2_init (void) { // Set P0_22 to 00 - GPIO LPC_PINCON->PINSEL1&= (~(3 << 12)); // Set GPIO - P0_22 - to be output LPC_GPIO0->FIODIR |= (1 << 22); } // Function to turn LED2 on void led2_on (void) { LPC_GPIO0->FIOSET = (1 << 22); } // Function to turn LED2 off void led2_off (void) { LPC_GPIO0->FIOCLR = (1 << 22); } int main(void) { int x; led2_init(); led2_on(); while(1) { led2_on(); for(x=0;x<=2000000;x++){} led2_off(); for(x=0;x<=2000000;x++){} } return 0 ; } |
/* =============================================================================== Name : main.c Author : Version : Copyright : Copyright (C) Description : main definition =============================================================================== */ #ifdef __USE_CMSIS #include "LPC17xx.h" #endif #include <cr_section_macros.h> #include <NXP/crp.h> // Variable to store CRP value in. Will be placed automatically // by the linker when "Enable Code Read Protect" selected. // See crp.h header for more information __CRP const unsigned int CRP_WORD = CRP_NO_CRP ; // TODO: insert other include files here // TODO: insert other definitions and declarations here // Function to initialise GPIO to access LED2 void led2_init (void) { // Set P0_22 to 00 - GPIO LPC_PINCON->PINSEL1&= (~(3 << 12)); // Set GPIO - P0_22 - to be output LPC_GPIO0->FIODIR |= (1 << 22); } // Function to turn LED2 on void led2_on (void) { LPC_GPIO0->FIOSET = (1 << 22); } // Function to turn LED2 off void led2_off (void) { LPC_GPIO0->FIOCLR = (1 << 22); } // Function to invert current state of LED2 void led2_invert (void) { int ledstate; // Read current state of GPIO P0_0..31, which includes LED2 ledstate = LPC_GPIO0->FIOPIN; // Turn off LED2 if it is on // (ANDing to ensure we only affect the LED output) LPC_GPIO0->FIOCLR = ledstate & (1 << 22); // Turn on LED2 if it is off // (ANDing to ensure we only affect the LED output) LPC_GPIO0->FIOSET = ((~ledstate) & (1 << 22)); } int main(void) { // TODO: insert code here // Enter an infinite loop, just incrementing a counter led2_init(); led2_on(); while(1) { led2_invert (); } return 0 ; } |