Target device - LPC1114x301
Flash setting = Cortex-M/R J-LINK/J-TRACE
Flash device size - LPC11xx/13xx IAP 32kB Flash
*** LED Testing ***
#include "lpc1114.h"
#include "typedef.h"
#define LED1 (1 << 4)
#define LED2 (1 << 5)
#define LED3 (1 << 6)
#define LED4 (1 << 7)
void Delay (uint32 nCount)
{
for(; nCount != 0; nCount--);
}
void led_on(uint32 num)
{
GPIO2DATA_ALL &= ~num;
}
void gpio_dir_set(uint32 num)
{
GPIO2DIR |= num;
}
void led_off(uint32 num)
{
GPIO2DATA_ALL |= num;
}
*** Key Test ***
#include "lpc1114.h"
#include "typedef.h"
#define LED1 (1 << 9) //PIO1_9
#define LED2 (1 << 10) //PIO1_10
#define KEY1 (1 << 0) //PIO1_0
#define KEY2 (1 << 1) //PIO1_1
void led_on(uint32 num)
{
GPIO1DATA_ALL &= ~num;
}
void gpio_dir_set(uint32 num)
{
GPIO1DIR |= num;
}
void led_off(uint32 num)
{
GPIO1DATA_ALL |= num;
}
int main(void)
{
gpio_dir_set( LED1 | LED2 );
led_off( LED1 | LED2 );
while(1)
{
if( (GPIO1DATA_ALL & KEY1) != KEY1 )
{
led_on( LED1 | LED2 );
}
if( (GPIO1DATA_ALL & KEY2) != KEY2 )
{
led_off( LED1 | LED2 );
}
}
}
#include <LPC11xx.h> /* LPC11xx Peripheral Registers */
#include "system_LPC11xx.h"
#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;
}
No comments:
Post a Comment