首先,新建ASF工程,然后加入EEPROM模块。
然后在ASF explorer中打开QUICK START GUIDE
按照上面步骤做,然后编译通过:
但下进去灯不亮,有断点才发现原来熔丝位没有设EEPROM段。究竟怎么原因,下回分解。
上程序先:
/**
* \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 system_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).
*/
#include <asf.h>
void configure_eeprom(void);
void configure_eeprom(void)
{
/* Setup EEPROM emulator service */
enum status_code error_code = eeprom_emulator_init();
if (error_code == STATUS_ERR_NO_MEMORY)
{
while (true)
{ /* No EEPROM section has been set in the device's fuses */ }
}
else if (error_code != STATUS_OK)
{ /* Erase the emulated EEPROM memory (assume it is unformatted or * irrecoverably corrupt) */
eeprom_emulator_erase_memory();
eeprom_emulator_init(); }}
int main (void)
{
system_init();
configure_eeprom();
uint8_t page_data[EEPROM_PAGE_SIZE];
eeprom_emulator_read_page(0, page_data);
page_data[0] = !page_data[0];
port_pin_set_output_level(LED_0_PIN, page_data[0]);
eeprom_emulator_write_page(0, page_data);
eeprom_emulator_commit_page_buffer();
while (true) { }
}
|