forked from KeilChris/M487KM_Blinky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlinky.c
77 lines (63 loc) · 1.72 KB
/
Blinky.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "NuMicro.h" // Device header
#include "gpio.h"
#define PLL_CLOCK 192000000
void SYS_Init(void)
{
/* Unlock protected registers */
SYS_UnlockReg();
/* Set XT1_OUT(PF.2) and XT1_IN(PF.3) to input mode */
PF->MODE &= ~(GPIO_MODE_MODE2_Msk | GPIO_MODE_MODE3_Msk);
/* Enable HXT clock (external XTAL 12MHz) */
CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);
/* Wait for HXT clock ready */
CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);
/* Set core clock as PLL_CLOCK from PLL */
CLK_SetCoreClock(PLL_CLOCK);
/* Set PCLK0/PCLK1 to HCLK/2 */
CLK->PCLKDIV = (CLK_PCLKDIV_APB0DIV_DIV2 | CLK_PCLKDIV_APB1DIV_DIV2);
/* Lock protected registers */
SYS_LockReg();
}
static void delay_ms(uint16_t nDelay)
{
uint16_t nIndex;
for (nIndex = 0; nIndex < nDelay; nIndex++)
{
CLK_SysTickDelay(1000); //delay one ms
}
}
/*----------------------------------------------------------------------------
Main function
*----------------------------------------------------------------------------*/
int main(void)
{
/* Init System, peripheral clock and multi-function I/O */
SYS_Init();
#ifdef M487KMCAN
// this is the blinky code for NuMaker-M487KMCAN
GPIO_SetMode(PH, BIT4, GPIO_MODE_OUTPUT);
GPIO_SetMode(PH, BIT5, GPIO_MODE_OUTPUT);
while (1)
{
PH4 = 0;
PH5 = 1;
delay_ms(1000);
PH4 = 1;
PH5 = 0;
delay_ms(1000);
}
#else
// this is the blinky code for NuMaker-PFM-M487
GPIO_SetMode(PH, BIT0, GPIO_MODE_OUTPUT);
GPIO_SetMode(PH, BIT2, GPIO_MODE_OUTPUT);
while (1)
{
PH0 = 0;
PH2 = 1;
delay_ms(1000);
PH0 = 1;
PH2 = 0;
delay_ms(1000);
}
#endif
}