本帖最后由 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就换一下状态。
|