typedef struct { __IO uint32_t PIO2_6; /*!< Offset: 0x000 I/O configuration for pin PIO2_6 (R/W) */ uint32_t RESERVED0[1]; __IO uint32_t PIO2_0; /*!< Offset: 0x008 I/O configuration for pin PIO2_0/DTR/SSEL1 (R/W) */ __IO uint32_t RESET_PIO0_0; /*!< Offset: 0x00C I/O configuration for pin RESET/PIO0_0 (R/W) */ __IO uint32_t PIO0_1; /*!< Offset: 0x010 I/O configuration for pin PIO0_1/CLKOUT/CT32B0_MAT2 (R/W) */ __IO uint32_t PIO1_8; /*!< Offset: 0x014 I/O configuration for pin PIO1_8/CT16B1_CAP0 (R/W) */ uint32_t RESERVED1[1]; __IO uint32_t PIO0_2; /*!< Offset: 0x01C I/O configuration for pin PIO0_2/SSEL0/CT16B0_CAP0 (R/W) */ __IO uint32_t PIO2_7; /*!< Offset: 0x020 I/O configuration for pin PIO2_7 (R/W) */ __IO uint32_t PIO2_8; /*!< Offset: 0x024 I/O configuration for pin PIO2_8 (R/W) */ __IO uint32_t PIO2_1; /*!< Offset: 0x028 I/O configuration for pin PIO2_1/nDSR/SCK1 (R/W) */ __IO uint32_t PIO0_3; /*!< Offset: 0x02C I/O configuration for pin PIO0_3 (R/W) */ __IO uint32_t PIO0_4; /*!< Offset: 0x030 I/O configuration for pin PIO0_4/SCL (R/W) */ __IO uint32_t PIO0_5; /*!< Offset: 0x034 I/O configuration for pin PIO0_5/SDA (R/W) */ __IO uint32_t PIO1_9; /*!< Offset: 0x038 I/O configuration for pin PIO1_9/CT16B1_MAT0 (R/W) */ __IO uint32_t PIO3_4; /*!< Offset: 0x03C I/O configuration for pin PIO3_4 (R/W) */ __IO uint32_t PIO2_4; /*!< Offset: 0x040 I/O configuration for pin PIO2_4 (R/W) */ __IO uint32_t PIO2_5; /*!< Offset: 0x044 I/O configuration for pin PIO2_5 (R/W) */ __IO uint32_t PIO3_5; /*!< Offset: 0x048 I/O configuration for pin PIO3_5 (R/W) */ __IO uint32_t PIO0_6; /*!< Offset: 0x04C I/O configuration for pin PIO0_6/SCK0 (R/W) */ __IO uint32_t PIO0_7; /*!< Offset: 0x050 I/O configuration for pin PIO0_7/nCTS (R/W) */ __IO uint32_t PIO2_9; /*!< Offset: 0x054 I/O configuration for pin PIO2_9 (R/W) */ __IO uint32_t PIO2_10; /*!< Offset: 0x058 I/O configuration for pin PIO2_10 (R/W) */ __IO uint32_t PIO2_2; /*!< Offset: 0x05C I/O configuration for pin PIO2_2/DCD/MISO1 (R/W) */ __IO uint32_t PIO0_8; /*!< Offset: 0x060 I/O configuration for pin PIO0_8/MISO0/CT16B0_MAT0 (R/W) */ __IO uint32_t PIO0_9; /*!< Offset: 0x064 I/O configuration for pin PIO0_9/MOSI0/CT16B0_MAT1 (R/W) */ __IO uint32_t SWCLK_PIO0_10; /*!< Offset: 0x068 I/O configuration for pin SWCLK/PIO0_10/SCK0/CT16B0_MAT2 (R/W) */ __IO uint32_t PIO1_10; /*!< Offset: 0x06C I/O configuration for pin PIO1_10/AD6/CT16B1_MAT1 (R/W) */ __IO uint32_t PIO2_11; /*!< Offset: 0x070 I/O configuration for pin PIO2_11/SCK0 (R/W) */ __IO uint32_t R_PIO0_11; /*!< Offset: 0x074 I/O configuration for pin TDI/PIO0_11/AD0/CT32B0_MAT3 (R/W) */ __IO uint32_t R_PIO1_0; /*!< Offset: 0x078 I/O configuration for pin TMS/PIO1_0/AD1/CT32B1_CAP0 (R/W) */ __IO uint32_t R_PIO1_1; /*!< Offset: 0x07C I/O configuration for pin TDO/PIO1_1/AD2/CT32B1_MAT0 (R/W) */ __IO uint32_t R_PIO1_2; /*!< Offset: 0x080 I/O configuration for pin nTRST/PIO1_2/AD3/CT32B1_MAT1 (R/W) */ __IO uint32_t PIO3_0; /*!< Offset: 0x084 I/O configuration for pin PIO3_0/nDTR (R/W) */ __IO uint32_t PIO3_1; /*!< Offset: 0x088 I/O configuration for pin PIO3_1/nDSR (R/W) */ __IO uint32_t PIO2_3; /*!< Offset: 0x08C I/O configuration for pin PIO2_3/RI/MOSI1 (R/W) */ __IO uint32_t SWDIO_PIO1_3; /*!< Offset: 0x090 I/O configuration for pin SWDIO/PIO1_3/AD4/CT32B1_MAT2 (R/W) */ __IO uint32_t PIO1_4; /*!< Offset: 0x094 I/O configuration for pin PIO1_4/AD5/CT32B1_MAT3 (R/W) */ __IO uint32_t PIO1_11; /*!< Offset: 0x098 I/O configuration for pin PIO1_11/AD7 (R/W) */ __IO uint32_t PIO3_2; /*!< Offset: 0x09C I/O configuration for pin PIO3_2/nDCD (R/W) */ __IO uint32_t PIO1_5; /*!< Offset: 0x0A0 I/O configuration for pin PIO1_5/nRTS/CT32B0_CAP0 (R/W) */ __IO uint32_t PIO1_6; /*!< Offset: 0x0A4 I/O configuration for pin PIO1_6/RXD/CT32B0_MAT0 (R/W) */ __IO uint32_t PIO1_7; /*!< Offset: 0x0A8 I/O configuration for pin PIO1_7/TXD/CT32B0_MAT1 (R/W) */ __IO uint32_t PIO3_3; /*!< Offset: 0x0AC I/O configuration for pin PIO3_3/nRI (R/W) */ __IO uint32_t SCK_LOC; /*!< Offset: 0x0B0 SCK pin location select Register (R/W) */ __IO uint32_t DSR_LOC; /*!< Offset: 0x0B4 DSR pin location select Register (R/W) */ __IO uint32_t DCD_LOC; /*!< Offset: 0x0B8 DCD pin location select Register (R/W) */ __IO uint32_t RI_LOC; /*!< Offset: 0x0BC RI pin location Register (R/W) */ __IO uint32_t CT16B0_CAP0_LOC; /*!< Offset: 0x0C0 IOCON CT16B0_CAP0 location register (IOCON_CT16B0_CAP0_LOC, address 0x4004 40C0) */ __IO uint32_t SCK1_LOC; /*!< Offset: 0x0C4 IOCON SCK1 location register (IOCON_SCK1_LOC, address 0x4004 40C4) */ __IO uint32_t MISO1_LOC; /*!< Offset: 0x0C8 IOCON MISO1 location register (IOCON_MISO1_LOC, address 0x4004 40C8) */ __IO uint32_t MOSI1_LOC; /*!< Offset: 0x0CC IOCON MOSI1 location register (IOCON_MOSI1_LOC, address 0x4004 40CC) */ __IO uint32_t CT32B0_CAP0_LOC; /*!< Offset: 0x0D0 IOCON CT32B0_CAP0 location register (IOCON_CT32B0_CAP0_LOC, address 0x4004 40D0) */ __IO uint32_t RXD_LOC; /*!< Offset: 0x0D4 IOCON RXD location register (IOCON_RXD_LOC, address 0x4004 40D4) */ } LPC_IOCON_TypeDef; |
LPC_IOCON->CT32B0_CAP0_LOC = 1; |
#include "driver_config.h" #include "target_config.h" uint32_t timeTick = 0; uint32_t stopTick = 0; void TIMER32_0_IRQHandler(void) { //overflow if(LPC_TMR32B0->IR & 0x1) { LPC_TMR32B0->IR = 0x1; } //CAP1 if(LPC_TMR32B0->IR & (1 << 5)) { LPC_TMR32B0->IR = (1 << 5); } //CAP0 if (LPC_TMR32B0->IR & (1 << 4)) { LPC_TMR32B0->IR = (1 << 4); } } int main(void) { LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6); LPC_SYSCON->SYSAHBCLKCTRL |= (1<<9); LPC_IOCON->PIO2_11 = 0x2 << 0 | 0x0 << 3 | (1<<5) | 0 << 10; LPC_IOCON->PIO2_9 = 0x1 << 0 | 0x0 << 3 | (1<<5) | 0 << 10; LPC_IOCON->PIO1_5 = 0x2 << 0 | 0x0 << 3 | (1<<5) | 0 << 10; LPC_TMR32B0->CCR = 0b101101; LPC_TMR32B0->CTCR = 0x2 << 5 | 0x1 << 4; LPC_TMR32B0->MR0 = SystemCoreClock; LPC_TMR32B0->MCR = 0b001;/* Interrupt on MR0 */ NVIC_EnableIRQ(TIMER_32_0_IRQn); LPC_TMR32B0->TCR = 1; while (1) /* Loop forever */ { __WFI(); } } |
RawData.lygis[1] = GetGPIOBit(2,11); RawData.lygis[0] = GetGPIOBit(2,9); |
void Timer32InterrupterInit() { LPC_SYSCON->SYSAHBCLKCTRL |= (1<<9); //P2_11, input, hysteresis, passive, CAP1 function SetupGPIO(2, 11, 0, 0b111 << 0 | 0b11 << 3 | (1<<5) | 1 << 10, 0x2 << 0 | 0x0 << 3 | (1<<5) | 0 << 10); //P2_11, input, hysteresis, passive, CAP0 function SetupGPIO(2, 9, 0, 0b111 << 0 | 0b11 << 3 | (1<<5) | 1 << 10, 0x1 << 0 | 0x0 << 3 | (1<<5) | 0 << 10); //CAP0/1 rising edge should trigger interrupt and write TC to CR0/1 LPC_TMR32B0->CCR = 0b101101; //reset timer on rising edge of CAP1 LPC_TMR32B0->CTCR = 0x2 << 5 | 0x1 << 4; //in case of overflow LPC_TMR32B0->MR0 = INTERRUPTER_TIMEOUT; LPC_TMR32B0->MCR = 0b001;/* Interrupt and Reset on MR0 */ NVIC_EnableIRQ(TIMER_32_0_IRQn); LPC_TMR32B0->TCR = 1; return; } |
void TIMER32_0_IRQHandler(void) { RawData.lygis[1] = GetGPIOBit(2,11); RawData.lygis[0] = GetGPIOBit(2,9); if(LPC_TMR32B0->IR & 0x1) { LPC_TMR32B0->IR = 0x1; } if(LPC_TMR32B0->IR & (1 << (4 + 1))) { LPC_TMR32B0->IR = (1 << (4 + INTERRUPTER_A_CAP)); } if (LPC_TMR32B0->IR & (1 << (4 + INTERRUPTER_B_CAP))) { LPC_TMR32B0->IR = (1 << (4 + INTERRUPTER_B_CAP)); } } |