打印
[PIC32/SAM]

ATSAMD51 EVK评估板评测2按键控制灯

[复制链接]
165|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
今天捣鼓了一下按键控制灯,用microchip studio自动生成代码,然后自己再增加一部分代码。
代码如下:
#include <atmel_start.h>

int main(void)
{
        /* Initializes MCU, drivers and middleware */
        atmel_start_init();
        _gpio_set_level(GPIO_PORTC,0x00040000,1);
        /* Replace with your application code */
        while (1) {
               
                if((gpio_get_port_level(GPIO_PORTB)&0x80000000)==0x00000000)
                        _gpio_set_level(GPIO_PORTC,0x00040000,0);
                else
                        _gpio_set_level(GPIO_PORTC,0x00040000,1);

        }
}

初始化代码:
#include <atmel_start.h>

/**
* Initializes MCU, drivers and middleware in the project
**/
void atmel_start_init(void)
{
        system_init();
}

/*
* Code generated from Atmel Start.
*
* This file will be overwritten when reconfiguring your Atmel Start project.
* Please copy examples or other code you want to keep to a separate file
* to avoid losing it when reconfiguring.
*/

#include "driver_init.h"
#include <peripheral_clk_config.h>
#include <utils.h>
#include <hal_init.h>

void system_init(void)
{
        init_mcu();

        // GPIO on PB31

        // Set pin direction to input
        gpio_set_pin_direction(KEY, GPIO_DIRECTION_IN);

        gpio_set_pin_pull_mode(KEY,
                               // <y> Pull configuration
                               // <id> pad_pull_config
                               // <GPIO_PULL_OFF"> Off
                               // <GPIO_PULL_UP"> Pull-up
                               // <GPIO_PULL_DOWN"> Pull-down
                               GPIO_PULL_UP);

        gpio_set_pin_function(KEY, GPIO_PIN_FUNCTION_OFF);

        // GPIO on PC18

        gpio_set_pin_level(LED,
                           // <y> Initial level
                           // <id> pad_initial_level
                           // <false"> Low
                           // <true"> High
                           true);

        // Set pin direction to output
        gpio_set_pin_direction(LED, GPIO_DIRECTION_OUT);

        gpio_set_pin_function(LED, GPIO_PIN_FUNCTION_OFF);
}
效果图:






使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

337

主题

3057

帖子

7

粉丝