//—————————————————————————-
// Name: LPC810_Blink.c
// Purpose: LED Flasher
// pin #8 set for LED
//—————————————————————————-
#include <stdint.h>//registers used for gpio & systick setup
#define GPIO_NOT (*((volatile unsigned int *)(0xA0002300)))
#define GPIO_DIR (*((volatile unsigned int *)(0xA0002000)))
#define SYSCON_PRESETCTRL (*((volatile unsigned int *)(0x40048004)))
#define SYSCON_SYSAHBCLKCTRL (*((volatile unsigned int *)(0x40048080)))
#define NVIC_ST_CTRL (*((volatile unsigned int *)(0xE000E010)))
#define NVIC_ST_RELOAD (*((volatile unsigned int *)(0xE000E014)))
#define NVIC_ST_CURRENT (*((volatile unsigned int *)(0xE000E018)))
#define SCB_SHP1 (*((volatile unsigned int *)(0xE000ED20)))//our systick interrupt handler
void SysTick_Handler(void) {
GPIO_NOT = (1<<0); //toggle led pin
}https://github.com/taisukef/wakeupeverymin/blob/master/main.c
int main(void) {
//enable AHB clock to the GPIO domain
SYSCON_SYSAHBCLKCTRL |= (1<<6);
//reset gpio peripheral control
SYSCON_PRESETCTRL &= ~(1<<10);
SYSCON_PRESETCTRL |= (1<<10);
//make gpio #0 pin an output (physical pin #8)
GPIO_DIR |= (1<<0);//set systick clock interrupt reload count
NVIC_ST_RELOAD = (1200000UL & 0xFFFFFFUL) – 1;
//set SysTick IRQ to lowest priority
SCB_SHP1 = 0xC0000000;
//reset the counter
NVIC_ST_CURRENT = 0;
//enable the IRQ and go
NVIC_ST_CTRL = 0x07;//loop forever
while(1)
asm(“wfi”); //wait for interrupt
}#include <stdio.h>
#include “LPC8xx.h”
#include “mrt.h”#define LED_LOCATION 2
#define GND_LOCATION 3
#define ISP_LOCATION 1#define LED_ON() (LPC_GPIO_PORT->SET0 = 1 << LED_LOCATION)
#define LED_OFF() (LPC_GPIO_PORT->CLR0 = 1 << LED_LOCATION)#define ISPBTN() (!(LPC_GPIO_PORT->PIN0 & (1 << ISP_LOCATION)))
// deep power down
void deepPowerDown(void) {
// if (LPC_PMU->PCON & 0b100)
// return 1; // error
LPC_PMU->PCON = 3;
SCB->SCR |= 0b100;
asm(“wfi”);
}
void deepPowerDownWithWakuUp(int msec, int usewakeuppin) {
LPC_PMU->DPDCTRL = usewakeuppin ? 0b1100 : 0b1110;
LPC_PMU->PCON = 3;
SCB->SCR |= 0b100;
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 9); // enable WKT
LPC_WKT->CTRL = 0b111;
LPC_WKT->COUNT = msec * 10;
asm(“wfi”);
}void init() {
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 7); // enable SWM
// LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 18); // enabel UART// pin config
LPC_SWM->PINASSIGN0 = 0xffff0004UL; // U0_TXD, U0_RXD
LPC_SWM->PINENABLE0 = 0xffffffbfUL;LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 6); // enable GPIO
LPC_SYSCON->PRESETCTRL &= ~(1 << 10); // GPIO reset
LPC_SYSCON->PRESETCTRL |= (1 << 10); //LPC_GPIO_PORT->DIR0 |= 1 << GND_LOCATION;
LPC_GPIO_PORT->CLR0 = 1 << GND_LOCATION;LPC_GPIO_PORT->DIR0 |= 1 << LED_LOCATION;
LPC_GPIO_PORT->CLR0 = 1 << LED_LOCATION;mrtInit(__SYSTEM_CLOCK / 1000); // multi-rate timer for 1ms
}
int main() {
init();
mrtDelay(100);
deepPowerDownWithWakuUp(60 * 1000, 0); // wake up after 30sec, disable wake up pin
}
↧
LPC810 Code
↧