реклама на сайте
подробности

 
 
> Изменить формат вывода __DATE__ , __TIME__, AVRstudio
Sergey_Aleksandr...
сообщение Oct 25 2009, 19:45
Сообщение #1


Частый гость
**

Группа: Свой
Сообщений: 168
Регистрация: 8-10-08
Из: РФ Смоленск
Пользователь №: 40 764



Всегда в проектах (пишу на асме в AVRstudio) создаю подобную конструкцию
Код
.org (FLASHEND - 64)
    .db "  Encoder&Keyboard  v1.4  25.10.2009"

Т.е. в конец флеша записываю строку с названием проекта, версией прошивки и датой билда, что порой очень выручает.
На днях узнал про "предопределённые макросы" __DATE__ __TIME__, был приятно удивлён. Но не очень устраивает формат вывода даты макросом __DATE__ . Он выдаёт "Oct 25 2009", а хочется именно "25.10.2009". В хэлпе по AVRasm2 приводят:
Код
-FDformat
-FTformat
Specify the format of the __DATE__ and __TIME__ predefined macros, respectively. The format string is passed directly to the strftime(3) C library function. The __DATE__ and __TIME__ preprocessor macros will always be string tokens, i.e., their values will appear in double quotes.

The default formats are "%b %d %Y" and "%H:%M:%S", respectively.

Example: To specify ISO format for __DATE__, specify  -FD"%Y-%m-%d"  See note below

These formats may only be specified at the command line, there are no corresponding #pragma directives.

Important note: The Windows command interpreter (cmd.exe or command.com) may interpret a character sequence starting and ending with a '%' character as an environment variable to be expanded even when it is quoted. This may cause the date/time format strings to be changed by the command interpreter and not work as expected. A workaround that will work in many cases is to use double '%' characters to specify the format directives, e.g., -FD"%%Y-%%m-%%d" for the example above. The exact behaviour of the command interpreter seems to be inconsistent and vary depending on a number of circumstances, for one, it is different in batch and interactive mode. The effect of the format directives should be tested. It is recommended to put the following line in the source file for testing this:

#message "__DATE__ =" __DATE__ "__TIME__ =" __TIME__

This will print the value of the date and time macros when the program is assembled, making verification easy (see #message directive documentation).

An alternative syntax for the format specification may be considered in future AVRASM2 versions to avoid this problem.


Some relevant strftime() format specifiers (see strftime(3) manual page for full details):

%Y - Year, 4 digits

%y - Year, 2 digits

%m - Month number (01-12)

%b - Abbreviated month name

%B - Full month name

%d - Day number in month (01-31)

%a - Abbreviated weekday name

%A - Full weekday name

%H - Hour, 24-hour clock (00-23)

%I - Hour, 12-hour clock (01-12)

%p - "AM" or "PM" for 12-hour clock

%M - Minute (00-59)

%S - Second (00-59)

Куда писать эти спецификаторы - ума не приложу :-[ Имею подозрения, что поле "Additional Parameters" окна "Project->Assembler Options" для этих целей используется.

Также вопрос вдогонку. При присваивании константам текстовых имён хочу делать проверку на допустимость значения
Код
.equ defineParam1 = 1
......
......
#if (defineParam1 < 3)
#error "defineParam1 must be more then 3"
#endif

Но вот как в тексте ошибки вернуть значение этой константы? Чтобы при неверно заданном параметре был виден не только текст констатирующий ошибку, но и первопричину этой ошибки, что-то вроде #error "defineParam1 must be more then 3. Param1=", (????).
Спасибо всем откликнувшимся.
Go to the top of the page
 
+Quote Post
 
Start new topic
Ответов
Sergey_Aleksandr...
сообщение Oct 30 2009, 18:14
Сообщение #2


Частый гость
**

Группа: Свой
Сообщений: 168
Регистрация: 8-10-08
Из: РФ Смоленск
Пользователь №: 40 764



Сам вопрос задал, сам же на него и отвечу (вдруг кому и пригодится). В поле "Additional Parameters" окна настроек ассемблера "Project->Assembler Options" необходимо ввести спецификатор -FD"%%Y.%%m.%%d" для вывода даты вида "YYYY.MM.DD" (например 2009.10.30). Аналогично предопределяется и макрос __TIME__ . 4 года пользуюсь студией, а о подобных настройках узню только сейчас((
PS А вот как к строке возвращаемой директивой #error приаттачивать число, так и не придумал/нашёл. Может у кого есть соображения по этому вопросу?
Go to the top of the page
 
+Quote Post



Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 22nd July 2025 - 13:19
Рейтинг@Mail.ru


Страница сгенерированна за 0.01269 секунд с 7
ELECTRONIX ©2004-2016