Louie NRT Story

[Firmware] M058 - gpio_output/input 본문

스마트홈

[Firmware] M058 - gpio_output/input

hyeok0724.kim@gmail.com 2019. 5. 3. 15:13
반응형

[설명]

- P3.2의 pin에 switch를 연결하고 P0.3에 LED를 연결함

- switch를 On/Off에 따라 LED가 켜지고 꺼짐

 

[기본코드]

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
#include <stdio.h>
#include "M051Series.h"
 
#define PLL_CLOCK           50000000
 
void SYS_Init(void)
{
    /*---------------------------------------------------------------------------------------------------------*/
    /* Init System Clock                                                                                       */
    /*---------------------------------------------------------------------------------------------------------*/
    /* Enable Internal RC 22.1184MHz clock */
    CLK_EnableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);
 
    /* Waiting for Internal RC clock ready */
    CLK_WaitClockReady(CLK_CLKSTATUS_OSC22M_STB_Msk);
 
    /* Switch HCLK clock source to Internal RC and HCLK source divide 1 */
    CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));
 
    /* Set core clock as PLL_CLOCK from PLL */
    CLK_SetCoreClock(PLL_CLOCK);
 
    /* Enable UART module clock */
    CLK_EnableModuleClock(UART0_MODULE);
 
    /* Select UART module clock source */
    CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_PLL, CLK_CLKDIV_UART(1));
    /*---------------------------------------------------------------------------------------------------------*/
    /* Init I/O Multi-function                                                                                 */
    /*---------------------------------------------------------------------------------------------------------*/
    /* Set P3 multi-function pins for UART0 RXD and TXD */
    SYS->P3_MFP &= ~(SYS_MFP_P30_Msk | SYS_MFP_P31_Msk);
    SYS->P3_MFP |= (SYS_MFP_P30_RXD;
}
 
int main(void)
{
    /* Unlock protected registers */
    SYS_UnlockReg();
 
    /* Init System, peripheral clock and multi-function I/O */
    SYS_Init();
 
    /* Lock protected registers */
    SYS_LockReg();
 
    /* Init UART0 for printf */
    UART0_Init();
    
    GPIO_SetMode(P0, BIT3, GPIO_PMD_OUTPUT); //Water LED
    P03 = 0;
 
    GPIO_SetMode(P3, BIT2, GPIO_PMD_INPUT); //Timer Switch
    
    while(1)
    {
        if(P32 != 1)
        {
            P03 = 1;
        }
        else
        {
            P03 = 0;
        }
    }
}
 

 

반응형
Comments