*** Blinky example by vilaca
http://vilaca.eu/lpc1114/vilaca.eu.lpc1114_102_led_blink.zip
#define LED (1<<9) /* LED D1 connect to PIO1_9 */
int main(void)
{
LPC_SYSCON ->SYSAHBCLKCTRL |= (1 << 8); // Enable Clock for TMR1
LPC_IOCON ->PIO1_9 |= (1 << 0); // PIN1_9 = CT16B1_MAT0
LPC_TMR16B1 ->MR0 = 2000; // 50% Duty Cycle
LPC_TMR16B1 ->PR = 12000;
LPC_TMR16B1 ->MR3 = 4000; // Cycle Length
LPC_TMR16B1 ->MCR |= (1 << 10); // TC Reset on MR3 Match
LPC_TMR16B1 ->PWMC |= (1 << 0); // PWM Mode
LPC_TMR16B1 ->TCR |= (1 << 0); // GO
while (1);
// unreachable
return 0;
*** Blinky example by uMich
http://web.eecs.umich.edu/~prabal/teaching/eecs373-f10/slides/lec21.pdf
// Set a 10ms timer
void TIMER32_0_IRQHandler(void)
{
LPC_TMR32B0->IR = 1;/* clear
interrupt flag */
timer32_0_counter++;
return;
}
// And loop forever:
while (1) {
/* Each time we wake up... */
/* Check TimeTick to see whether to set or
clear the LED I/O pin */
if ( (timer32_0_counter%LED_TOGGLE_TICKS) <
(LED_TOGGLE_TICKS/2) )
{
GPIOSetValue( LED_PORT, LED_BIT, LED_OFF );
} else {
GPIOSetValue( LED_PORT, LED_BIT, LED_ON );
}
/* Go to sleep to save power between timer
interrupts */
__WFI();
}
*** lpc11xx.h Tiimer typedef ***
typedef struct
{
__IO uint32_t IR; /*!< Offset: 0x000 (R/W) Interrupt Register */
__IO uint32_t TCR; /*!< Offset: 0x004 (R/W) Timer Control Register */
__IO uint32_t TC; /*!< Offset: 0x008 (R/W) Timer Counter Register */
__IO uint32_t PR; /*!< Offset: 0x00C (R/W) Prescale Register */
__IO uint32_t PC; /*!< Offset: 0x010 (R/W) Prescale Counter Register */
__IO uint32_t MCR; /*!< Offset: 0x014 (R/W) Match Control Register */
__IO uint32_t MR0; /*!< Offset: 0x018 (R/W) Match Register 0 */
__IO uint32_t MR1; /*!< Offset: 0x01C (R/W) Match Register 1 */
__IO uint32_t MR2; /*!< Offset: 0x020 (R/W) Match Register 2 */
__IO uint32_t MR3; /*!< Offset: 0x024 (R/W) Match Register 3 */
__IO uint32_t CCR; /*!< Offset: 0x028 (R/W) Capture Control Register */
__I uint32_t CR0; /*!< Offset: 0x02C (R/ ) Capture Register 0 */
uint32_t RESERVED1[3];
__IO uint32_t EMR; /*!< Offset: 0x03C (R/W) External Match Register */
uint32_t RESERVED2[12];
__IO uint32_t CTCR; /*!< Offset: 0x070 (R/W) Count Control Register */
__IO uint32_t PWMC; /*!< Offset: 0x074 (R/W) PWM Control Register */
} LPC_TMR_TypeDef;
*** LPC1114FN28 Pin reference
PIN GPIO AD Timers SPI I2C UART Other
1 PIO0_8 CT16B0_MAT0 MISO0
2 PIO0_9 CT16B0_MAT1 MOSI0
3 PIO0_10 CT16B0_MAT2 SCK0 SWCLK
4 PIO0_11 AD0 CT32B0_MAT3
5 PIO0_5 SDA
6 PIO0_6
7 VDDA
8 VSSA
9 PIO1_0 AD1 CT32B1_CAP0
10 PIO1_1 AD2 CT32B1_MAT0
11 PIO1_2 AD3 CT32B1_MAT1
12 PIO1_3 AD4 CT32B1_MAT2 SWDIO
13 PIO1_4 AD5 CT32B1_MAT3 WAKEUP
14 PIO1_5 CT32B0_CAP0 RTS
15 PIO1_6 CT32B0_MAT0 RXD
16 PIO1_7 CT32B0_MAT1 TXD
17 PIO1_8 CT16B1_CAP0
18 PIO1_9 CT16B1_MAT0
19 XTALOUT
20 XTALIN
21 VDD
22 VSS
23 PIO0_0 RESET
24 PIO0_1 CT32B0_MAT2 CLKOUT
25 PIO0_2 CT16B0_CAP0 SSEL0
26 PIO0_3
27 PIO0_4 SCL
28 PIO0_7 CTS
.END
No comments:
Post a Comment