Страница 3 из 4 ПерваяПервая 1234 ПоследняяПоследняя
Показано с 21 по 30 из 40

Тема: компилятор sdcc.

  1. #21
    Moderator Аватар для Leff
    Регистрация
    26.04.2012
    Адрес
    Царевококшайск, Россия.
    Сообщений
    6,761
    Тоже для 8051F410


    // C8051F3410-411

    -D_IDATA_END=0xFF // Last address of Idata memory (0xFF for 8052 and 0x7F for 8051)

    -D_PDATA_START=0x0701 // First address for PDATA memory.
    -D_PDATA_END=0x07FF // Last address for PDATA memory.

    -D_IXDATA_START=0x0001 // First address of on chip XDATA memory.
    -D_IXDATA_END=0x7FF // Last address of on chip XDATA memory.

    -D_XDATA_START=_IXDATA_START // First address of XDATA memory.
    -D_XDATA_END=_IXDATA_END // Last address of XDATA memory.

    // Silicon Laboratories F32x chip has 16kb flash memory in the range
    // - CODE:0x0000-0x4000
    // In this application flash used for data begins at address
    // FIRST_FLASH_FILE and ends at address FIRST_FLASH_FILE + 0x2A00.
    //
    // FIRST_FLASH_FILE is a symbol that is defined in USB_MAIN.c
    //
    -D_CODE_START=0x0000 // First address for CODE.
    -D_CODE_END=0x7DFF // Last address for CODE.
    //
    -D_NEAR_CODE_END=0x7DFF // Last address for near code.
    //
    -D_FAR_DATA_NR_OF_BANKS=0 // Number of banks in far data memory.
    -D_FAR_DATA_START=0 // First address of far memory.
    -D_FAR_DATA_END=_XDATA_END // Last address of far memory.
    //
    -D_FAR_CODE_START=_CODE_START // First address for far code.
    -D_FAR_CODE_END=_CODE_END // Last address for far code.
    //
    //
    -D?REGISTER_BANK=0 // Default register bank (0,1,2,3).
    -D_REGISTER_BANK_START=0 // Start address for default register bank (00,08,10,18).
    //
    -D?PBANK_NUMBER=0F // high byte of 16-bit address to the PDATA area
    -D?PBANK=A0 // Most significant byte in MOVX A,@R0. (0xA0 is sfr P2)
    -D?PBANK_EXT=0xEA // Most significant byte in MOVX A,@R0. (0xEA is for Dallas DS80C390)
    //
    -D_BREG_START=0x00 // The bit address where the BREG segments starts.
    // Must be placed on: _BREG_START%8=0 where _BREG_START <= 0x78.
    -D?VB=0x20 // ?VB is used when referencing BREG as whole byte.

    -D_FIRST_BANK_ADDR=0

  2. #22
    Moderator Аватар для Leff
    Регистрация
    26.04.2012
    Адрес
    Царевококшайск, Россия.
    Сообщений
    6,761

  3. #23
    Moderator Аватар для Leff
    Регистрация
    26.04.2012
    Адрес
    Царевококшайск, Россия.
    Сообщений
    6,761
    Последний раз редактировалось Leff; 30.05.2014 в 14:52.

  4. #24
    Moderator Аватар для Leff
    Регистрация
    26.04.2012
    Адрес
    Царевококшайск, Россия.
    Сообщений
    6,761
    SDCC and Keil Compatibility Issues

    Many developers accustomed to the use of the Keil development tools for 8051 targets may not have had exposure to the free SDCC tools. SoftConsole uses SDCC for compiling and linking your Core8051s projects. As you develop your programs, or port your existing Keil-compatible code to use under SoftConsole for a Core8051s target, there are some fundamental differences you will want to keep in mind.

    The SDCC compiler's User Manual (available under the Start menu entry for SoftConsole) covers such differences in detail. Some of the more important differences are highlighted here.
    Syntax Differences
    In your code developed with Keil, you can use
    #pragma NOEXTEND
    to make sure you've weeded out exactly what compiler-specific keywords exist.
    SFR declarations
    The Keil syntax with

    sfr IOA = 0x80;

    looks slightly different with SDCC, using either of

    sfr at 0x80 IOA;
    __sfr __at 0x80 IOA;

    The SDCC "at" and "__at" keywords are used in place of an initialization-style statement. In the interests of pointing out possible compatibility issues, many users opt to choose the leading "__" version of these keywords to make their use more clear.

    Also, SDCC does not require the bytes to be adjacent in memory for sfr or sfr16.
    SBIT declarations
    Also the case with SBIT, you use the "at" keyword. Instead of

    sbit SEL = 0x86+0;

    you should have one of

    sbit at 0x86+0 SEL;
    __sbit __at 0x86+0 SEL;

    External Registers
    The Keil compiler looks for "_at_" in the declaration of an external register, such as
    extern xdata volatile unsigned char GPIO_LED_REG _at_ 0xF200;
    Instead, the SDCC style is
    extern xdata at 0xF200 volatile unsigned char GPIO_LED_REG;
    Printf Functionality

    The SDCC compiler does support the use of printf(); however, you will need to create your own putc() function to implement the actual emitting of bytes to a specific device for stdout.
    Macro Workarounds
    Some users elect to take advantage of macro text substitution in their source code to make the creation of more compatible code less labour-intensive. For example, you can employ:

    #define SFR(a,b) __sfr __at(a) b
    #define SBIT(a,c) __sbit __at(a) c
    #define SBIT(a,b,c) __sbit __at(a+b) c
    #define SFR16(a,b) __sfr16 __at(((b+1)<<8) | b) a

    This will enable you to use "SFR(0x80, IOA)" regardless of which specific syntax they're using.
    Assembly Language Programming

    If you are writing a program in assembly language rather than in C, you should be aware of some differences between the asx8051 assembler and Keil's A51. As noted by Daniel Clemente in his description of using SDCC with a particular development board:
    Global symbols (tags accessible from outside) are specified with .globl (or with tag:. Then you don't need the -g when compiling.
    Files are included with .include
    Constants (equ) are done with NAME = value
    You must use .area CSEG (CODE) before the code.
    The hexadecimal values are written with 0xVALUE, and binary with 0bVALUE. In A51 they have the letter at the end.
    You don't need the end instruction at the bottom of each file.
    Keil ignores everything about upper/lower case, and even when in your code you're calling EZUSB_Delay1ms, for instance, at the assembler there's only defined the symbol EZUSB_DELAY1MS.
    Symbols created by asx8051 must have the prefix _ (it means external symbol). sdcc adds it automatically when compiling C.
    ISO/ANSI Compliance

    There are some traits of the SDCC compiler that are not in full compliance with the ISO standard for the C programming language. Users who would like to know the specifics are encouraged to consult section 8.2, "ANSI-Compliance", in the SDCC User Manual (available in HTML and PDF format under the Start menu entry for SoftConsole).
    Последний раз редактировалось Leff; 05.06.2014 в 10:21.

  5. #25
    Moderator Аватар для Leff
    Регистрация
    26.04.2012
    Адрес
    Царевококшайск, Россия.
    Сообщений
    6,761
    Программа преобразует строку в переменную long.
    Ссылка на исходник выкладывал ранее в этой теме.
    Поддерживает числа до 10 цифр со знаком, вида LNG=-1234567890;


    //*******************************************
    long _atol_( const char *c ) {
    long value = 0;
    bit sign = 0;
    if( *c == '+' || *c == '-' ) {
    if( *c == '-' ) sign = 1;
    c++;
    }
    while ( isdigit( *c ) ) {
    value *= 10;
    value += (long) (*c - '0');
    c++;
    }
    if(sign)value=-value;
    return value;
    }

  6. #26
    Moderator Аватар для Leff
    Регистрация
    26.04.2012
    Адрес
    Царевококшайск, Россия.
    Сообщений
    6,761
    Программа для преобразования переменной типа float в строку.
    Взята по ссылке выложенной в начале темы, и была немного подправлена.
    Переменная вида f=-12.123456;
    Всего максимально (суммарно) 8 разрядов, разделенных точкой.
    Переменная w - количество знаков после запятой.



    ///************************************************** *************
    char* _ftoa_(float pn, char* buffer, char ww) {
    char* ptr = buffer;
    char sst, js;
    float fract;
    long rest;
    if(pn < 0) {
    *ptr++ = '-';
    pn = -pn; }
    else *ptr++ = ' ';
    if(ww>6) ww=6;
    rest = (long)pn;
    fract = (pn - rest); //
    _ltoa_(rest, ptr);
    js=strlen(ptr);
    ptr = ptr + js;
    *ptr++ = '.';
    if(ww > (8-js)) ww = 8-js;
    while(ww--){
    fract = fract * 10;
    sst = (char)fract;
    fract = fract - sst;
    *ptr++ = sst + 0x30;
    }
    *ptr = 0;
    return buffer;
    }
    Последний раз редактировалось Leff; 10.06.2014 в 17:59.

  7. #27
    Moderator Аватар для Leff
    Регистрация
    26.04.2012
    Адрес
    Царевококшайск, Россия.
    Сообщений
    6,761
    Программа аналогичная предыдущей, с функцией восстановления переменной float из строки.
    Взята по ссылке, немного подправлена.



    //**************************************
    float _atof_(char * s) {
    float value, fraction;
    long iexp;
    bit sign;
    while (isspace(*s)) s++;
    if (*s == '-') {
    sign=1;
    s++; }
    else { sign=0;
    // if (*s == '+') s++;
    }
    for (value=0.0; isdigit(*s); s++) {
    value=10.0*value+(*s-'0'); }

    if (*s == '.') {
    s++;
    for (fraction=0.1; isdigit(*s); s++) {
    value+=(*s-'0')*fraction;
    fraction*=0.1; }
    } if (toupper(*s)=='E') {
    s++;
    iexp=(long)_atol_(s);
    while(iexp!=0)
    {
    if(iexp<0) {
    value*=0.1;
    iexp++; }
    else {
    value*=10.0;
    iexp--; }
    }
    }
    if(sign) value*=-1.0;
    return (value);
    }

  8. #28
    Moderator Аватар для Leff
    Регистрация
    26.04.2012
    Адрес
    Царевококшайск, Россия.
    Сообщений
    6,761
    По ссылке лежит исходник программы - sprintf.c
    http://www.opensource.apple.com/sour...ruby/sprintf.c

  9. #29
    Moderator Аватар для Leff
    Регистрация
    26.04.2012
    Адрес
    Царевококшайск, Россия.
    Сообщений
    6,761
    Программа выводит текстовую строку в буфер и вставляет значение переменной F (float) в строку. После точки по умолчанию 2 знака.
    _sprintf_( buffer, " R=%f Ohm ", F);
    Если вставить цифру до символа "f" - то количество знаков после запятой будет равно этому значению (суммарно, до запятой и после, также не более 8).
    _sprintf_( buffer, " R=%4f Ohm ", F);



    ///******* _sprintf_ *************************************************
    void _sprintf_( char* ptr, const char *fmt, float pnf) {
    char w=2, j, ibuf[16];
    char* ptrS = ibuf;
    while (*fmt != 0)
    {
    if (*fmt == '%') {
    fmt++;
    while (*fmt != 'f') if(isdigit(*fmt)) { w=*fmt-'0'; fmt++; }
    fmt++;
    _ftoa_(pnf, ptrS, w);
    j=strlen(ptrS)+1;
    strncpy(ptr, ptrS,j);
    ptr = ptr + j;
    }
    else *ptr++ = *fmt++;
    }
    }



    Если переменная F=-123.123456;
    то будет напечатано в первом случае: " R=-123.12 Ohm "
    и во втором: " R=-123.1234 Ohm "
    Последний раз редактировалось Leff; 06.06.2014 в 16:31.

  10. #30
    Moderator Аватар для Leff
    Регистрация
    26.04.2012
    Адрес
    Царевококшайск, Россия.
    Сообщений
    6,761
    Описание библиотечных функций на русском языке
    http://cppstudio.com/post/726/

Ваши права

  • Вы не можете создавать новые темы
  • Вы не можете отвечать в темах
  • Вы не можете прикреплять вложения
  • Вы не можете редактировать свои сообщения
  •