打印
[Atmel]

跑SAM4S程序3:利用滴答时钟延时

[复制链接]
768|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 ddllxxrr 于 2015-2-14 13:00 编辑

这个程序是调用,CMSIS中的滴答时钟来实现1秒钟延时。

首选建立ASF工程,然后选择SAM4S的芯片,我这里选择ATSAM4SD32C

然后系统自动建立程序框架,并且还有LED程序。

然后加入Delay routines模块,



最后键入以下程序:

/**
* \file
*
* \brief Empty user application template
*
*/

/**
* \mainpage User Application template doxygen documentation
*
* \par Empty user application template
*
* This is a bare minimum user application template.
*
* For documentation of the board, go \ref group_common_boards "here" for a link
* to the board-specific documentation.
*
* \par Content
*
* -# Include the ASF header files (through asf.h)
* -# Minimal main function that starts with a call to board_init()
* -# Basic usage of on-board LED and button
* -# "Insert application code here" comment
*
*/

/*
* Include header files for all drivers that have been imported from
* Atmel Software Framework (ASF).
*/
/**
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
*/
#include <asf.h>
#include "conf_board.h"
static volatile uint32_t ticks = 0U;

void SysTick_Handler(void)
{
        ticks ++;
}

int main (void)
{
        sysclk_init();
        board_init();     
        

        // Insert application code here, after the board has been initialized.
     if(SysTick_Config(sysclk_get_cpu_hz()/(uint32_t)1000))
         {
                 while(1)
                 {
                 }
         }
        // This skeleton code simply sets the LED to the state of the button.
        while (1) {
                // Is button pressed?
                //if (ioport_get_pin_level(BUTTON_0_PIN) == BUTTON_0_ACTIVE) {
                        // Yes, so turn LED on.
                        ioport_set_pin_level(LED_0_PIN, LED_0_ACTIVE);
                        delay_ms((uint32_t)1000);
                //} else {
                        // No, so turn LED off.
                        ioport_set_pin_level(LED_0_PIN, !LED_0_ACTIVE);
                        delay_ms((uint32_t)1000);
                //}
        }
}





编译通过时,下进开发板,发现LED0每一秒换一下亮灭的状态。


这个程序就是每记到1000就换一下状态。

相关下载

相关帖子

沙发
dirtwillfly| | 2015-2-13 13:41 | 只看该作者
感谢分享

使用特权

评论回复
板凳
ddllxxrr|  楼主 | 2015-2-13 13:57 | 只看该作者

使用特权

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

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2394

主题

6938

帖子

66

粉丝