//****************************************************************************************** // Project : LPC810M021FN08 Sample Program // Program Name : // Programer : // Create date : Version 1.0 H25.12.30 // History : // Laungage : //****************************************************************************************** // (1)Description // //****************************************************************************************** #include "LPC8xx.h" void Init_IOCON(void); void Init_PIN(void); void Init_MRT(void); void Wait_timer(unsigned int); void Init_CLK(void); void Init_PRC(void); volatile unsigned int G_TIM_COUNTER = 0; int main(void) { // ******************** // 1.Initialized // ******************** // (1)Initialized Clock Init_CLK(); // (2)Initialized reset control register Init_PRC(); // (3)Assign PIN Init_PIN(); // (4)Define I/O PORT (Configuration) Init_IOCON(); // (5)Define I/O PORT (Direction) LPC_GPIO_PORT->DIR0 = 0x0000000E; // (6)Initialized Multi-Rate Timer Init_MRT(); // ******************** // 2.Main // ******************** while(1){ LPC_GPIO_PORT->SET0 = 0x00000002; Wait_timer((unsigned int)100); // 10ms * n LPC_GPIO_PORT->CLR0 = 0x00000002; Wait_timer((unsigned int)100); // 10ms * n LPC_GPIO_PORT->SET0 = 0x00000004; Wait_timer((unsigned int)100); // 10ms * n LPC_GPIO_PORT->CLR0 = 0x00000004; Wait_timer((unsigned int)100); // 10ms * n LPC_GPIO_PORT->SET0 = 0x00000008; Wait_timer((unsigned int)100); // 10ms * n LPC_GPIO_PORT->CLR0 = 0x00000008; Wait_timer((unsigned int)100); // 10ms * n } } //****************************************************************************************** // Function Name : Init_IOCON // Title : This function sets the attributes of the port . // Input : // Output : // Description : This function may be a default value is usually . //****************************************************************************************** void Init_IOCON(void) { // **************************** // 1.Define IOCON ( PIO0_0 ) register // **************************** // IOCON(PIO0_0)[2:0] - Reserved. Reset value:0 // IOCON(PIO0_0)[4:3] MODE Selects function mode (on-chip pull-up/pull-down resistor control). Reset value:0b10 // 0x0 Inactive (no pull-down/pull-up resistor enabled). // 0x1 Pull-down resistor enabled. // 0x2 Pull-up resistor enabled. // 0x3 Repeater mode. // IOCON(PIO0_0)[5] HYS Hysteresis. Reset value:0 // 0 Disable. // 1 Enable. // IOCON(PIO0_0)[6] INV Invert input Reset value:0 // 0 Input not inverted (HIGH on pin reads as 1; LOW on pin reads as 0). // 1 Input inverted (HIGH on pin reads as 0, LOW on pin reads as 1). // IOCON(PIO0_0)[9:7] - Reserved. Reset value:0b001 // IOCON(PIO0_0)[10] OD Open-drain mode. Reset value:0 // 0 Disable. // 1 Open-drain mode enabled. Remark: This is not a true open-drain mode. // IOCON(PIO0_0)[12:11] S_MODE Digital filter sample mode. Reset value:0 // 0x0 Bypass input filter. // 0x1 1 clock cycle. Input pulses shorter than one filter clock are rejected. // 0x2 2 clock cycles. Input pulses shorter than two filter clocks are rejected. // 0x3 3 clock cycles. Input pulses shorter than three filter clocks are rejected. // IOCON(PIO0_0)[15:13] CLK_DIV Select peripheral clock divider for input filter sampling clock. Reset value:0 // Value 0x7 is reserved. 0 // 0x0 IOCONCLKDIV0. // 0x1 IOCONCLKDIV1. // 0x2 IOCONCLKDIV2. // 0x3 IOCONCLKDIV3. // 0x4 IOCONCLKDIV4. // 0x5 IOCONCLKDIV5. // 0x6 IOCONCLKDIV6. // IOCON(PIO0_0)[31:16] - Reserved. Reset value:0 // LPC_IOCON->PIO0_0 &= ~0x00000000; // **************************** // 2.Define IOCON ( PIO0_1 ) register // **************************** // IOCON(PIO0_1)[2:0] - Reserved. Reset value:0 // IOCON(PIO0_1)[4:3] MODE Selects function mode (on-chip pull-up/pull-down resistor control). Reset value:0b10 // 0x0 Inactive (no pull-down/pull-up resistor enabled). // 0x1 Pull-down resistor enabled. // 0x2 Pull-up resistor enabled. // 0x3 Repeater mode. // IOCON(PIO0_1)[5] HYS Hysteresis. Reset value:0 // 0 Disable. // 1 Enable. // IOCON(PIO0_1)[6] INV Invert input Reset value:0 // 0 Input not inverted (HIGH on pin reads as 1; LOW on pin reads as 0). // 1 Input inverted (HIGH on pin reads as 0, LOW on pin reads as 1). // IOCON(PIO0_1)[9:7] - Reserved. Reset value:0b001 // IOCON(PIO0_1)[10] OD Open-drain mode. Reset value:0 // 0 Disable. // 1 Open-drain mode enabled. Remark: This is not a true open-drain mode. // IOCON(PIO0_1)[12:11] S_MODE Digital filter sample mode. Reset value:0 // 0x0 Bypass input filter. // 0x1 1 clock cycle. Input pulses shorter than one filter clock are rejected. // 0x2 2 clock cycles. Input pulses shorter than two filter clocks are rejected. // 0x3 3 clock cycles. Input pulses shorter than three filter clocks are rejected. // IOCON(PIO0_1)[15:13] CLK_DIV Select peripheral clock divider for input filter sampling clock. Reset value:0 // Value 0x7 is reserved. 0 // 0x0 IOCONCLKDIV0. // 0x1 IOCONCLKDIV1. // 0x2 IOCONCLKDIV2. // 0x3 IOCONCLKDIV3. // 0x4 IOCONCLKDIV4. // 0x5 IOCONCLKDIV5. // 0x6 IOCONCLKDIV6. // IOCON(PIO0_1)[31:16] - Reserved. Reset value:0 LPC_IOCON->PIO0_1 &= ~0x00000018; LPC_IOCON->PIO0_1 |= (0x01<<5); // **************************** // 3.Define IOCON ( PIO0_2 ) register // **************************** // IOCON(PIO0_2)[2:0] - Reserved. 0 // IOCON(PIO0_2)[4:3] MODE Selects function mode (on-chip pull-up/pull-down resistor control). Reset value:0b10 // 0x0 Inactive (no pull-down/pull-up resistor enabled). // 0x1 Pull-down resistor enabled. // 0x2 Pull-up resistor enabled. // 0x3 Repeater mode. // IOCON(PIO0_2)[5] HYS Hysteresis. Reset value:0 // 0 Disable. // 1 Enable. // IOCON(PIO0_2)[6] INV Invert input. Reset value:0 // 0 Input not inverted (HIGH on pin reads as 1; LOW on pin reads as 0). // 1 Input inverted (HIGH on pin reads as 0, LOW on pin reads as 1). // IOCON(PIO0_2)[9:7] - Reserved. Reset value:0b001 // IOCON(PIO0_2)[10] OD Open-drain mode. Reset value:0 // 0 Disable. // 1 Open-drain mode enabled. Remark: This is not a true open-drain mode. // IOCON(PIO0_2)[12:11] S_MODE Digital filter sample mode. Reset value:0 // 0x0 Bypass input filter. // 0x1 1 clock cycle. Input pulses shorter than one filter clock are rejected. // 0x2 2 clock cycles. Input pulses shorter than two filter clocks are rejected. // 0x3 3 clock cycles. Input pulses shorter than three filter clocks are rejected. // IOCON(PIO0_2)[15:13] CLK_DIV Select peripheral clock divider for input filter sampling clock. Reset value:0 // Value 0x7 is reserved. // 0x0 IOCONCLKDIV0. // 0x1 IOCONCLKDIV1. // 0x2 IOCONCLKDIV2. // 0x3 IOCONCLKDIV3. // 0x4 IOCONCLKDIV4. // 0x5 IOCONCLKDIV5. // 0x6 IOCONCLKDIV6. // IOCON(PIO0_2)[31:16] - Reserved. Reset value:0 LPC_IOCON->PIO0_2 &= ~0x00000018; LPC_IOCON->PIO0_2 |= (0x01<<5); // **************************** // 4.Define IOCON ( PIO0_3 ) register // **************************** // IOCON(PIO0_3)[2:0] - Reserved. Reset value:0 // IOCON(PIO0_3)[4:3] MODE Selects function mode (on-chip pull-up/pull-down resistor control). Reset value:0b10 // 0x0 Inactive (no pull-down/pull-up resistor enabled). // 0x1 Pull-down resistor enabled. // 0x2 Pull-up resistor enabled. // 0x3 Repeater mode. // IOCON(PIO0_3)[5] HYS Hysteresis. Reset value:0 // 0 Disable. // 1 Enable. // IOCON(PIO0_3)[6] INV Invert input. Reset value:0 // 0 Input not inverted (HIGH on pin reads as 1; LOW on pin reads as 0). // 1 Input inverted (HIGH on pin reads as 0, LOW on pin reads as 1). // IOCON(PIO0_3)[9:7] - Reserved. Reset value:0b001 // IOCON(PIO0_3)[10] OD Open-drain mode. Reset value:0 // 0 Disable. // 1 Open-drain mode enabled. Remark: This is not a true open-drain mode. // IOCON(PIO0_3)[12:11] S_MODE Digital filter sample mode. Reset value:0 // 0x0 Bypass input filter. // 0x1 1 clock cycle. Input pulses shorter than one filter clock are rejected. // 0x2 2 clock cycles. Input pulses shorter than two filter clocks are rejected. // 0x3 3 clock cycles. Input pulses shorter than three filter clocks are rejected. // IOCON(PIO0_3)[15:13] CLK_DIV Select peripheral clock divider for input filter sampling clock. Reset value:0 // Value 0x7 is reserved. // 0x0 IOCONCLKDIV0. // 0x1 IOCONCLKDIV1. // 0x2 IOCONCLKDIV2. // 0x3 IOCONCLKDIV3. // 0x4 IOCONCLKDIV4. // 0x5 IOCONCLKDIV5. // 0x6 IOCONCLKDIV6. // IOCON(PIO0_3)[31:16] - Reserved. Reset value:0 LPC_IOCON->PIO0_3 &= ~0x00000018; LPC_IOCON->PIO0_3 |= (0x01<<5); // **************************** // 5.Define IOCON ( PIO0_4 ) register // **************************** // IOCON(PIO0_4)[2:0] - Reserved. Reset value:0 // IOCON(PIO0_4)[4:3] MODE Selects function mode (on-chip pull-up/pull-down resistor control). Reset value:0b10 // 0x0 Inactive (no pull-down/pull-up resistor enabled). // 0x1 Pull-down resistor enabled. // 0x2 Pull-up resistor enabled. // 0x3 Repeater mode. // IOCON(PIO0_4)[5] HYS Hysteresis. Reset value:0 // 0 Disable. // 1 Enable. // IOCON(PIO0_4)[6] INV Invert input Reset value:0 // 0 Input not inverted (HIGH on pin reads as 1; LOW on pin reads as 0). // 1 Input inverted (HIGH on pin reads as 0, LOW on pin reads as 1). // IOCON(PIO0_4)[9:7] - Reserved. Reset value:0b001 // IOCON(PIO0_4)[10] OD Open-drain mode. Reset value:0 // 0 Disable. // 1 Open-drain mode enabled. Remark: This is not a true open-drain mode. // IOCON(PIO0_4)[12:11] S_MODE Digital filter sample mode. Reset value:0 // 0x0 Bypass input filter. // 0x1 1 clock cycle. Input pulses shorter than one filter clock are rejected. // 0x2 2 clock cycles. Input pulses shorter than two filter clocks are rejected. // 0x3 3 clock cycles. Input pulses shorter than three filter clocks are rejected. // IOCON(PIO0_4)[15:13] CLK_DIV Select peripheral clock divider for input filter sampling clock.Reset value:0 // Value 0x7 is reserved. // 0x0 IOCONCLKDIV0. // 0x1 IOCONCLKDIV1. // 0x2 IOCONCLKDIV2. // 0x3 IOCONCLKDIV3. // 0x4 IOCONCLKDIV4. // 0x5 IOCONCLKDIV5. // 0x6 IOCONCLKDIV6. // IOCON(PIO0_4)[31:16] - Reserved. Reset value:0 // LPC_IOCON->PIO0_4 = 0x00000000; // **************************** // 6.Define IOCON ( PIO0_5 ) register // **************************** // IOCON(PIO0_5)[2:0] - Reserved. Reset value:0 // IOCON(PIO0_5)[4:3] MODE Selects function mode (on-chip pull-up/pull-down resistor control). Reset value:0b10 // 0x0 Inactive (no pull-down/pull-up resistor enabled). // 0x1 Pull-down resistor enabled. // 0x2 Pull-up resistor enabled. // 0x3 Repeater mode. // IOCON(PIO0_5)[5] HYS Hysteresis. Reset value:0 // 0 Disable. // 1 Enable. // IOCON(PIO0_5)[6] INV Invert input Reset value:0 // 0 Input not inverted (HIGH on pin reads as 1; LOW on pin reads as 0). // 1 Input inverted (HIGH on pin reads as 0, LOW on pin reads as 1). // IOCON(PIO0_5)[9:7] - Reserved. Reset value:0b001 // IOCON(PIO0_5)[10] OD Open-drain mode. Reset value:0 // 0 Disable. // 1 Open-drain mode enabled. Remark: This is not a true open-drain mode. // IOCON(PIO0_5)[12:11] S_MODE Digital filter sample mode. Reset value:0 // 0x0 Bypass input filter. // 0x1 1 clock cycle. Input pulses shorter than one filter clock are rejected. // 0x2 2 clock cycles. Input pulses shorter than two filter clocks are rejected. // 0x3 3 clock cycles. Input pulses shorter than three filter clocks are rejected. // IOCON(PIO0_5)[15:13] CLK_DIV Select peripheral clock divider for input filter sampling clock. Reset value:0 // Value 0x7 is reserved. // 0x0 IOCONCLKDIV0. // 0x1 IOCONCLKDIV1. // 0x2 IOCONCLKDIV2. // 0x3 IOCONCLKDIV3. // 0x4 IOCONCLKDIV4. // 0x5 IOCONCLKDIV5. // 0x6 IOCONCLKDIV6. // IOCON(PIO0_5)[31:16] - Reserved. Reset value:0 // LPC_IOCON->PIO0_5 = 0x00000000; //PIO0_5/RESET (R) } //****************************************************************************************** // Function Name : Init_PIN // Title : // Input : // Output : // Description : //****************************************************************************************** void Init_PIN(void) { // **************************** // 1.Define Pin enable register 0 // **************************** // PINENABLE0[0] ACMP_I1_EN Enables fixed-pin function. // Writing a 1 deselects the function and any movable function can be assigned to this pin. // By default the fixed--pin function is deselected and GPIO is assigned to this pin. // Default value:1 // 0 Enable ACMP_I1. This function is enabled on pin PIO0_0. // 1 Disable ACMP_I1. GPIO function PIO0_0 (default) or any other movable function can be assigned to pin PIO0_0. // PINENABLE0[1] ACMP_I2_EN Enables fixed-pin function. // Writing a 1 deselects the function and any movable function can be assigned to this pin. // By default the fixed-pin function is deselected and GPIO is assigned to this pin. // Functions CLKIN and ACMP_I2 are connected to the same pin PIO0_1. // To use ACMP_I2, disable the CLKIN function in bit 7 of this register and enable ACMP_I2. // Default value:1 // 0 Enable ACMP_I2. This function is enabled on pin PIO0_1. // 1 Disable ACMP_I2. GPIO function PIO0_1 (default) or any other movable function can be assigned to pin PIO0_1. // PINENABLE0[2] SWCLK_EN Enables fixed-pin function. // Writing a 1 deselects the function and any movable function can be assigned to this pin. // This function is selected by default. // Default value:0 // 0 Enable SWCLK. This function is enabled on pin PIO0_3. // 1 Disable SWCLK. GPIO function PIO0_3 is selected on this pin. Any other movable function can be assigned to pin PIO0_3. // PINENABLE0[3] SWDIO_EN Enables fixed-pin function. // Writing a 1 deselects the function and any movable function can be assigned to this pin. // This function is selected by default. // Default value:0 // 0 Enable SWDIO. This function is enabled on pin PIO0_2. // 1 Disable SWDIO. GPIO function PIO0_2 is selected on this pin. Any other movable function can be assigned to pin PIO0_2. // PINENABLE0[4] XTALIN_EN Enables fixed-pin function. // Writing a 1 deselects the function and any movable function can be assigned to this pin. // By default the fixed--pin function is deselected and GPIO is assigned to this pin. // Default value:1 // 0 Enable XTALIN. This function is enabled on pin PIO0_8. // 1 Disable XTALIN. GPIO function PIO0_8 (default) or any other movable function can be assigned to pin PIO0_8. // PINENABLE0[5] XTALOUT_EN Enables fixed-pin function. // Writing a 1 deselects the function and any movable function can be assigned to this pin. // By default the fixed--pin function is deselected and GPIO is assigned to this pin. // Default value:1 // 0 Enable XTALOUT. This function is enabled on pin PIO0_9. // 1 Disable XTALOUT. GPIO function PIO0_9 (default) or any other movable function can be assigned to pin PIO0_9. // PINENABLE0[6] RESET_EN Enables fixed-pin function. // Writing a 1 deselects the function and any movable function can be assigned to this pin. // This function is selected by default. // Default value:0 // 0 Enable RESET. This function is enabled on pin PIO0_5. // 1 Disable RESET. GPIO function PIO0_5 is selected on this pin. Any other movable function can be assigned to pin PIO0_5. // PINENABLE0[7] CLKIN Enables fixed-pin function. // Writing a 1 deselects the function and any movable function can be assigned to this pin. // By default the fixed-pin function is deselected and GPIO is assigned to this pin. // Functions CLKIN and ACMP_I2 are connected to the same pin PIO0_1. // To use CLKIN, disable ACMP_I2 in bit 1 of this register and enable CLKIN. // Default value:1 // 0 Enable CLKIN. This function is enabled on pin PIO0_1. // 1 Disable CLKIN. GPIO function PIO0_1 (default) or any other movable function can be assigned to pin CLKIN. // PINENABLE0[8] VDDCMP Enables fixed-pin function. // Writing a 1 deselects the function and any movable function can be assigned to this pin. // By default the fixed--pin function is deselected and GPIO is assigned to this pin. // Default value:1 // 0 Enable VDDCMP. This function is enabled on pin PIO0_6. // 1 Disable VDDCMP. GPIO function PIO0_6 (default) or any other movable function can be assigned to pin PIO0_6. // PINENABLE0[31:9] - Reserved. LPC_SWM->PINENABLE0 |= 0x0000000C; } //****************************************************************************************** // Function Name : Init_CLK // Title : // Input : // Output : // Description : //****************************************************************************************** void Init_CLK(void) { // **************************** // 1.Define System clock control register // **************************** // SYSAHBCLKCTRL[0] SYS Enables the clock for the AHB, the APB bridge, the Cortex-M0+ core clocks, SYSCON, and the PMU. // This bit is read only and always reads as 1. Reset value :1 // 0 Reserved // 1 Enable // SYSAHBCLKCTRL[1] ROM Enables clock for ROM. Reset value :1 // 0 Disable // 1 Enable // SYSAHBCLKCTRL[2] RAM Enables clock for SRAM. Reset value :1 // 0 Disable // 1 Enable // SYSAHBCLKCTRL[3] FLASHREG Enables clock for flash register interface. Reset value :1 // 0 Disable // 1 Enable // SYSAHBCLKCTRL[4] FLASH Enables clock for flash. Reset value :1 // 0 Disable // 1 Enable // SYSAHBCLKCTRL[5] I2C Enables clock for I2C. Reset value :0 // 0 Disable // 1 Enable // SYSAHBCLKCTRL[6] GPIO Enables clock for GPIO port registers and GPIO pin interrupt registers. Reset value : 0 // 0 Disable // 1 Enable // SYSAHBCLKCTRL[7] SWM Enables clock for switch matrix. Reset value :0 // 0 Disable // 1 Enable // SYSAHBCLKCTRL[8] SCT Enables clock for state configurable timer. Reset value :0 // 0 Disable // 1 Enable // SYSAHBCLKCTRL[9] WKT Enables clock for self wake-up timer. Reset value :0 // 0 Disable // 1 Enable // SYSAHBCLKCTRL[10] MRT Enables clock for multi-rate timer. // 0 Disable // 1 Enable // SYSAHBCLKCTRL[11] SPI0 Enables clock for SPI0. Reset value :0 // 0 Disable // 1 Enable // SYSAHBCLKCTRL[12] SPI1 Enables clock for SPI1. // 0 Disable // 1 Enable // SYSAHBCLKCTRL[13] CRC Enables clock for CRC. Reset value :0 // 0 Disable // 1 Enable // SYSAHBCLKCTRL[14] UART0 Enables clock for USART0. Reset value :0 // 0 Disable // 1 Enable // SYSAHBCLKCTRL[15] UART1 Enables clock for USART1. Reset value :0 // 0 Disable // 1 Enable // SYSAHBCLKCTRL[16] UART2 Enables clock for USART2. Reset value :0 // 0 Disable // 1 Enable // SYSAHBCLKCTRL[17] WWDT Enables clock for WWDT. Reset value :0 // 0 Disable // 1 Enable // SYSAHBCLKCTRL[18] IOCON Enables clock for IOCON block. Reset value :0 // 0 Disable // 1 Enable // SYSAHBCLKCTRL[19] ACMP Enables clock to analog comparator. Reset value :0 // 0 Disable // 1 Enable // SYSAHBCLKCTRL[31:20] - Reserved LPC_SYSCON->SYSAHBCLKCTRL |= ( 0x1 << 0 )|( 0x1 << 10 ); } //****************************************************************************************** // Function Name : Init_PRC // Title : reset control register // Input : // Output : // Description : //****************************************************************************************** void Init_PRC(void) { // **************************** // 1.Define Peripheral reset control register // **************************** // PRESETCTRL[0] SPI0_RST_N SPI0 reset control Reset value :1 // 0 Assert the SPI0 reset. // 1 Clear the SPI0 reset. // PRESETCTRL[1] SPI1_RST_N SPI1 reset control Reset value :1 // 0 Assert the SPI1 reset. // 1 Clear the SPI1 reset. // PRESETCTRL[2] UARTFRG_RST_N USART fractional baud rate generator (UARTFRG) reset control Reset value :1 // 0 Assert the UARTFRG reset. // 1 Clear the UARTFRG reset. // PRESETCTRL[3] USART0_RST_N USART0 reset control Reset value :1 // 0 Assert the USART0 reset. // 1 Clear the USART0 reset. // PRESETCTRL[4] UART1_RST_N USART1 reset control Reset value :1 // 0 Assert the USART reset. // 1 Clear the USART1 reset. // PRESETCTRL[5] UART2_RST_N USART2 reset control Reset value :1 // 0 Assert the USART2 reset. // 1 Clear the USART2 reset. // PRESETCTRL[6] I2C_RST_N I2C reset control Reset value :1 // 0 Assert the I2C reset. // 1 Clear the I2C reset. // PRESETCTRL[7] MRT_RST_N Multi-rate timer (MRT) reset control Reset value :1 // 0 Assert the MRT reset. // 1 Clear the MRT reset. // PRESETCTRL[8] SCT_RST_N SCT reset control Reset value :1 // 0 Assert the SCT reset. // 1 Clear the SCT reset. // PRESETCTRL[9] WKT_RST_N Self wake-up timer (WKT) reset control Reset value :1 // 0 Assert the WKT reset. // 1 Clear the SCT reset. // PRESETCTRL[10] GPIO_RST_N GPIO and GPIO pin interrupt reset control Reset value :1 // 0 Assert the GPIO reset. // 1 Clear the GPIO reset. // PRESETCTRL[11] FLASH_RST_N Flash controller reset control Reset value :1 // 0 Assert the flash controller reset. // 1 Clear the flash controller reset. // PRESETCTRL[12] ACMP_RST_N Analog comparator reset control Reset value :1 // 0 Assert the analog comparator reset. // 1 Clear the analog comparator controller reset. // PRESETCTRL[31:13] - Reserved LPC_SYSCON->PRESETCTRL &= ~(0x1<<7); LPC_SYSCON->PRESETCTRL |= (0x1<<7); } //****************************************************************************************** // Function Name : Init_MRT // Title : // Input : // Output : // Description : System clock:12MHz, Wait timer : 10[mS] //****************************************************************************************** void Init_MRT(void) { // **************************** // 0.Initialize // **************************** G_TIM_COUNTER=0; // **************************** // 1.Define Time interval register // **************************** // INTVAL[0:3][30:0] IVALUE Time interval load value. // This value is loaded into the TIMERn register and the MRTn starts counting down from IVALUE -1. // If the timer is idle, writing a non-zero value to this bit field starts the timer immediately. // If the timer is running, writing a zero to this bit field does the following: // *If LOAD = 1, the timer stops immediately. // *If LOAD = 0, the timer stops at the end of the time interval. // Reset value : 0 // INTVAL[0:3][31] LOAD Determines how the timer interval value IVALUE -1 is loaded into the TIMERn register. // This bit is write-only. // Reading this bit always returns 0. // Reset value : 0 // 0 No force load. The load from the INTVALn register to the TIMERn register is processed at the end of the time interval // if the repeat mode is selected. // 1 Force load. The INTVALn interval value IVALUE -1 is immediately loaded into the TIMERn register while TIMERn is running. // [Examples] // system tick clock frequency : 12MHz, Wait time : 10mS // RELOAD = (system tick clock frequency * 10 ms) -1 // = (12 MHz * 10 ms) -1 = 120000 - 1 // = 119999 = 0x0001D4BF LPC_MRT->Channel[0].INTVAL = 0x0001D4BF; LPC_MRT->Channel[0].INTVAL |= 0x1<<31; // **************************** // 2.Define Timer register (This register is read-only) // **************************** // TIMER[0:3][30:0] VALUE Holds the current timer value of the down-counter. // The initial value of the TIMERn register is loaded as IVALUE - 1 from the INTVALn // register either at the end of the time interval or immediately in the following cases: // INTVALn register is updated in the idle state. // INTVALn register is updated with LOAD = 1. // When the timer is in idle state, reading this bit fields returns -1 // Reset value : 0x00FF FFFF // TIMER[0:3][31] - Reserved. // Reset value : 0 // **************************** // 3.Define Control register // **************************** // CTRL[0:3][0] INTEN Enable the TIMERn interrupt. Reset value : 0 // 0 Disable. // 1 Enable. // CTRL[0:3][2:1] MODE Selects timer mode. Reset value : 0 // 0x0 Repeat interrupt mode. // 0x1 One-shot interrupt mode. // 0x2 Reserved. // 0x3 Reserved. // CTRL[0:3][31:3] - Reserved. Reset value : 0 LPC_MRT->Channel[0].CTRL = (0x00<<1); // **************************** // 4.Define Status register // **************************** // STAT[0:3][0] INTFLAG Monitors the interrupt flag. Reset value : 0 // 0 No pending interrupt. Writing a zero is equivalent to no operation. // 1 Pending interrupt. // The interrupt is pending because TIMERn has reached the end of the time interval. // If the INTEN bit in the CONTROLn is also set to 1, the interrupt for timer channel n and the global interrupt are raised. // Writing a 1 to this bit clears the interrupt request. // STAT[0:3][1] RUN Indicates the state of TIMERn. This bit is read-only. // Reset value : 0 // 0 Idle state. TIMERn is stopped. // 1 Running. TIMERn is running. // STAT[0:3][31:2] - Reserved. Reset value : 0 // **************************** // 5.Define Idle channel register // **************************** // IDLE_CH[3:0] - Reserved. Reset value : 0 // IDLE_CH[7:4] CHAN Idle channel. // Reading the CHAN bits, returns the lowest idle timer channel. // If all timer channels are running, CHAN = 4. // Reset value : 0 // IDLE_CH[31:8] - Reserved. Reset value : 0 // **************************** // 6.Define Global interrupt flag register // **************************** // IRQ_FLAG[0] GFLAG0 Monitors the interrupt flag of TIMER0. Reset value : 0 // 0 No pending interrupt. Writing a zero is equivalent to no operation. // 1 Pending interrupt. // The interrupt is pending because TIMER0 has reached the end of the time interval. // If the INTEN bit in the CONTROL0 register is also set to 1, the interrupt for timer // channel 0 and the global interrupt are raised. // Writing a 1 to this bit clears the interrupt request. // IRQ_FLAG[1] GFLAG1 Monitors the interrupt flag of TIMER1. Reset value : 0 // 0 No pending interrupt. // Writing a zero is equivalent to no operation. // 1 Pending interrupt. The interrupt is pending because TIMER1 has reached the end of the time interval. // If the INTEN bit in the CONTROL1 register is also set to 1, the interrupt for timer // channel 1 and the global interrupt are raised. // Writing a 1 to this bit clears the interrupt request. // IRQ_FLAG[2] GFLAG2 Monitors the interrupt flag of TIMER2. Reset value : 0 // 0 No pending interrupt. Writing a zero is equivalent to no operation. // 1 Pending interrupt. // The interrupt is pending because TIMER2 has reached the end of the time interval. If the INTEN bit in the // CONTROL2 register is also set to 1, the interrupt for timer channel 2 and the global interrupt are raised. // Writing a 1 to this bit clears the interrupt request. // IRQ_FLAG[3] GFLAG3 Monitors the interrupt flag of TIMER3. Reset value : 0 // 0 No pending interrupt. Writing a zero is equivalent to no operation. // 1 Pending interrupt. // The interrupt is pending because TIMER3 has reached the end of the time interval. If the INTEN bit in the // CONTROL3 register is also set to 1, the interrupt for timer channel 3 and the global interrupt are raised. // Writing a 1 to this bit clears the interrupt request. // IRQ_FLAG[31:4] - Reserved. Reset value : 0 // **************************** // 7.Define Nested Vectored Interrupt Controller(NVIC) // **************************** // SPI0_IRQn 0 // SPI1_IRQn 1 // Reserved0_IRQn 2 // UART0_IRQn 3 // UART1_IRQn 4 // UART2_IRQn 5 // Reserved1_IRQn 6 // Reserved2_IRQn 7 // I2C_IRQn 8 // SCT_IRQn 9 // MRT_IRQn 10 // CMP_IRQn 11 // WDT_IRQn 12 // BOD_IRQn 13 // Reserved3_IRQn 14 // WKT_IRQn 15 // Reserved4_IRQn 16 // Reserved5_IRQn 17 // Reserved6_IRQn 18 // Reserved7_IRQn 19 // Reserved8_IRQn 20 // Reserved9_IRQn 21 // Reserved10_IRQn 22 // Reserved11_IRQn 23 // PININT0_IRQn 24 // PININT1_IRQn 25 // PININT2_IRQn 26 // PININT3_IRQn 27 // PININT4_IRQn 28 // PININT5_IRQn 29 // PININT6_IRQn 30 // PININT7_IRQn 31 NVIC->ISER[0] = (1 << ((uint32_t)(MRT_IRQn) & 0x1F)); } //****************************************************************************************** // Function Name : Wait_timer // Title : Wait 10mS // Input : // Output : // Description : //****************************************************************************************** void Wait_timer(unsigned int num) { // 1.Initialized Counter G_TIM_COUNTER = 0; // 2.Start timer LPC_MRT->Channel[0].CTRL |= (0x1<<0); // 3.Timer program while (G_TIM_COUNTER < num); // 4.Stop timer LPC_MRT->Channel[0].CTRL &= ~(0x1<<0) ; return; } //****************************************************************************************** // Function Name : MRT_IRQHandler(void) // Title : // Input : // Output : // Description : MRT interrupt happens //****************************************************************************************** void MRT_IRQHandler(void) { if( LPC_MRT->Channel[0].STAT & (0x1<<0)){ LPC_MRT->Channel[0].STAT = (0x1<<0); // clear interrupt flag G_TIM_COUNTER++; } return; }