If CMSIS is to use the code format of your example (using structures) then my application already generates code for all LPC17xx chips this way, is this what you mean?
Code: Select all/************************************************************************************
Code created using the ARMwizard, visit http://alexan.edaboard.eu
************************************************************************************/
#include LPC17xx.h>
/******************************************************************************
TIMER0 interrupt service function
******************************************************************************/
void TIMER0_IRQHandler(void) {
/* write code here */
/* list of all available flags, select which to use */
LPC_TIM0->IR = 1; /* Clear MAT0.0 interrupt flag */
LPC_TIM0->IR = 2; /* Clear MAT0.1 interrupt flag */
LPC_TIM0->IR = 4; /* Clear MAT0.2 interrupt flag */
LPC_TIM0->IR = 8; /* Clear MAT0.3 interrupt flag */
LPC_TIM0->IR = 16; /* Clear CAP0.0 interrupt flag */
LPC_TIM0->IR = 32; /* Clear CAP0.1 interrupt flag */
}
/******************************************************************************
EINT0 interrupt service function
******************************************************************************/
void EINT0_IRQHandler(void) {
/* write code here */
LPC_SC->EXTINT = 1; /* Clear EINT0 interrupt flag */
}
/******************************************************************************
SPI interrupt service function
******************************************************************************/
void SPI_IRQHandler(void) {
/* write code here */
LPC_SPI->SPINT = 1; /* Clear SPI interrupt flag */
}
int main(void)
{
/*
P0.0: PORT0.0 (General purpose I/O) Output, pull-up resistor enabled
P0.1: PORT0.1 (General purpose I/O) Output, pull-up resistor enabled
P0.2: PORT0.2 (General purpose I/O) Input, repeater mode
P0.3: PORT0.3 (General purpose I/O) Input, repeater mode, open drain
P0.4: PORT0.4 (General purpose I/O) Input, pull-up resistor enabled
P0.5: PORT0.5 (General purpose I/O) Input, pull-up resistor enabled
P0.6: PORT0.6 (General purpose I/O) Input, neither pull-up nor pull-down
P0.7: PORT0.7 (General purpose I/O) Input, neither pull-up nor pull-down
P0.8: PORT0.8 (General purpose I/O) Input, pull-down resistor enabled, open drain
P0.9: PORT0.9 (General purpose I/O) Input, pull-up resistor enabled
P0.10: PORT0.10 (General purpose I/O) Input, pull-up resistor enabled
P0.11: PORT0.11 (General purpose I/O) Input, pull-up resistor enabled
P0.15: PORT0.15 (General purpose I/O) Input, pull-up resistor enabled
P0.16: PORT0.16 (General purpose I/O) Input, pull-up resistor enabled, open drain
P0.17: PORT0.17 (General purpose I/O) Input, pull-up resistor enabled
P0.18: PORT0.18 (General purpose I/O) Input, pull-up resistor enabled
P0.19: PORT0.19 (General purpose I/O) Input, pull-up resistor enabled
P0.20: PORT0.20 (General purpose I/O) Input, pull-up resistor enabled
P0.21: PORT0.21 (General purpose I/O) Input, pull-up resistor enabled
P0.22: PORT0.22 (General purpose I/O) Input, pull-up resistor enabled
P0.23: PORT0.23 (General purpose I/O) Input, pull-up resistor enabled
P0.24: PORT0.24 (General purpose I/O) Input, pull-up resistor enabled
P0.25: PORT0.25 (General purpose I/O) Input, pull-up resistor enabled
P0.26: PORT0.26 (General purpose I/O) Input, pull-up resistor enabled
P0.27: PORT0.27 (General purpose I/open-drain O) Input
P0.28: PORT0.28 (General purpose I/open-drain O) Input
P0.29: PORT0.29 (General purpose I/O) Input
P0.30: PORT0.30 (General purpose I/O) Input
P1.0: PORT1.0 (General purpose I/O) Input, pull-up resistor enabled
P1.1: PORT1.1 (General purpose I/O) Input, pull-up resistor enabled
P1.4: PORT1.4 (General purpose I/O) Input, pull-up resistor enabled
P1.8: PORT1.8 (General purpose I/O) Input, pull-up resistor enabled
P1.9: PORT1.9 (General purpose I/O) Input, pull-up resistor enabled
P1.10: PORT1.10 (General purpose I/O) Input, pull-up resistor enabled
P1.14: PORT1.14 (General purpose I/O) Input, pull-up resistor enabled
P1.15: PORT1.15 (General purpose I/O) Input, pull-up resistor enabled
P1.16: PORT1.16 (General purpose I/O) Input, pull-up resistor enabled
P1.17: PORT1.17 (General purpose I/O) Input, pull-up resistor enabled
P1.18: PORT1.18 (General purpose I/O) Input, pull-up resistor enabled
P1.19: PORT1.19 (General purpose I/O) Input, pull-up resistor enabled
P1.20: PORT1.20 (General purpose I/O) Input, pull-up resistor enabled
P1.21: PORT1.21 (General purpose I/O) Input, pull-up resistor enabled
P1.22: PORT1.22 (General purpose I/O) Input, pull-up resistor enabled
P1.23: PORT1.23 (General purpose I/O) Input, pull-up resistor enabled
P1.24: PORT1.24 (General purpose I/O) Input, pull-up resistor enabled
P1.25: PORT1.25 (General purpose I/O) Input, pull-up resistor enabled
P1.26: PORT1.26 (General purpose I/O) Input, pull-up resistor enabled
P1.27: PORT1.27 (General purpose I/O) Input, pull-up resistor enabled
P1.28: PORT1.28 (General purpose I/O) Input, pull-up resistor enabled
P1.29: PORT1.29 (General purpose I/O) Input, pull-up resistor enabled
P1.30: PORT1.30 (General purpose I/O) Input, pull-up resistor enabled
P1.31: PORT1.31 (General purpose I/O) Input, pull-up resistor enabled
P2.0: PORT2.0 (General purpose I/O) Input, pull-up resistor enabled
P2.1: PORT2.1 (General purpose I/O) Input, pull-up resistor enabled
P2.2: PORT2.2 (General purpose I/O) Input, pull-up resistor enabled
P2.3: PORT2.3 (General purpose I/O) Input, pull-up resistor enabled
P2.4: PORT2.4 (General purpose I/O) Input, pull-up resistor enabled
P2.5: PORT2.5 (General purpose I/O) Input, pull-up resistor enabled
P2.6: PORT2.6 (General purpose I/O) Input, pull-up resistor enabled
P2.7: PORT2.7 (General purpose I/O) Input, pull-up resistor enabled
P2.8: PORT2.8 (General purpose I/O) Input, pull-up resistor enabled
P2.9: PORT2.9 (General purpose I/O) Input, pull-up resistor enabled
P2.10: PORT2.10 (General purpose I/O) Input, pull-up resistor enabled
P2.11: PORT2.11 (General purpose I/O) Input, pull-up resistor enabled
P2.12: PORT2.12 (General purpose I/O) Input, pull-up resistor enabled
P2.13: PORT2.13 (General purpose I/O) Input, pull-up resistor enabled
P3.25: PORT3.25 (General purpose I/O) Input, pull-up resistor enabled
P3.26: PORT3.26 (General purpose I/O) Input, pull-up resistor enabled
P4.28: PORT4.28 (General purpose I/O) Input, pull-up resistor enabled
P4.29: PORT4.29 (General purpose I/O) Input, pull-up resistor enabled
*/
LPC_PINCON->PINSEL0=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE0=0x0003A050; /* binary: 00000000_00000011_10100000_01010000 */
LPC_GPIO0->FIODIR=0x00000003; /* binary: 00000000_00000000_00000000_00000011 */
LPC_PINCON->PINMODE_OD0=0x00010108; /* binary: 00000000_00000001_00000001_00001000 */
LPC_PINCON->PINSEL1=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE1=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINSEL2=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE2=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_GPIO1->FIODIR=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE_OD1=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINSEL3=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE3=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINSEL4=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE4=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_GPIO2->FIODIR=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE_OD2=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINSEL7=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE7=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_GPIO3->FIODIR=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE_OD3=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINSEL9=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE9=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_GPIO4->FIODIR=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE_OD4=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
/******************************************************************************
External interrupts
*******************************************************************************
Ext. interrupt 0 mode: Edge sensitivity / Rising edge
*/
LPC_SC->EXTMODE=0x01; /* binary: 00000001 */
LPC_SC->EXTPOLAR=0x01; /* binary: 00000001 */
LPC_SC->EXTINT=0x01; /* clear the external interrupt flags */
/******************************************************************************
GPIO interrupts
*******************************************************************************
P0.0 : On falling edge
P0.1 : On falling edge
P0.4 : On both edges
P0.6 : On rising edge
*/
LPC_GPIOINT->IO0IntEnR=0x00000050; /* binary: 00000000_00000000_00000000_01010000 */
LPC_GPIOINT->IO0IntEnF=0x00000013; /* binary: 00000000_00000000_00000000_00010011 */
LPC_GPIOINT->IO2IntEnR=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_GPIOINT->IO2IntEnF=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
/******************************************************************************
Vectored Interrupt initialization
******************************************************************************/
NVIC_EnableIRQ(TIMER0_IRQn); /* Enable TIMER0 interrupt */
NVIC_SetPriority(TIMER0_IRQn,0); /* Default priority group 0, can be 0(highest) - 31(lowest) */
NVIC_EnableIRQ(EINT0_IRQn); /* Enable EINT0 interrupt */
NVIC_SetPriority(EINT0_IRQn,0); /* Default priority group 0, can be 0(highest) - 31(lowest) */
NVIC_EnableIRQ(SPI_IRQn); /* Enable SPI interrupt */
NVIC_SetPriority(SPI_IRQn,0); /* Default priority group 0, can be 0(highest) - 31(lowest) */
/******************************************************************************
ADC0
*******************************************************************************
ADC operational
ADC clk: 3 MHz (calculated with peripheral clock: 15MHz)
ADC rate: 46,1538 Ksamples/sec
manual mode, 60 clocks / 12 bit accuracy
No start (only in manual mode, for burst always on)
Channel 0 enabled, global DONE flag in ADGDR will generate an interrupt
Channel 1 disabled, global DONE flag in ADGDR will generate an interrupt
Channel 2 disabled, global DONE flag in ADGDR will generate an interrupt
Channel 3 disabled, global DONE flag in ADGDR will generate an interrupt
Channel 4 disabled, global DONE flag in ADGDR will generate an interrupt
Channel 5 disabled, global DONE flag in ADGDR will generate an interrupt
Channel 6 disabled, global DONE flag in ADGDR will generate an interrupt
Channel 7 disabled, global DONE flag in ADGDR will generate an interrupt
*/
LPC_SC->PCONP |= 0x1000; /* Enable peripheral clock for ADC (default is disabled) */
LPC_ADC->ADCR=0x00200401; /* binary: 00000000_00100000_00000100_00000001 */
LPC_ADC->ADINTEN=0x00000100; /* binary: 00000000_00000000_00000001_00000000 */
/******************************************************************************
Timer0 (32bit)
*******************************************************************************
Counter Disabled, Counter Reset=0
Timer mode: count on rising edge of PCLK
Counter clk: 2 MHz, Counts every: 500 ns (calculated with peripheral clock: 30MHz)
MCR0.0 : generate interrupt on compare match
*/
LPC_TIM0->CTCR=0x00; /* binary: 00000000 */
LPC_TIM0->TC=0x00000000; /* decimal 0 */
LPC_TIM0->PR=0x0000000E; /* decimal 14 */
LPC_TIM0->MCR=0x0001; /* binary: 00000000_00000001 */
LPC_TIM0->MR0=0x000000C8; /* decimal 200 */
LPC_TIM0->MR1=0x00000000; /* decimal 0 */
LPC_TIM0->MR2=0x00000000; /* decimal 0 */
LPC_TIM0->MR3=0x00000000; /* decimal 0 */
LPC_TIM0->CCR=0x0000; /* binary: 00000000_00000000 */
LPC_TIM0->EMR=0x0000; /* binary: 00000000_00000000 */
LPC_TIM0->TCR=0x00; /* binary: 00000000 */
while(1)
{
}
}