在Atmle Studio6.2环境下,插上开发板就可自动识别。这时真接打开例程即可:
时钟配置在conf_clock.h中。
#ifndef CONF_CLOCK_H_INCLUDED
#define CONF_CLOCK_H_INCLUDED
// ===== System Clock (MCK) Source Options
//#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_SLCK_RC
//#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_SLCK_XTAL
//#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_SLCK_BYPASS
//#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_MAINCK_4M_RC
//#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_MAINCK_8M_RC
//#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_MAINCK_12M_RC
//#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_MAINCK_XTAL
//#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_MAINCK_BYPASS
#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_PLLACK
// ===== System Clock (MCK) Prescaler Options (Fmck = Fsys / (SYSCLK_PRES))
//#define CONFIG_SYSCLK_PRES SYSCLK_PRES_1
#define CONFIG_SYSCLK_PRES SYSCLK_PRES_2
//#define CONFIG_SYSCLK_PRES SYSCLK_PRES_4
//#define CONFIG_SYSCLK_PRES SYSCLK_PRES_8
//#define CONFIG_SYSCLK_PRES SYSCLK_PRES_16
//#define CONFIG_SYSCLK_PRES SYSCLK_PRES_32
//#define CONFIG_SYSCLK_PRES SYSCLK_PRES_64
//#define CONFIG_SYSCLK_PRES SYSCLK_PRES_3
// ===== PLL0 (A) Options (Fpll = (Fclk * PLL_mul) / PLL_div)
// Use mul and div effective values here.
#define CONFIG_PLL0_SOURCE PLL_SRC_MAINCK_8M_RC
#define CONFIG_PLL0_MUL 25
#define CONFIG_PLL0_DIV 1
// ===== Target frequency (System clock)
// - Internal RC frequency: 8MHz
// - System clock source: PLLA
// - System clock prescaler: 2 (divided by 2)
// - PLLA source: 8M_RC
// - PLLA output: 8M_RC * 25 / 1
// - System clock: 8M_RC * 25 / 1 / 2 = 100MHz
#endif /* CONF_CLOCK_H_INCLUDED */
而本例中的管脚LED定义在主程的最上边
#if ((BOARD == SAM4CMP_DB) || (BOARD == SAM4CMS_DB))
# define EXAMPLE_LED_GPIO LED4_GPIO
#else
# define EXAMPLE_LED_GPIO LED0_GPIO
#endif
而延时函数用了系统滴答时钟,其中断函数也在主函数的上边:
void SysTick_Handler(void)
{
ul_ms_ticks++;
}
而主函数只是每隔半分钟切换一下LED状态
int main(void)
{
sysclk_init();
board_init();
/* Setup SysTick Timer for 1 msec interrupts */
if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) {
while (1) { /* Capture error */
}
}
while (1) {
ioport_toggle_pin_level(EXAMPLE_LED_GPIO);
mdelay(500);
}
}
|