金牌会员
积分 2452
金钱 2452
注册时间 2015-11-1
在线时间 301 小时
1 金钱
一堆宏定义无法理解,还请赐教:如下:
#if defined(__GNUC__) || defined(__DOXYGEN__)
# include <avr/pgmspace.h>
# define PROGMEM_LOCATION(type, name, loc) \
type name __attribute__((section (#loc)))
# define PROGMEM_DECLARE(type, name) const type name __attribute__((__progmem__))
# define PROGMEM_STRING(x) PSTR(x)
# define PROGMEM_STRING_T PGM_P
# define PROGMEM_T const
# define PROGMEM_PTR_T const *
# define PROGMEM_BYTE_ARRAY_T uint8_t*
# define PROGMEM_WORD_ARRAY_T uint16_t*
# define PROGMEM_READ_BYTE(x) pgm_read_byte(x)
# define PROGMEM_READ_WORD(x) pgm_read_word(x)
#elif defined(__ICCAVR__)
# include <pgmspace.h>
# ifndef __HAS_ELPM__
# define _MEMATTR_ASF __flash
# else /* __HAS_ELPM__ */
# define _MEMATTR_ASF __hugeflash
# endif /* __HAS_ELPM__ */
# define PROGMEM_LOCATION(type, name, loc) const _MEMATTR_ASF type name @ loc
# define PROGMEM_DECLARE(type, name) _MEMATTR_ASF type name
# define PROGMEM_STRING(x) ((_MEMATTR_ASF const char *)(x))
# define PROGMEM_STRING_T char const _MEMATTR_ASF *
# define PROGMEM_T const _MEMATTR_ASF
# define PROGMEM_PTR_T const _MEMATTR_ASF *
# define PROGMEM_BYTE_ARRAY_T uint8_t const _MEMATTR_ASF *
# define PROGMEM_WORD_ARRAY_T uint16_t const _MEMATTR_ASF *
# define PROGMEM_READ_BYTE(x) *(x)
# define PROGMEM_READ_WORD(x) *(x)
#endif
在C内直接就这样定认数据:
PROGMEM_DECLARE(char const, header[]) = "Temperature";
PROGMEM_DECLARE(char const, cdc_help[]) =
"\r\n"
"Welcome to the XMEGA-A3BU Xplained Demo CDC interface!\r\n"
"\r\n"
"Key bindings for LCD menu control:\r\n"
" Enter : Enter\r\n"
" Backspace : Back\r\n"
" Arrow Up : Up\r\n"
" Arrow Down : Down\r\n";
PROGMEM_DECLARE(char const, tz_00[]) = "UTC: UK (GMT)";
PROGMEM_DECLARE(char const, tz_01[]) = " +1: Oslo, Berlin";
PROGMEM_DECLARE(char const, tz_02[]) = " +2: Istanbul";
PROGMEM_DECLARE(char const, tz_03[]) = " +3: Nairobi";
PROGMEM_DECLARE(char const, tz_04[]) = " +4: Moscow";
PROGMEM_DECLARE(char const, tz_05[]) = " +5: Pakistan";
PROGMEM_DECLARE(char const, tz_06[]) = " +6: Bangladesh";
PROGMEM_DECLARE(char const, tz_07[]) = " +7: Thailand";
PROGMEM_DECLARE(char const, tz_08[]) = " +8: Hong Kong";
PROGMEM_DECLARE(char const, tz_09[]) = " +9: Tokyo";
PROGMEM_DECLARE(char const, tz_10[]) = "+10: AEST";
PROGMEM_DECLARE(char const, tz_11[]) = "+11: Solomon Island";
PROGMEM_DECLARE(char const, tz_12[]) = "+12: Fiji";
就这样执行了:
while ((val = PROGMEM_READ_BYTE(help))) {
udi_cdc_putc(val);
help++;
}
这几句,真心不懂。
# define PROGMEM_LOCATION(type, name, loc) \
type name __attribute__((section (#loc)))
# define PROGMEM_DECLARE(type, name) const type name __attribute__((__progmem__))
我来回答