Skip to content

Instantly share code, notes, and snippets.

@xiupos
Created March 20, 2017 01:47
Show Gist options
  • Save xiupos/9c7b25649571d4993eb0ef65ffe1d344 to your computer and use it in GitHub Desktop.
Save xiupos/9c7b25649571d4993eb0ef65ffe1d344 to your computer and use it in GitHub Desktop.
Delay Library (SysTick) for LPC810
#include "LPC8xx.h"
#include "delay_st.h"
int main(void) {
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7);
LPC_SWM->PINENABLE0 = 0xffffffbfUL;
LPC_GPIO_PORT->DIR0 |= (1<<2);
delay_init();
while(1) {
LPC_GPIO_PORT->NOT0 |= (1<<2);
delay(500);
}
return 0 ;
}
/*
* delay_st.c
*
* Created on: 2017/03/20
* Author: ha2zakura
* http://ktrikms.blog.jp/
*/
#include "LPC8xx.h"
#include "delay_st.h"
volatile uint32_t count = 0;
void SysTick_Handler(void)
{
count++;
}
void delay_init(void)
{
SysTick->LOAD = 6000 - 18;
SysTick->VAL = 0;
}
void delay(uint32_t ms)
{
SysTick->CTRL = (1 << 0) | (1 << 1);
while(count != ms){}
SysTick->CTRL = (0 << 0) | (0 << 1);
count = 0;
}
/*
* delay_st.h
*
* Created on: 2017/03/20
* Author: ha2zakura
* http://ktrikms.blog.jp/
*/
#ifndef DELAY_ST_H_
#define DELAY_ST_H_
#ifdef __cplusplus
extern "C" {
#endif
void SysTick_Handler(void);
void delay_init(void);
void delay(uint32_t ms);
#ifdef __cplusplus
}
#endif
#endif /* DELAY_ST_H_ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment