国产成人av人人爽人人澡-亚洲国产日韩欧美一区-好吊日视频这里只有精品-日本高清精品视频在线

您好,歡迎進入深圳市穎特新科技有限公司官方網(wǎng)站!

您現(xiàn)在的位置:首頁 新聞資訊 >> 新聞頭條 >> M451例程講解之按鍵
新聞資訊
NEWS INFORMATION

M451例程講解之按鍵

關(guān)鍵字:M451 發(fā)布時間:2019-05-22
/**************************************************************************//**
 * @file     main.c
 * @version  V3.00
 * $Revision: 3 $
 * $Date: 15/09/02 10:03a $
 * @brief    Demonstrate how to set GPIO pin mode and use pin data input/output control.
 * @note
 * Copyright (C) 2013~2015 Nuvoton Technology Corp. All rights reserved.
 *
 ******************************************************************************/
#include "stdio.h"
#include "M451Series.h"
#include "NuEdu-Basic01.h"

#define PLL_CLOCK       72000000


void SYS_Init(void)
{
    /*---------------------------------------------------------------------------------------------------------*/
    /* Init System Clock                                                                                       */
    /*---------------------------------------------------------------------------------------------------------*/

    /* Enable HIRC clock (Internal RC 22.1184MHz) */
    CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);

    /* Wait for HIRC clock ready */
    CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);

    /* Select HCLK clock source as HIRC and and HCLK clock divider as 1 */
    CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));

    /* 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);

    /* Enable UART module clock */
    CLK_EnableModuleClock(UART0_MODULE);

    /* Select UART module clock source as HXT and UART module clock divider as 1 */
    CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UARTSEL_HXT, CLK_CLKDIV0_UART(1));

    /*---------------------------------------------------------------------------------------------------------*/
    /* Init I/O Multi-function                                                                                 */
    /*---------------------------------------------------------------------------------------------------------*/

    /* Set PD multi-function pins for UART0 RXD(PD.6) and TXD(PD.1) */
    SYS->GPD_MFPL &= ~(SYS_GPD_MFPL_PD6MFP_Msk | SYS_GPD_MFPL_PD1MFP_Msk);
    SYS->GPD_MFPL |= (SYS_GPD_MFPL_PD6MFP_UART0_RXD | SYS_GPD_MFPL_PD1MFP_UART0_TXD);

}

void UART0_Init()
{
    /*---------------------------------------------------------------------------------------------------------*/
    /* Init UART                                                                                               */
    /*---------------------------------------------------------------------------------------------------------*/
    /* Reset UART module */
    SYS_ResetModule(UART0_RST);

    /* Configure UART0 and set UART0 baud rate */
    UART_Open(UART0, 115200);
}

/*---------------------------------------------------------------------------------------------------------*/
/*  Main Function                                                                                          */
/*---------------------------------------------------------------------------------------------------------*/
int32_t 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();

    printf("Key1 ~ Key4 detection:\n");

    Open_Seven_Segment();
    Initial_Key_Input();
    while(1)
    {
            
            if(Get_Key_Input()&0XFF)
            {
            if(Get_Key_Input()&0x01)
            {
            Show_Seven_Segment(0,1);
            }
            if(Get_Key_Input()&0x02)
            {
            Show_Seven_Segment(2,1);
            }
            if(Get_Key_Input()&0x04)
            {
            Show_Seven_Segment(4,1);
            }
            if(Get_Key_Input()&0x08)
            {
            Show_Seven_Segment(8,1);
            }
            
            }
        
            
            
            //Show_Seven_Segment(Get_Key_Input(), 1);
            
            
    }

}

這是我設(shè)計的一個小程序基于M451的庫函數(shù),可以下載到板子上試一試,努力去學(xué)習(xí)思考,反復(fù)驗證,

當(dāng)SW1按上時,B1出電壓為零。

我在把庫函數(shù)貼出來

#include <stdio.h>
#include "M451Series.h"
#include "NuEdu-Basic01_Button.h"
#define KEY1 PE2
#define KEY2 PA8
#define KEY3 PB6
#define KEY4 PB7
void Initial_Key_Input(void)
{
    GPIO_SetMode(PE, BIT2, GPIO_MODE_INPUT);//設(shè)為輸入
    GPIO_SetMode(PA, BIT8,  GPIO_MODE_INPUT);
    GPIO_SetMode(PB, BIT6, GPIO_MODE_INPUT);
    GPIO_SetMode(PB, BIT7, GPIO_MODE_INPUT);
}

unsigned char Get_Key_Input(void)
{
    unsigned char temp = 0;
    if(KEY1 == 0)
        temp |= 0x1;


    if(KEY2 == 0)
        temp |= 0x2;


    if(KEY3 == 0)
        temp |= 0x4;


    if(KEY4 == 0)
        temp |= 0x8;

    return   temp;
}
/**************************************************************************//**
 * @file     NuEdu-Basic01_7_Segment.c
 * @version  V3.00
 * $Revision: 4 $
 * $Date: 15/09/02 10:02a $
 * @brief    M451 series NuEdu Basic01 7-Segment driver source file
 *
 * @note
 * Copyright (C) 2014~2015 Nuvoton Technology Corp. All rights reserved.
*****************************************************************************/

#include <stdio.h>
#include "M451Series.h"
#include "NuEdu-Basic01_7_Segment.h"

#ifdef __cplusplus
extern "C"
{
#endif

/** @addtogroup M451_Device_Driver M451 Device Driver
  @{
*/

/** @addtogroup NuEdu-Basic01_7_Segment Driver
  @{
*/


/** @addtogroup NuEdu-Basic01_7_Segment Exported Functions
  @{
*/


/**
  * @brief  Configure the 7-Segment module
  *
  * @param[in]  None
  *
  * @return     None
  *
  * @details    Configure GPIOs of 7-Segment as output mode and turn off all 7-Segement..
  */
void Open_Seven_Segment(void)
{
    GPIO_SetMode(PB, BIT11, GPIO_MODE_OUTPUT);//設(shè)為輸出
    GPIO_SetMode(PB, BIT12, GPIO_MODE_OUTPUT);
    GPIO_SetMode(PB, BIT13, GPIO_MODE_OUTPUT);
    GPIO_SetMode(PB, BIT14, GPIO_MODE_OUTPUT);
    GPIO_SetMode(PB, BIT15, GPIO_MODE_OUTPUT);
    GPIO_SetMode(PB, BIT5, GPIO_MODE_OUTPUT);
    GPIO_SetMode(PD, BIT11, GPIO_MODE_OUTPUT);
    GPIO_SetMode(PF, BIT2, GPIO_MODE_OUTPUT);
    GPIO_SetMode(PD, BIT8, GPIO_MODE_OUTPUT);
    GPIO_SetMode(PC, BIT8, GPIO_MODE_OUTPUT);

    SEG_A_OFF;
    SEG_B_OFF;
    SEG_C_OFF;
    SEG_D_OFF;
    SEG_E_OFF;
    SEG_F_OFF;
    SEG_G_OFF;
    SEG_H_OFF;
}


/**
  * @brief  Show number at 7-Segment module
  *
  * @param[in]  no The number that will be showed at the specified 7-Segment module.
  * @param[in]  number The group number of the specified 7-Segment module.
  *
  * @return     None
  *
  * @details    Configure GPIOs of 7-Segment to show number at 7-Segment module 
  */
void Show_Seven_Segment(unsigned char no, unsigned char number)
{
    SEG_A_OFF;
    SEG_B_OFF;
    SEG_C_OFF;
    SEG_D_OFF;
    SEG_E_OFF;
    SEG_F_OFF;
    SEG_G_OFF;
    SEG_H_OFF;
    SEG_CONTROL1_OFF;
    SEG_CONTROL2_OFF;
    switch(no)
    {
        //show 0
        case 0:
            SEG_A_ON;
            SEG_B_ON;
            SEG_C_ON;
            SEG_D_ON;
            SEG_E_ON;
            SEG_F_ON;

            break;

        //show 1
        case 1:
            SEG_B_ON;
            SEG_C_ON;
            break;

        //show 2
        case 2:
            SEG_A_ON;
            SEG_B_ON;
            SEG_G_ON;
            SEG_E_ON;
            SEG_D_ON;
            break;

        //show 3
        case 3:
            SEG_A_ON;
            SEG_B_ON;
            SEG_G_ON;
            SEG_C_ON;
            SEG_D_ON;
            break;

        //show 4
        case 4:
            SEG_F_ON;
            SEG_B_ON;
            SEG_G_ON;
            SEG_C_ON;
            break;

        //show 5
        case 5:
            SEG_A_ON;
            SEG_F_ON;
            SEG_G_ON;
            SEG_C_ON;
            SEG_D_ON;
            break;

        //show 6
        case 6:
            SEG_A_ON;
            SEG_F_ON;
            SEG_E_ON;
            SEG_G_ON;
            SEG_C_ON;
            SEG_D_ON;
            break;

        //show 7
        case 7:
            SEG_A_ON;
            SEG_B_ON;
            SEG_C_ON;
            SEG_F_ON;
            break;

        //show 8
        case 8:
            SEG_A_ON;
            SEG_B_ON;
            SEG_C_ON;
            SEG_D_ON;
            SEG_E_ON;
            SEG_F_ON;
            SEG_G_ON;
            break;

        //show 9
        case 9:
            SEG_A_ON;
            SEG_B_ON;
            SEG_C_ON;
            SEG_F_ON;
            SEG_G_ON;
            break;
    }

    switch(number)
    {
        case 1:
            SEG_CONTROL1_ON;
            break;

        //show 1
        case 2:
            SEG_CONTROL2_ON;
            break;
    }
}


/*@}*/ /* end of group NuEdu-Basic01_7_Segment_EXPORTED_FUNCTIONS */

/*@}*/ /* end of group NuEdu-Basic01_7_Segment_Driver */

/*@}*/ /* end of group M451_Device_Driver */

#ifdef __cplusplus
}
#endif

/*** (C) COPYRIGHT 2014~2015 Nuvoton Technology Corp. ***/

多看看庫函數(shù),對你的編程有很大的提高

/*---------------------------------------------------------------------------------------------------------*/
/* 7-Segment GPIO constant definitions                                                                           */
/*---------------------------------------------------------------------------------------------------------*/
#define SEG_A_ON            PB11=0    /*!< 7_Segment setting for turning on 7-Segment A. */
#define SEG_B_ON            PB12=0    /*!< 7_Segment setting for turning on 7-Segment B. */
#define SEG_C_ON            PB13=0    /*!< 7_Segment setting for turning on 7-Segment C. */
#define SEG_D_ON            PB14=0    /*!< 7_Segment setting for turning on 7-Segment D. */
#define SEG_E_ON            PB15=0    /*!< 7_Segment setting for turning on 7-Segment E. */
#define SEG_F_ON            PB5=0    /*!< 7_Segment setting for turning on 7-Segment F. */
#define SEG_G_ON            PD11=0    /*!< 7_Segment setting for turning on 7-Segment G. */
#define SEG_H_ON            PF2=0    /*!< 7_Segment setting for turning on 7-Segment H. */
#define SEG_CONTROL1_ON        PD8=1    /*!< 7_Segment setting for turning on 7-Segment C1. */
#define SEG_CONTROL2_ON        PC8=1    /*!< 7_Segment setting for turning on 7-Segment C2. */


#define SEG_A_OFF            PB11=1    /*!< 7_Segment setting for turning off 7-Segment A. */
#define SEG_B_OFF            PB12=1    /*!< 7_Segment setting for turning off 7-Segment B. */
#define SEG_C_OFF            PB13=1    /*!< 7_Segment setting for turning off 7-Segment C. */
#define SEG_D_OFF            PB14=1    /*!< 7_Segment setting for turning off 7-Segment D. */
#define SEG_E_OFF            PB15=1    /*!< 7_Segment setting for turning off 7-Segment E. */
#define SEG_F_OFF            PB5=1    /*!< 7_Segment setting for turning off 7-Segment F. */
#define SEG_G_OFF            PD11=1    /*!< 7_Segment setting for turning off 7-Segment G. */
#define SEG_H_OFF            PF2=1    /*!< 7_Segment setting for turning off 7-Segment H. */
#define SEG_CONTROL1_OFF    PD8=0    /*!< 7_Segment setting for turning off 7-Segment C1. */
#define SEG_CONTROL2_OFF    PC8=0    /*!< 7_Segment setting for turning off 7-Segment C2. */

按鍵設(shè)為輸入,斷碼管設(shè)為輸出。

 

輕觸開關(guān)的功能分為兩種:一個是常開型、一種是常閉型。最為常見的是常開型,常開型是指線路一般為斷開,輕按按鍵柄觸動彈片和底座的炮點接觸,這時開關(guān)視為導(dǎo)通,放開按鍵柄彈片和炮點分開,這時開關(guān)視為分開,產(chǎn)品的性能為OK。線路斷開時兩路的阻值為30m歐,當(dāng)開關(guān)導(dǎo)通時兩路的接觸電阻0,這時開關(guān)性能就是非常好的。常閉型是比較少見的,因為這樣比較不符合常規(guī)的產(chǎn)品設(shè)計,常閉型是指正常情況下開關(guān)是導(dǎo)通的,當(dāng)觸動開關(guān)的時候,線路和功能都是為斷開的。這種開關(guān)的阻值就是和常開的相反,所以一般不推薦使用。下圖都是常開輕觸開關(guān):

 

 

不論是常開型還是常閉輕觸開關(guān)必須由兩個引腳以上組成,這樣才能形成一組開關(guān)功能,正常為兩腳、四腳、五腳。為什么會有五腳開關(guān)的呢?因第五只腳是用來接地的,接地腳是用來干嘛的我想大家都知道。當(dāng)然還有三個腳的,一般三腳都是側(cè)壓的比較多,這個第三只腳就是為了固定設(shè)計的,所以大家可以放心使用,使勁的去按壓都是沒有問題的。下圖中兩腳線路我們一款就一目了然了,我來解釋一下輕觸開關(guān)的四個引腳是怎么接的吧!正常情況下1和2為一組導(dǎo)通,3和4為一組導(dǎo)通,當(dāng)觸動開關(guān)的時候的1和3為一組,2和4為一組,按照這樣的方式來設(shè)計開關(guān)的功能就是對的了。

聯(lián)系方式0755-82591179

傳真:0755-82591176

郵箱:vicky@yingtexin.net

地址:深圳市龍華區(qū)民治街道民治大道973萬眾潤豐創(chuàng)業(yè)園A棟2樓A08

中文字幕一二区在线观看| 日韩色婷婷综合在线观看| 日韩黄片大全免费在线看| 日韩精品小视频在线观看| 超薄丝袜足一区二区三区| 亚洲国产成人一区二区在线观看| 夜色福利久久精品福利| 色一欲一性一乱—区二区三区| 中文字幕一区二区熟女| 国产一级二级三级观看| 国产精品涩涩成人一区二区三区| 欧美极品欧美精品欧美| 日韩高清中文字幕亚洲| 国产亚洲精品香蕉视频播放| 亚洲欧洲日韩综合二区| 国产一区麻豆水好多高潮| 伊人欧美一区二区三区| 亚洲欧洲一区二区中文字幕| 免费黄片视频美女一区| 久久福利视频这里有精品| 风韵人妻丰满熟妇老熟女av| 欧美国产日韩变态另类在线看| 中文字幕高清免费日韩视频| 欧美日韩在线视频一区| 国产精品午夜一区二区三区| 2019年国产最新视频| 成年男女午夜久久久精品| 日本高清中文精品在线不卡| 国产亚洲系列91精品| 欧美日韩三区在线观看| 欧美日本道一区二区三区| 欧美日韩精品视频在线| 国产精品欧美一级免费| 午夜福利视频日本一区| 亚洲熟妇熟女久久精品| 欧美性欧美一区二区三区| 91人妻人人精品人人爽| 绝望的校花花间淫事2| 亚洲一区二区精品免费| 人妻熟女中文字幕在线| 国产一级一片内射视频在线|