embedded c new

Upload: kaushik4208

Post on 30-May-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 Embedded C New

    1/10

    PROGRAMMING WITH

    EMBEDDED C in 8051

    By

    Siva . J

  • 8/14/2019 Embedded C New

    2/10

    Memory AreasProgram Memory: may be accessed using the code

    memory type specifier in the Cx51 compiler.

    External Data Memory

    The Cx51 Compiler offers two different memory types that

    access external data:xdata and pdata.

    Xdata: refers to any location in the 64 Kbyte address space

    ofexternal data memory.

    pdata :memory type specifier refers to only one (1) page

    or 256 bytes of external data memory.

  • 8/14/2019 Embedded C New

    3/10

    Memory Areas (Contd)Internal Data Memory: can be broken down into three distinctmemory types data, idata, and bdata.

    data :refers to the first 128 bytes of internal data memory.Variables stored here are accessed using directaddressing.Idata : refers to all 256 bytes of internal data memory;however,this memory type specifier code is generated byindirect addressing which is slower than directaddressing.bdata : refers to the 16 bytes of bit-addressable memory Inthe internal data area (20h to 2Fh).This memory typespecifier, allows you to declare data types that can also be

    accessed at the bit level.

  • 8/14/2019 Embedded C New

    4/10

    Memory Models

    The memory model determines the default

    memory type to use for function arguments,

    automatic variables, and declarations with

    no explicit memory type specifier.

    Small Model

    Compact Model

    Large Model

  • 8/14/2019 Embedded C New

    5/10

    Absolute Variable Location:

    type memory_space variable_name _at_constant;

    where: memory_space is the memory space for the

    variable. If missing from the declaration, thedefault memory space is used.

    type is the variable type.

    variable_name is the name of the variable.

    constantis the address at which to locate the

    variable.Special Function Registers: Sfr16, sfr, sbit.

  • 8/14/2019 Embedded C New

    6/10

    Variable Decleration -exampletype memory_space variable_name _at_ constant;

    unsigned char xdata port_a _at_ 0xe000;data unsigned char i _at_ 0x34;unsigned char data text[16] _at_ 0x40;unsigned char mess[ ] = { 'W','A','I','T };

    bit b0;

    unsigned char bdata flag _at_ 0x20;sbit fbit = flag ^ 7;

    sbit P1_2 = 0x90 ^ 2;

    sfr scon = 0x98;Sfr16 data_ptr = 0x82;

  • 8/14/2019 Embedded C New

    7/10

    Function DeclarationsThe Cx51 compiler provides a number

    of

    extensions for standard C function

    declarations.

    These extensions allow you to:

    Specify a function as an interruptprocedure.

    Choose the register bank to be used. Select the memory model.

    Specify reentrancy.

  • 8/14/2019 Embedded C New

    8/10

    Cx51 function declarationreturn_type funcname (args) {small/compact/large}

    [reentrant] [interruptn] [usingn]where: return_type is the type of the value returned from the

    function.

    If no type is specified, int is assumed.

    funcname is the name of the function. args is the argument list for the function. small, compact, or large is the explicit memory model for

    the function. reentrant indicates that the function is recursive or

    reentrant. interrupt indicates that the function is an interrupt

    function. using specifies which register bank the function uses.

  • 8/14/2019 Embedded C New

    9/10

    Function Declaration -exemple

    return_type funcname (args) {small/compact/large}

    [reentrant] [interruptn] [usingn]

    Void timer0_int ( ) interrupt 1

    void serial_int ( ) interrupt 4void Disp_Key (unsigned char c)

    void new (unsigned char c) small

    void old (unsigned char t) smallreentrant

    void new (void) using 2

  • 8/14/2019 Embedded C New

    10/10

    Differences from ANSI CCompiler-related Differences Wide Characters

    Wide 16-bit characters are notsupported by Cx51. ANSI provides widecharacters for future support of aninternational character set.

    Recursive Function CallsRecursive function calls are not

    supported by default. Functions that arerecursive must be declared using thereentrant function attribute.