Home
        µC / 51 - grifo¨ COM
         Contents
1.         else  leall test11   endif   endif  ifdef    ifndef  Usage   ifdef SYMBOL and    ifndef SYMBOL    This directive simply checks  if a SYMBOL is already defined  It is quite similar to the   if  above  An example     If macro not already defined  define it      1fndef char out   macro char out    No Ne Ne Se Ne          mov A  Q1 parameter  1 into A  lcall output and OUT   endmacro now the macro is definitely defined    endif  char out  X    Use the macro for output of a  X   hide    show    This two directives increment and decrement the  documentation level  of the assembler  Only  if this level is greater than zero  a listing or sourcecode information is generated  During  expansion of a macro  the level will be temporarily decremented  So if you re interested in the  expanded macros  simply add an addition   show   The default level is 1      dc b    de w    dc l    de f    These directives insert numbers and strings in the output  A comma is used as a delimiter   For   dc b  strings may be used  The byte order for   dc w  and   dc l  is Big Endian  this means  highbyte first  The   dc f inserts a number in the IEEE32 32 bit floating point format  Some  example     28    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual     dc b  Hello World  13 10 0   Text   lt CR gt    lt LF gt   0   dc w init   0000   AB       AB  is  41 542  same as  dc b  A   B     dc w test   sppose test  8023  would be same as  dc b  80   23      de l  IinN1Et   ABCD    4 byte constant   SAGE  
2.         endmacro    sichern temp 17   17 bytes safe from    sichern temp 10   10 Bytes safe from temp    The label   s0  in the both expansions is different     29    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    Generated symbols    On demand  if imported with  import    the assembler and the linker will generate additional  symbols  containing infos about segments  The system  let   s  be the segment s name  so  these additional labels are available  a double     at the beginning and end      _ _org _ segment s start  real  address   __ s_ size __ segment s  real  size in bytes  bits for  sclass bit     _  s_maxsize __ maximum segment s size  if supplied    _  s load __ address of the initialisation data in the code space  1f supplied     Wome wow    Additionally for each  sclass   for   s sclass can be  text    bit    dram    iram    xram       __  s_org _  __ s_size__    Last not least     _ stack org _ the first unused byte in the internal RAM is used for the  stack  It will grow upwards   _ bin size __ this is the complete size of the binary  including all code and    initialisation data     Technical description of the related tools    This chapter will work out some of the deeper details of the related tools  It will follow in an  later version of this documentation       The libraries    Currently only the most important library functions have been added  But the list is continu   ously growing       standard libraries    stdio h    This is one of the most impor
3.     line   and a word about source level debugging                   o  o oo o   2T    macro    endmacro   6    ee ee eee ete t ees 27  if else  sendif 8 Si dedi RAN 28  del UMC Be te o A E Duh etry    ale awa ag 28     DIE SIMO WW cis Li A A Sees On A E A E BO 28    dc b    de w del   def 56 9 6 56 cs a oS  oh BE Be 28    lt ds b    ds w    ds l  ds f 00000 ee ee eee ne tenes 29  MAGCIOS   sk er ah ieee AS Oh oh tte ane dh ees alee tied dh ee ek hese 29  Generated symbols coito vsed ss iad ee PURSES PRES OSSD eae ese 30  Technical description of the related tools 30  The lbrarles ora usara da tie a Ne eas 30  Standard libraries 3 33 ia it Fok SRE A ARA 30  SCHON dt td Mere BEE 30  SOREN ID  a ts Sota Pe ie te ba ace nae res la a ea 31  Cte es tae oe A Ma ais Ris Wi ee ae a a ee 32  A tas tk Abd ASO os ARON OS WOR MAES MAES AMO ge BO 32  A pe ask E eE eas oe A Ga fue Hi ee a 32  math o a a Lea ee 32  8051 SPECIES AA RA RARAS ATA 32  A E ee eer ate N A ee ee eee A 32  regs  hy reg52 h  reg535 h ic a A RE RG it ORAS 33  Appendix A  Migrating from other compilers     ___         33  Memory usage   memory models                  0 0    cece eee eee 33  Absolute addresses A ak he a he eee ae i BO AEE AHR 33  Interrupts  ec 6 63 55 9 5 oS erann Boa 8 oe BE GEOR a ARO OS Re ORS 33  Assembly language                0    ccc ete n en eas 33    Appendix B  A demo of pC 51 s optimisers                  34    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    HC 51 V1 10 User s Manual   
4.    Please note  for uC 51 the memory model has no affect on where global variables are located     unlike as in other compilers   We suggest  that you should use a    typedef    or a    define    to  modify the memory type of global data  depending on the memory model     8051 memory modifiers    To distinguish between the different types of memory on the 8051 uC 51 defines some new  keywords  modifiers      bit as  unsigned char bit  this data type uses only 1 bit  Ideal for global flags   The 8051 allows up to 128 bits for data  128 bits are reserved for    Special    Function Bits     SFB   Many of them have commonly used names  like    RI        xdata data with this modifier is located in the external ram  access to it needs a  16 Bit pointer    code data is in the code memory  access by a 16 Bit pointer  near data is in the internal RAM  locations 0  127  access by an 8 Bit pointer    inear data is in the internal RAM  locations 0  255  access by an 8 Bit pointer  Using    10    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    inear is less effective than near  because access is always done by an indirection  It is  well suited i e  for global arrays in the internal RAM  The advantage for inear is  that  it might be located in the upper half of the internal RAM  whereas near  and all   local variables in the small memory model  must be located in the lower half  If the  internal space is low on the controller  consider the use of inear     far or  generic  a far modifi
5.    mended  because it may disturb the optimiser  which sometimes completely reorders the  instructions of a function     A good starting point is  write a skeleton of your functions in C and use the compiler s  output     Our assembler syntax is slightly different from the  standard   we think  that our syntax is  better readable  for information read the chapter about the assembler s technical reference  Of  course  the differences concern only assembler directives and number representation  the  mnemonics are full compatible to the standard     A few short hints for using the Assembler 51  continuous blocks of code should be placed in     segments   each segment starts with a  segment NAME   OPTIONST  directive  Segments of  the same name will be joint by the linker  The OPTIONS may be  sclass SCLASS      org    16    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    ORG      size SIZE      notext   SCLASS is  dram    iram   xram   without SCLASS the segment is   code   ORG sets the segment to an absolute position  the linker may add an additional offset  due to it s  rCODE XRAM  parameter   With  SIZE  the size of the segment will be fixed    notext  is only of use for data segments  If  notext  is not set  a mirror segment with initialisa   tion data is added in the code segment  this mechanism is used by the  startup    routine to  initialise the data segments   The labels of a segments can by exported with   export  or  importet with  import   A more detailed descripti
6.  FNAME    is allowed     error    An optional text might follow this directive  An error will be displayed and assembling is  stopped  Like      1f VERSION  1   error Only version 1 alloweed    endif        end    Assembly is stopped  All following text is ignored  even if  end  is in an included file        import    Usage   Import SYMBOL    FURTHER_SYMBOLS Jopt     To use a symbol  defined in another sourcecode  it must be imported  otherwise the assem   bler would give an error   This is done by   import       export  Usage   export SYMBOL    FURTHER_SYMBOLS op     Exporting a symbol allows its global use  If a symbol has   import  and   export  in the same  sourcecode  an   export  is assumed  This is useful for libraries  There is also the possibility to  export assignments in uC 51  i e  used for the  startup_first    function   This might be useful  i e  for libraries  I e   If the IPC library would import the SDA and SCL pins  and not define  them by itself   the user could write the following      export SDA SCL  SDA P1 7  SCL P1 6    26    WWW WICKENHAEUSER COM uC 51 V1 10 User s Manual    This would set SDA and SCL only for this project to P1 6 7  Other pins could be used for  other projects without changing the library     Note  If dealing with compiler generated symbols  you must consider  that the compiler will  add a leading     to each symbol  So the function  test    in C correspondents to the symbol    test  in assembler      file    The directive   file  HL
7.  Preface    Thank you for deciding to use uC 51  a complete ANSI C language development system for  the whole 8051 family of microcontrollers     This is the documentation is for the first  official release   Although this is a version V1 xx   using uC 51 bears no risk of  jumping into cold water   This development system has a long  history  the generated code is very stable and highly optimised  Until now  many industrial  developments have been done with it  The included source code  libraries and demos cover a  broad range  from writing applications in full ANSI C for the smallest available 8051 CPUs   ATMEL s 89C1051 with as little as 1kB of code space and only 64 bytes of internal RAM    up to the largest  uC 51 is able to manage memory sizes up to 16 MB   from Maxim s  1 Wire   Bus  over the PC Bus  up to Ethernet        We developed uC 51 for our own use and needs  Almost daily uC 51 is used by ourselves for  all kind of industrial applications and these test beds are not easy  Besides of that  many  useful functions arise  like our PC Bus library or the  binary safe  function  that locks a whole  binary file against modifications       History    The idea for writing compilers was born a few years ago  We had written a small BASIC   compiler for use with 8051 based microcontroller  Although this    uBASIC 51    was quite  simple  writing software for the 8051   s suddenly became much easier than in Assembler  But  with the projects the demands grew too    So the uC 5
8.  a short jump could be used as an optimisation  Therefore it  uses a guess  Most instructions are less than 2 bytes long  so a label distance of 50 would  allow short jumps within a distance of 50 assembler lines  or     100 bytes  which should be  safe  However  increasing this value could improve code size  If the assembler requires to  decrease it  please let us know     UmShell  amp  Umake    As introduced beforee  these two helpers will build your software  by using a  recipe   also  named  makefile    UmShell is the graphical user interface  but Umake will do all the work       20    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    The most important Flags in Make files    The flags in the Make file are nothing more than variables  able to hold a string value  As   there are    C51FLAGS  Flags for the compiler  default is empty  My be used for telling the compiler  something  like a definition    CSIFLAGS    dTEST  dABC 3  is the same  as if    define TEST    and     define ABC 3    inside the source code     ASIFLAGS  Flags for the assembler  predefined as   d  g    d  expand the macro   _line  for each sourceline  needed for single step    g  include sourcecode info in the listing    LSIFLAGS  Flags for the linker  predefined to   r 8000  F000   this will link all programs  to  8000  with xdata starting at  F000     MODEL  The memory model  default is  small   set to  large  if required    SIOTYPE  The used library for the serial i o  Default is    d     for using t
9.  ccoo AAA a ROS  Reentrant functions            SAA AA ERE EES  Indirect TUNCTIONS ds li BEER ds  Varna dic functi    ns 20 1264030 AAA AR AG ERO ERLE  Integral promotion 0000 id A Oe Rabe     Old style functions    lt 2  cj asin xen ined aes IAS eke dee ah te  Defining your own SFR s   defining absolute addresses with               Overwriting library functions            0   0    ccc nee  The job Of Startup      lt a ds ra ii  The binary safe  _bin_sSafe               20    0  ccc eens  Efficient coding  as0s seh tect hh AA One eae a    Predefined Symbols  20 500 bine ibys eee es ar 19    Some important options  command line   pragma                       19  UmShell 8 Umake eee  20  The most important Flags in Make files                                 21  Make tiles Simple i   ash Sai aaa 21  Technical description of the compiler UC51 EXE  _   _   sdi_ads  22  Technical description of the assembler A51 EXE  __i_d   22  Mnemonics  Luis a ste ae te ota  o q aea oe ees 23  Names  variables and labels                             o oooooocoo o    23  Numbers  3 cod ote tes a ao edad is veta tn ala 23  Operators oan oeie NS 24  Directives v hae reet werk de os fase cd tre gig has OS O ORRA A 24    SEO MENE ras ido de dr UA AA 24  Cd a o e e o A ie ed Ole ted AE ah ae 26  ADENT AN A E a EE A TN a 26  A O II A RA 26   O A O a Sade A ae  amp  Late wad Baha 26   AMD ORG  5g hea A wis ahaa ele Cale tt Bn Qe aa ds e nte 26  SOXDOUE  AAA AS HU VRP AAA LY VES DOS OR TRV AEE 26  O A 27 
10.  decimal  or     for base 16     Make files simple    This is a minimum description for make files  The idea behind make is  to have an recipe of  how something is made from something else  if the result is older than the sources  in other  words  Make will only do what is really necessary  Make is based on rules  depending on file  name extensions  You may find the default rules in  BIN BUILTINS MAK   We have  supplied rules for the most common tasks here in  like     21    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    Making a   bin out of   c or   s51  Making a   obj out of   c or   s51  Making a   bin out of   obj and   lib  Making a   hex out of   bin    Using a rule in a make file always starts with the result  followed by a colon  Then the  sources follow  To select a rule  Make must detect the Target s filename in the sources  i e     happy bin  fast obj happy obj newlink obj    If any of the three sources are younger than  happy bin   Make will try to find a rule how to  make happy bin  It will detect  that  happy  is in happy obj  so 1t will use the rule for Making    bin out of   obj  In case of success  the file time stamps will reflect this     Guess  what the following line will do     happy hex  happy bin    In some cases Make is not able to detect all dependencies  1  e  if you change header files for  a source code  but Make does not know about this dependency  it could be advised to watch  for this  but often one is too lazy to tell that      In this ca
11.  have been appropriate marked  But we can not attest the  accuracy of this information  Use of a term should not be regarded as affecting the validity of  any trademark or service mark     Internet    All references to Internet addresses are given by best knowledge  However  we want to  emphasise particularly that the contents of those addresses usually are beyond our influence   Therefor we dissociate us explicitly from any referenced contents  if they are an offence  against any current laws     Installation and de installation    uC 51 will work on any    Win9x     or better  computer  There is no special requirement  This  software may be completely removed by the computer s standard de installation routines   Merely files  which have been produced by the use of this software are excluded from de  installation  If desired remove them manually     Important  Please note  that uC 51 must be installed in a path without    whitespace charac   ters     i e     C   MyFiles uC51         but not    C   My Files uC51          because wC 51   s    MAKE      system is currently not able to handle such filenames     Installing the full version    If uC 51 is installed  it will run first in the 8kb limited demo mode  If you are owner of a  license for the full version  you first have to register your installation  Each license gives  your the right to install uC 51 on two  2  different computers  provided that the software is  only used on one computer at the same time  From your vend
12.  of the segment to its maximum size  makes only  sense in combination with parameter  size      Parameter  notext    Normally there is no way for the linker to initialise non code segments  like RAM   So the  linker puts all initialisations data in a  mirror segment   This  mirror segment    might be  accessed by the  startup    function to copy it to the RAM     Parameter  page NUMBER    If this parameter is given  the segment will be completely located inside a page of the given  NUMBER  As an example  if the segment uses  acall  and  ajmp  instructions  NUMBER must  be 2048  A fixed value can be set for the segment  parameter  size    Normally for NUMBER  only powers of 2 are used     Parameter  align NUMBER  This parameter specifies the condition for the first byte of the segment  I e  if a segment must    start at an even address  NUMBER must be 2   align  and  page  might be used in any  combination     25    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual      include    There are two versions    include  lt FILE gt   and   include  FILE   Both version include a  text   file in the assembly  The difference is    lt FILE gt  uses the path  given to the assembler by  command line  option   i    which points normally to wC 51 s  include  directory  whereas     FILE    uses the directory relative to the current directory     Included files may include further files       bytes    This directive will include a pure binary file  i e  a data table   only the format   ibytes  
13.  other case    Include the header file  bin_safe h  to declare the function  Due to the algorithm   the speed is not very fast  on a 12MHz 8051  about 8kB per sec  can be examined     Remark  If one of our competitors has such a function too  please let us know       Efficient coding    Keep in mind  that the 8051 is a 8 Bit CPU  whereas most books about C assume a 32 Bit  bolt  Unsigned operations usually are significantly faster than signed on the 8051  And the  native  data type for an 8051 is not  int   as for 16 Bit and 32 Bit CPUs   but  unsigned char      Predefined symbols    The compiler defines some preprocessor symbols  which are common standard  except for    UC_  and  18051          _ DATE today s date   __TIME   and time   _ FILE   the name of the source file   __LINE __ and the current line no    _ STDC __ defined as _ STDC_    UC _ defined as  UC __   this is uC 51 specific    _ 18051 defined as 1  this is wC 51 specific   only one leading          Some important options  command line   pragma     The compiler can be controlled either by command line  or by   pragma  directives  For the  command line options  the compiler will show a full list  if called as  UC51      Here the most    19    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    important options are described  You can pass them to the compiler in a makefile by using  the variable  C51FLAGS        8     size   speed    a    W   dMACRO   b0   nograph   noline    Debug level  1    default  or 2   If 
14.  required  the logger  can send and receive calls and SMS  The complete software required only about 15 kB of  Code and about 60 Bytes of the internal RAM  No external memory is needed     Accessing the Internet requires to compile a    TCP IP stack     For wC 51 this is no problem   the stack is finished as another reference application  the appropriate hardware is available   the board is match box sized and has a built in 10 MB Ethernet  you may find more informa   tion about the    FlexGate   family    under WWW FLEXGATE COM   The idea for the  FlexGates was to have a module with a    well known infrastructure    on the one side  and a  true Web Server on the other side  With only a very low overhead the user can access the  application on the FlexGate with a standard Internet browser or by e mail       But   returning to the topics   there is still a lot of room for further optimisation in uC 51  We  will implement as much as possible     Limitations of the demo version    The demo version comes with only two restrictions  the maximum size of the generated code  is limited to 8 kB  This is more than enough for    real world applications     8 kB allows the use  of floating point routines and    printf      functions  In one of the demos  shipped with uC 51  we have implemented a complete spectrum analysis in only about 6 kB    The second restric     tion is  the demo version may only be used for educational or evaluation purposes     WWW WICKENHAEUSER COM wC 51 V1 10 Use
15.  result would be a  constantly triggered watchdog reset  To omit such things  the user can specify a custom  function  It is called immediately after reset  but internal RAM is already cleared and the  stackpointer is set  so it might be even written in C        This tells the linker  that a custom function must be called first    asm    export START DEF   START DEF 1    endasm          18    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual       The function itself  The name is given   void startup first  void            For the C515 our solution was  to start a 60 msec  interrupt  delaying the watchdog to 16  sec    Another idea is to jump directly to   main   if no initialisation of the external memory  must be done     The binary safe  _bin_safe      With this function a program can check it s integrity  We have provided this function  to lock  binary files against modifications  An example  one of our customers distributes his binary  updates  for his machines  by e mail  the users can upload the update by themselves  So there  might be a chance  that the one or other user tries to make changes in the binaries  like text  messages or something else  But the software might still work      bin_safe    will detect such changes with a very high reliability  Because it does not  compute a simple checksum over itself  it uses a 16 bit CRC instead  which is quite hard to  bypass           bin safe    will return 0  if no changes are found  Decide for yourself  what to to in the 
16. 1 8 Version was developed  Although  the 8 Version   s code generator was quite ineffective  it was ideally suited for data logging  applications  where speed and software size usually is not crucial  but where other things like  floating point math and modular structured software are more important     Still focusing on    small devices     we decided to embed the Internet in further developments   For this  a high efficient and optimising compiler was needed  This was the trigger for the  uC 51 V1 xx  It comes with a totally new code generator  generates a very high efficient  code  is easy to use and is full ANSI compatible  with only a very few restrictions due to  hardware limitations      Target processors    uC 51 is suited for all members of the 8051 family  There are no special requirements  like  the need of external RAM   We are using wC 51 on ATMEL s 89C1051 as well as on larger  systems with banked memory  like our FlexGate  512kB  and or data loggers  currently 2  MB    Ready to start header files and source codes are included for many popular 8051  family members  including some very interesting mixed signal parts  like Ts MSC1210 and  the ADuC8xx family from Analog Devices     WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    Code quality    uC 51 is based on a universal modelling system  capable of modelling all kind of 8 16 32 bit  processor cores  But more important is  that this system was especially designed to deal with     non linear    architectures  
17. 322141997 25718282   two floating points        ds b    ds w    ds l    ds f  Usage   ds X NUMBER  The   ds X  directives do nothing than simple reserve the number of bytes  words  longs or    floats  NUMBER must be a constant value or expression  For the reserved space  bytes of the  vale 255 are written  NUMBER might be zero  In this case nothing is written     Macros    A macro is a simple text replacement with some additional features  A macro may contain  other macros and usage of temporary labels     Before a macro can be used  it has to be defined inside a   macro      endmacro  block     Each macro can have up to 10 arguments   0  to   9   The number of supplied arguments is  given in   0    the first argument is in   1   If using an undefined argument  an error will be  generated  Even complete strings might be used as macro arguments  Please note  during the  expansion of a macro  the  documentation level  is decremented  see   hide    show         Temporary labels are generated for each expansion  An example      macro help text   help text in a table   dc b  1  2 0   The system   Help ID  String  0   endmacro        segment help tab  sclass text   help text 22  Valve open  7 usage   help text 25  Temperature low    another usage  help text 17    C  Copyright 2003      macro safe   save register  mov RO  1 a start  mov R1  2   len   2s0  mov A   RO   not an argument  instead a mnemonic  inc RO   next addr   push ACC  djnz R1  s0 7   s0  treated as   ID s0   ID  1 2
18. AGS  in the project s makefile  UmShell  to   d   listing only  or to something else   The default is  AS1IFLAGS    d  g   from  BIN BUILTINS MAK          Remark  We are currently planning a new version of the SLD51  For a    real breakpoint     SLD51 will modify the    jmp  0006  by something else  possible because the program is  located in the RAM   This is not possible for Flash memory  Because nowadays many 8051 s  are equipped with Flash memory  we will modify the breakpoint system to a  non destructive   system  The new SLD51 will be able to debug on all 8051 s  directly on the field used board        Note  The above mixing of assembly and sourcecode is quite simple  Because the compiler  sometimes totally reorders the logical flow of a function  the output might not be 100   synchronise in some cases  This is not an error  it s just a matter of lazy cosmetics        macro    endmacro    Usage   macro NAME    27    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    The A51 is a macro assembler  A macro is a simple text replacement with some additional  features  Programing with macros is described in the next part of this documentation     Af    else    endif    Usage  if CONDITION    This directives are use for conditional assembly  The   else  part is an option  The condition  must be full evaluable at assembly time  You can not use labels for the condition  Conditions  might be nested  like         if DEBUG LEVEL   1   1f SUBVERSION  gt  2  lcall testl2p            
19. L FILENAME    tells the assembler  that a high level language  sourcefile  currently only uC 51  corresponds to this assembler file  Only one   file  directive  is allowed in an assembler sourcefile       line   and a word about source level debugging    The directive   line NUMBER  tells the assembler  that all following mnemonics correspon   dent to line no  NUMBER of the sourcefile  previously set by a   file  directive   If the assem   bler is instructed to produce a listing  commandline   s   or to include high level sourcecode  information in the object file  commandline   g    the assembler will include the appropriate  high level lines  Otherwise nothing will happen     But   line  has a second  very important function  It may be used to lard the binary file with  breakpoints  if the assembler is instructed to expand the macro   _line   by command line s    d   and a macro with the name   _ line  is called  with NUMBER as an argument  By default  the uC 51 includes a definition for this macro as  ljmp  0006   the argument NUMBER is  currently not used   At address  0006 there will be either the  OS515 BIN  or a simple  ret   instruction  added by  LIB LIB_C STARTUP C  as a safety precaution   So  after each high  level line  C statement  the monitor OS515 BIN is called     This is a very nice feature for debugging software  Unfortunately each breakpoint is three  bytes of extra code  and a little bit of time   To disable this feature  set either the definition   ASIFL
20. OV R7 AR6  0022 7000055  0022 22 RET      FUNCTION _bang  END     And this is the result of    C 51 V1 10   we need only 25 bytes           gt  define Pl B6 0x86    gt  define Pl B7 0x87    gt bit unsigned char out bit   _P1_B6     gt bit unsigned char in bit   _P1_B7     34    WWW WICKENHAEUSER COM uC 51 V1 10 User s Manual     segment _ bang    bang     leaf function  unsigned char bang  unsigned  char       parameter  ob  in  R7  assigned to  R5   co 8007  ad 07   mov R5 AR7    Variable  ib  assigned to register  Rl1   o    gt    Simple 8 Bit Banger    gt unsigned char bang  unsigned char ob       co 8009  7b 08   mov R3  8   amp  238     gt  int i    gt  unsigned char ib     gt  for  1 0 1 lt 8 1      co 800b  ed   mov A R5  co 800c  33   rlc A  co 800d  92 86   mov 134 C    gt  out bit  o0b8128     lt  gt  ib lt  lt  1   co 800f  e9   mov A R1  co 8010  29   add A R1  co 80l1    9   mov R1 A    gt  if in bit  ib  1   co 8012  30 87 03   2 Jb 135 27  co 8015  43 01 01   orl AR1  1  I  pE ob lt  lt  1   co 8018  ed   mov A R5  co 8019  2d   add A R5  co 80la  fd   mov R5 A    gt     co 801b  db ee E djnz R3  3    gt  return ib   co 801d  af 01   mov R7 AR1  cosB01t  22   ret    end of function bang    used  R 1 3 5 7 BR         ACC PSW    uC 51 s optimisers are still not fully implemented  some parts are still completely missing    The compiler is yet a learning child  Many of the optimisers are founded on some kind of  expert system  As you might see  the system is workin
21. WWW WICKENHAEUSER COM    110 51 V1 10  User s Manual  mShell   C  C UC51 sre led led mak    File Edit Search Options Window Help File Edit Search Make Options Help    eu al Oe Mae 91  a  Dle2    fiea bin  gt   bal    if  c   c    i   Makefile for the LED Demo  _pute  va_arg ap int       0  1999 Wickenhaeuser  len       velse ific   d            Umake   C  C UCS1 bin cgS1l led x led s5l  e           A A    pEdit UmShell Sid51 FlashiMon          E CPU Registers   f  RO  38 ACC  ff  PC  803E       inc DPTR  RI  00  B  00       mov BRO A  R2  20 E H 3 inc RO   SP  3d DPTR 38888       djnz R1  _31   int i   PSW   a6   C 1 AC 0 RS 0 OV 1 P 0 for  i 0 4 lt 20 i    _pute  a t ig3l         5 7         External Reset gt  A co 8041  e4  Oco  8042  fc  Hello World  Aco 8043  fa             Downloaded 2317 Bytes at  8000    ANSI C Compiler  for the 8051 family of  microcontrollers    ol 1    oe ae een eee ee ae tee von eee weer eee Sree ees  HISO ir   N Gorter vai teehee test oot a eee aes  Target p  r  cessors iii A hee keke eee A  COde quality toi ra ds AA oes Aa  Limitations of the demo version                 0 0 00  c ccc eens  Sourcecode compatibility with other compilers                            PUULVGISION  toi  24 35 a oS oa eee eee een Be ha the   Support   Versions 5 33 LEIA Bh a BA AA  PDOUL US  AA OG gS Rs AA RE  The TUU  002 dee Sova a a Se evs ae ains  Disclaimer  2 A Gh Coats eae bas Betas hea ad   EONS Soa ee sere ahs eae Pht AE a sae Sat ide Mates a an td A Se   Tradem
22. addition to that Make uses    Macros     Think of them as variables  By default some  macros are predefined  i e        L51FLAGS    may hold extra settings  to be passed to the linker     Back to the demo   you may enter the rule above or simply open the prepared make file     SRC HELLO HELLO MAK    in UmShell  Pressing     lt F9 gt     will generate the program  It will  have something about 300 bytes in size     Now start the Soure Level Debugger    SLD51      Select    SRC HELLO HELLO BIN    for  download  maybe you must select the appropriate baud rate for your board first  if it is not  9600 Bd      After downloading you may start  by clicking on the    shoe    A  The program will run in an    endless loop printing    Hello World     You can single step through the assembler commands   C files and set breakpoints with the mouse     Note  Currently there is no way to step  over  a breakpoint  First disable it  step over it  then  enable it again  After a software stop through a breakpoint  you need two assembler single  steps  just press   lt F2 gt   twice   Because are simulated by an  ljmp  instruction  written to the  external RAM  Because  ljmp  needs 3 Bytes  it is not possible to set a breakpoint  everywhere     For the future we will revise the debugger totally  that it even might be able to debug  programs in Flash memory     WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    Important  Most of the demo makefiles will generate a pure binary file  suitable to be wi
23. al    Hex format  lower case letters   Single character   Hex format  upper case letters   Floating point format  form    dddd dddd   Scientific format  form    d dddd e     ddd   Scientific format  form    d dddd E     ddd   Same as e   Same as g   A string   the     itself    a QMMOo   xo o      a    As you see  the formatter is quite complete     The formatter will always return the number of written bytes     number of calls of for the  character handler      Note  for UART output  each newline      n   is replaced by the sequence      r n    This is  required for most terminal programs  but our FLASHMON and SLD51 are inherent to  this      This is done directly by the character handlers of the serial I O  see   LIBILIB_ASSISERIOD S51  and  LIB LIB_ASS SERIOP S51    So for the formatter each  An  counts only as one        Remark  There is no need of explicitly casting 8 bit sized values to 16 bit values  This is  automatically done by uC 51  as the ANSI standard requires  The need of an explicit cast   like other 8051 compilers need it   is not according to the standard     A word about strings in general    Besides the alphanumeric and other printable characters  you can designate hexadecimal and  octal escape sequences in uC 51  These escape sequences are interpreted as ASCII  characters  allowing you to use characters outside the printable range  ASCII decimal  20 126   The format of a hexadecimal escape sequence is ix lt hexnum gt   where  lt hexnum gt  is  up to 2 he
24. arks 0000 oh Blak A AAA RR Brie ies ta Sa Fi Seta ea Aah   TAa A 243 A ohne ee ee daca ee Ae td AA sed    Installation and de installation     sn   Installing the full version 94 5 4 ye6 aes pt A 24 CHEE A de te Wie ews 4  Documentation           0 0 0    ce ec ee eee eee ee eee eee e eee    Quick start   a micro tutorial   ee   Installati  n  nran ea a a TO TS RA OA a  Microcontroller hardware   special development boards                   Hello  Worldi ts A A A AAA  More about C  the ANSI compatibility of wC 51                             More demos  tetas aa ee daha  What s GOING ON  26  65 2054 22h cee A AAA ALA    Basic data of pC 51 cece eens  BUG reprit arca aio ale eww ten  es e a be a  Data LYPGS   vir saw eee bake eal Oba eee Pes A eA ewe   Mntesr ality pes  IA ARES RGA WA AR EEA AAA  Floating point precision             20 00  eee eens  Pointer types  00 aed Me ad pe ad eee Se ES oe  Memory models 2200 5 253 3 e tee AS AA eRe  8051 MEMOry MOdMIETS   0  cobras codes aa stan  Understanding memory modifiers  memory spaces and segmentation      Memory modifiers in typedefs              o  oooo ocoooocoooocoo  Register USO  cuarta oud kee Ode we A Na  Interr  pts IN Ge Pai ES AA AAA A AS  Dealing with call graphs                   oooo oocoocococr  Using the    printf   formatter                    o oooooococcococcr o   A word about strings in general               0    ccc eee eee nee  Mixing C and Assembler              o ooocccococo eee eens  How  to use assembler  
25. c data of pC 51    Bug report    If you think of having found a bug  please let us know  We will try as fast as possible to  solve it  Please include a small source to track the bug  Please send bug reports only to  UC51  WICKENHAEUSER  DE        Data types  uC 51 is offers the following data types     Integral types  char 8 Bit 0  255  chars are treated as    unsigned   this is ANSI compatible  unsigned char  as above   signed char 8 Bit  128   127  please note  as a constant  128 is int  ANSI    short 16 Bit   32768  32767  please note  as a constant  32768  is long  ANSI    int  as above   unsigned int 16 Bit 0  65535  long 32 Bit  214783648  2147483647  unsigned long 32 Bit 0  4294967295  float 32 Bit IEEE format    char unsigned bit 1 Bit  the modifier  bit  is no ANSI keyword     all data is represented in the  big endian  format  Data types not mentioned here are mapped to  the next smaller types  like double to float  long long to long          The data type    bit    is 8051 specific  It has the values only 0 and non 0  the integral represen   tation is 1  but the integral value 123 is seen as non 0 too        Floating point precision    The floating point routines are based on IEEE proceedings  Rounding is performed as  proposed  All mathematical library functions  like  sin         have been implemented by using  industrial approved algorithms and approximations     Pointer types    generic   far  pointer 32 Bit  explained later  may point to everything   xdata poi
26. cated in the  code   space  but what about  pc    Well  it is definitely not constant  because pc can be written   So uC 51 will spend a  generic  pointer in the  xdata  for it     Even if you qualify it as       const char  const pc  HELLO      uC 51 will use a generic pointer  although both in  code   because pc is a pointer and not an  integral type        For an explicit memory determination you may use the memory modifiers     xdata int a     a is xdata  this is the dafault too    near char u     u is near  access is fastest    inear char x     x is in the inear  access is a little bit slower   inear buf 50     if more internal memory is needed  inear is the     best choice   unsigned char flag motor state     On or off   code float 3  12 23 3 45 5 99      a look up table       12    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    Memory modifiers for pointers follow the same rules as the ANSI  const  and  volatile   modifiers        code char  code pc  HELLO      This will fix pc as a bullet proof     16 Bit code pointer  pointing to code  xdata char  near xp     xp is in  near  but  xp is  xdata   far char  fp     fp is in  xdata   default   the  far      is obsolete  but may be more readabl       Summary  Modifying the memory type in some situation will result in an optimised memory  access  uC 51 will track the modifiers over a random number of indirection s  But don t  exaggerate it  the compiler will have the better overview than the user       Memory modifiers 
27. converting sourcecodes from other compilers concern non  standard language extensions of these compilers  Usually the uC 51 compiler will tell you   what it does not like  Some of the most important things you should know     Memory usage   memory models    uC 51 offers only two memory models   small   this is the default  and  large   The only  difference between the two models is the type of memory for the local variables  For  small  it  is the internal RAM  for  large  it is external RAM     Non constant Global variables will always be placed in external RAM  except something else  is explicitly specified  Globals might be placed in the internal RAM by the memory modifier     near     in the indirect internal RAM with  inear          Constant global variables are located in the code memory     Bit variables are declared as    unsigned char bit     Absolute addresses    Assigning an absolute address to a variable is done by the     operator  i e   near unsigned  char PO   0x80    After     only a number  a constant expression or a defined constant  i e     define SCL 0xB0 7      unsigned char bit scl_bit   SCL     is allowed     Interrupts    Interrupts might be written in uC 51  The vector is not included in the declaration  binding an  interrupt to a function requires the macro  IRQ VECTOR   as mentioned in the previous  text      Assembly language    uC 51 s assembler uses other directives  However  mnemonics are full compatible to the  8051 standard  Best way to conver
28. don t want to take an as close look at the internals  don t worry  The simple usage  of uC 51 does not require this     int a   char pre name    Bart    const char last name    Simpson      void say hi char  pc  char  pd     printf   Hello  s  s n  pc  pd       void do_it void     char no 1    no 0  0   say hi  pre name  last name    say hi no   King Kong           a    pre_name  and    last name  are so called  top level definitions   They represent the data  itself   a  and  pre_name  are global variables with read and write access  uC 51 will place  them in the external RAM  xdata     last name  is declared as const  The compiler knows   that it might only be read later  So it is safe to locate it in  code   the Code space  some other  compilers offer memory models  that blindly pack everything in the external RAM  only that  they can later use single 16 Bit pointers  what we think is an incredible waste of RAM  see       above       11    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    Same is for the String  King Kong   It is definitely a constant string  so it will be placed in  the  code  Code space too  The  no  is local  there is no choice for placement  in the small  model it will become a  near   in the large model it will become a  xdata   It is not  top level   too     So  pc  and  pd  might point to anything in the 8051 s code space  Because they are pointers  and not bound to real data  they are not  top level   This means  the compiler can not  automaticall
29. ed char _bin_safe  void      success  return 0    math h    All math functions have a precision of at least 7 significant digits  All algorithms use indus   trial approved iterations  If you need a special mathematical function  let us know     Constants     M PI 2 1 570796326794895    ANSI  M PI 3 14159265358979    ANSI  M TWO PI 6 28318530717958     Constant NOT ANSI    Functions  all according to the ANSI standard         float atof  far char  pc      convert a string to float   float sqrt  float f      square root   float sin float x      sin   function in radiants  standard   float cos  float x      cos     float log float x      natural logarithm   float logl0 float x      decimal logarithm   float exp float x      exponential function   float pow float x      power function    8051 specific    irq52 h    To bind an interrupt to an interrupt function   irq52 h  defines a macro   name  is the name of  the function   loc  is either the address of the interrupts or its name  like INTO  SERIAL             IRQ VECTOR  name  loc      32    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    reg51 h  reg52 h  reg535 h    Header files for the most common CPUs  other CPUs will follow  The header files for very  specific CPUs  like the both mixed signal parts   are located in the directory above their  demos     Appendix A  Migrating from other compilers    As stated before  uC 51 was designed to be as close to the ANSI standard as possible on the  8051  That is why most items in 
30. ed pointer may point to everything  Currently far pointer are only     virtual    pointers  You can not declare a variable as far  this will be possible in future  version  In some cases the far keyword may be left out  such pointers are called   generic  pointers  the same is for  local  data types  because there is no explicit  modifier      Understanding memory modifiers  memory spaces and segmentation    On common PCs there is no need for memory modifiers  because all data can be accessed  over a single  usually 32 Bit  pointer type  the memory is  flat   A few years ago  in the days  of the  good      old 16 Bit PCs  modifiers were quite common  Even in some header files  they still live on  although without any effect         For uC 51 we implemented modifiers as an    option for the wise     If you do not want to deal  with memory modifiers  just don t use them  The price you have to pay is code size  memory  usage and speed  An example  the Dhrystone demo   SRCIDHRYIDHRY C     which is one of  the standard demos of ancient times  does not use them  Nevertheless  C 51 compiles it  But  if you let it run  it will be quite slower than it could be  Some competitors offer additional  memory models  which are better suited for such kind of source code  but they usually are of  limited practical use  because they have other disadvantages     and lesser portability      For an explanation of memory modifiers  let   s start without them and look at the following  code  If you 
31. escribe the logical hierarchy of a program  Because each  program begins with a  main    function  main is always a  root  of the call graph  After the  call graph is built  the linker knows about the used local space  An example  if main   calls  two functions  a    and  b     both may share the same local data  if none of them calls each  other   In other situations they may only share parts of the data or none at all  This informa   tion is represented by the call graph     13    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    Call graphs can either be totally exclusive or identical  Reasons for having more than one call  graph in a program are interrupts or Assembler called C functions  If the linker detects  irregularities in the call graph it is not able to build the binary     The depth of a call graph will represent the amount of used stack  On the a 8051 each call  takes 2 bytes  so the depth of the call graph is about the same as the required stack space  this  is why each call takes two levels in the call graph      Of course  the compiler will at first try to use registers for parameters and variables  Only if  more space is needed  local variables are allocated     Using the    printf      formatter    Formatted output is a too precious routine to waste it to a single  printf    implementation  For  this our  printf    simply calls a formatter function with its arguments and an additional output  function  By using this mechanism it is very easy to generate a 
32. formatted output to almost  everywhere  One example is  SRC RS232_2 RS232 C2 C   where a function  com2_printf     is defined with only a few lines  On our data loggers  we use a  flash_printf    to write format   ted messages to the Flash memory  For our LC Displays a  Icd_printf    is supported  For  uC 51 s libraries the  sprintf    functions is based on this formatter     You can find the complete source code of the formatter    doprnt      in the file   LIBALIB_CIDOPRNT C   Feel free to modify it  The system is  to pass a character handler   the format string  and the caller s arguments to the formatter     Currently the  printf    formatter accepts formatting instructions of the type      flags   width    prec   1   L  type_char     flags   optional     Left justifies the result  pads on the right with blanks   If not given  it right justifies the result  pads on the  left with zeros or blanks      Signed conversion results always begin with a  plus     or minus     sign    blank If value is nonnegative  the output begins with a  blank instead of a plus  negative values still  begin with a minus      width   optional   Minimum number of characters to print  padding  with blanks or zeros     prec   optional   Maximum number of characters to print  for  integers  minimum number of digits to print        L   optional   Treat the following type as 32 bit  instead of 16 bit   type_char  u Unsigned format  d Signed format    14    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manu
33. g  but the collections of rules  these  expert systems are based on  are still quite small and in other cases  the results will not be as  much as 40  better  But C 51 has the ability to do it and  we have first V1 10 yet        END     35    
34. he interrupt  driven one  In some cases  a polled version might fit better  the polled  version gets all possible values  0  255  and is smaller in size  but the  interrupt driven version allows source code debugging  Set to    p    to use  the polled version    PFLAGS  If set to    PFLAGS FULL_ PRINTF    the full featured printf   formatter ist  used  This might be interesting  if format strings are dynamically generated  during execution  By default the value is    SMART PRINTF     which allow  the compiler to tailor the formatter to the minimum size     The default definitions for the macros above are found in  BINBUILTINS MAK   If you  want to get help about additional parameters  you can start the program  Assembler   Compiler  Linker       from command line with the parameter          One of the most important items is  ASIFLAGS  d       Usually the compiler writes a defini   tion for the macro   __line  at the beginning of each translated file  Currently this macro does  nothing else than make a call to location  0006  where the debugger is expected  The assem   bler then will expand this macro for each C source line in its output  so you can single step  through your program   But if the software development is finished you should disable this  feature  because for each line 3 bytes are spend     if you forget it  this is not crucial  because  there is a default handler  so your software won t crash         The format of the numbers in the L51FLAGS can be either  0x  
35. he supplement     About us       Wickenh  user Elektrotechnik    is a small company  located in the southern part of Germany   This is our address     Wickenh  user Elektrotechnik   Nikolaus Lenau Str  20   D 76199 Karlsruhe  Germany   Phone    49 0  721 98849   0   Fax    49 0  721 98849   29   E mail  SERVICE WICKENHAEUSER  DE  for administrative contacts only   UC51 WICKENHAEUSER  DE  for wC 51 related correspondence           The future    There are lots of improvements  optimisations  tools  demos      on our list  One is the  Graphical User Interface for wC 51  Although the included one is quite sufficient  putting it  all under one IDE might be a little more convenient  Additionally we want to expand the  FlexGate family by some members  and port the uC to other cores     3    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    Disclaimer    If you disagree in any of the following items  installation and use of this software is not  permitted     Errors    Our software and hardware has been carefully developed and tested  But it is a well known  fact  that at the contemporary state of technology  it is not possible to guarantee that a  product is completely free of errors  For that reason we decline any liability  loss  or damage  caused directly or indirectly by our software and or use of our hardware  The use is at your  own risk     Trademarks    All terms mentioned in this software and the complementary documentation that are known  to be trademarks or service marks
36. ike  puts      except it does not add the new line char at the end  The  inputse   can be used to retrieve a  input from the user to the string  where   pc  points to  of size  max   The result is the length  of the user s input  at maximum this is  max  1   The string has a   0  char at the end     void putsl far char  ps      Non Standard    unsigned char inputse far char  pc unsigned char max      Non Standard    Remark  inputse   is used in the demo  SRC MINI535 M535V3 C     string h    A few ANSI standard string functions     int strlen far char  px    int strcmp  far char  pa  far char  pb    int memcmp  far char  pa far char  pb  int n    far char  strcpy  far char   pdst  far char   psrc         A non ANSI byte move  note   src  is the first argument    But also quite common     void bmove  far void   psrc  far void   pdest  unsigned int count      Remark  all memory move functions use generic pointer  so memory can be moved from and  to everywhere  If the memory type of the source and destination is known  i e  both external  RAM   a more specific move function could run very much faster  We will supply these  in  the next version of uC 51     31    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    ctype h    char tolower char c    char toupper char c      stdarg h  Defines ANSI compatible access to variadic arguments    va_start y y    va_arg  x y    va end x      bin_safe h    This file declares only one function for the  binary safe   as stated before      unsign
37. in typedefs    This is not recommended  There is no situation  where a memory modifier can not be put  outside a typedef     Register usage    On the 8051 we have 4 register banks  By default uC 51 uses the lower two banks  0 and 1    If not desired  as it might be for interrupt functions   the compiler can be instructed only to  use bank 0  An example for this can be found in  SRC MISC SOFT_RTC C   Bank 2 and 3  are completely free  We suggest to reserve them for debuggers  protocol stacks and other  background stuff     Of course  they can be used as regular space in the  near  memory  But currently the linker  can not do this automatically  because it can not locate  near  segments below the  bit   segment  For this  the easiest way is to partition those  at maximum 16 Bytes  manually  i  e      near char buf a 8    16   near char buf b 8    24     This will reserve two buffers in the bank 2 and 3 area  the     directive is described later      Interrupts in C    Interrupts may be written in C  uC 51 is keeping a list of the trashed registers during a  function and will only save the trashed registers  To declare a function an interrupts function   the  interrupt  keyword must be added after the declaration  The function must have a proto   type  To assign the function to an interrupts  the macro  IRQ_VECTOR function  cpu_irqad   dress   from   lt irq52 h gt   is needed  See  SRC MISC SOFT_RTC C  as an example     Dealing with call graphs    Call graphs are graphs  which d
38. ined in an include file   As a  convention  all of the 8051 s SFRs are upper case letters     In cases  where a number is expected  you may even use a calculation  like simply writing       mov R6 a   you could write  could be useful in macros  use braces      WORKREG 5  mov R WORKREG 1  a          Names  variables and labels    All names must be composed as in C  first char        a z  or  A Z   rest may contain numbers   A name must not exceed 64 characters  else this will lead to an error message     Labels have a following colon and are treated as addresses     A variable is a symbol  that can hold a value  assignment   Multiple assignments for the same  symbol are allowed     nr 11  mov A  nr   nr is 11  nr 21  mov A   21  gt  nr is 21    Temporary labels may have a       as first sign  Temporary labels behave like normal labels   except they will never appear in a listing     Numbers    The assembler will accept many different formats     123 regular decimal number   x  8 bit number  ASCII character     AB  16 bit number  like ASCII character      A  256   B      0x100 Hex number  256 dec   C language syntax    100 Hex number  256 dec   Motorola syntax   0100h Hex number  256 dec   Intel syntax  version 1   0100H Hex number  256 dec   Intel syntax  version 1   100h Hex number  256 dec   Intel syntax  version 2   100H Hex number  256 dec   Intel syntax  version 2   0100 Octal  base 8  number  83 dec   C language syntax    23    WWW WICKENHAEUSER COM wC 51 V1 10 User s Ma
39. like the 8051   s Harvard architecture  with separated code and data  space      uC 51 is the first implementation for this system and the results are very good  There is only  a very small part in the software especially dedicated to the 8051  but the generated code can  easily compete with the    market leaders     as they describe themselves   In some cases  the  code is even better  i e  1C 51 V1 10 translates the SIEVE demo   SRC SIEVE SIEVE C      which is one of the standard demos  with a module size of 142 bytes  the closest competitor  needs 6  more      the total code size is only 897 bytes   no one of the    market leaders    does  beat this     Read more about uC 51 s optimisation techniques and a comparison with other compilers in  the appendix of this documentation     If demanded  like here  the compiler utilises a    call graph    scheme for minimum usage of the  precious resources  for the 8051 this is undoubted the internal RAM   In combination with a     data flow optimisation    the amount of allocated internal RAM is astonishing low     Before publishing uC 51 V1 xx we have implemented  for customers and as a test suite   many reference applications  One was a data logger  controlling a RS485 network of remote  sensor nodes  The logger has a built in a cellular  GSM  modem  2MB Flash memory  for  program and data   only     256 Bytes of internal RAM and a Real Time Clock  For minimum  power  the modem is hooked to the cellular net only for short times  If
40. ment  This segment is cleared by  startup       On demand  the linker will generate additional symbols  allowing access to internal data of  the segments  like size  load address       This feature is normally not used    Note  The linker will remove all unused segments  only referenced segments of segments  containing an  org  parameter will be linked to the binary     Parameter  org NUMBER    24    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    Sets an absolute address for this segment  Only once per segment allowed  The program will  start with the first label of the segment with org  0000  This value might be added by and  offset from the linker  like for our development boards  The linker offset is set to  8000 by  default  where the RAM starts and the program will be downloaded to    Parameter  sclass NAME    Sets the memory class of the segment  If no  sclass  is given  the default sclass is  text     Allowed NAMEs for the 8051     text Code  constants   EPROM    This is also the default storage class  xram The external RAM   bit The bit field in the internal RAM  from  20   2F    dram The internal  direct accessible RAM  from 0   7F    dram The internal  indirect accessible RAM  from 0   FF     Parameter  size NUMBER    Defines the maximum size for this segment  For multiple set  size   only the largest directive  is used  The compiler makes intensive use of this directive to manage local variables     Parameter  fill    If set  the linker will always set the size
41. ntegral promotion    The ANSI standard defines the  integral promotion     It says  that all calculations smaller than   int  are extended to  int  size  and  float  to  double       On a 8 Bit microcontroller this will  produce a huge overhead of code  You can enable the integral promotion for uC 51 too  by  default it is disabled  uC 51 uses a  smart promotion  scheme  it will only extend the size of a  result  if it is required  For functions integral promotion is omitted  if a prototype for the  function is given     17    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    Old style functions    They may be used in the  common old way     but all arguments are automatically treated by  integral promotion  even if there is a prototype following  Mixing old style and new style  declarations in different files may lead to undesired results       Defining your own SFR s   defining absolute addresses with        One of the reasons for the success of the 8051 family is  that new family members simply  have more or other  special function registers   SFR   To use a special family member  we  have supplied some register definition files like  INCLUDE REGS51 H  or    REG52 H  or   REGS35 H   To extend or modify the given definition files  there are two ways     The first way might be used  if it is important to have the definition for assembler as well as  for C  First add the definition for Assembler  like  WPM_BIT   P3 4    Then in a second line  this definition must be mapped t
42. nter 16 Bit  external ram    code pointer 16 Bit  code memory     WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    near pointer 8 Bit  internal RAM  address 0  127   inear pointer 8 Bit  internal RAM  address 0  255   bit pointer not an allowed type    Memory models    uC 51 supports two memory models  small and large  in the small model all local variables  are located in the internal RAM   near     This is the fastest model  Unfortunately there are  only 128 Bytes  If large blocks must be allocated as local variables  the large model must be  used  Currently it is not possible to mix both models in one application  Both memory models  use the call graph scheme for minimum RAM usage     The type of the memory which is used for the local variables and parameters is the only  difference for the two memory models  Global variables can be placed in both models  anywhere  By default  if nothing else is specified  they will be placed in the external RAM or  in the code area  if it is a constant   But if using the memory modifies  xdata   code   near    inear  and bit  each variable can separately been placed anywhere you like  Of course   generic pointers can address the whole 256   16 MB address space in both models        The names  small  and  large  denote only the size of the available memory for the local  variables  Nothing else     By default the compilers chooses the small model  To use the large model  the flag   C51FLAGS  must be set to  CSIFLAGS   large  in UmShell  
43. nual     111 Binary number  7 dec     000111 Binary number  7 dec    0111b Binary number  7 dec   Intel syntax  version 1   0111B Binary number  7 dec   Intel syntax  version 1   111b Binary number  7 dec   Intel syntax  version 2   111b Binary number  7 dec   Intel syntax  version 2     We recommend the formats with     and      They are the most readable ones     Operators    The A51 uses the same operators and hierarchy as C  except bit addressing        Braces  highest Priority  4 Bit addressing  like ACC 7  highest bit of ACC         Multiplication  division  module      As sign   lt  lt   gt  gt  Shift operators   lt   gt   gt    lt   Comparison  value is 1 if true  0 for false   amp  Binary and  di Binary exclusive or    Binary or   amp  amp  Logical and  Il Logical or  Directives   segment  Usage  segment NAME     Parameter Jopi     Open an existing or a new segment  NAME   The linker will collect all segments with the  same NAME and treat them as an unit  The compiler will generate a segment for each C  function  We recommend to use as NAME the name of the function  or entry label  plus a  leading      For functions each function should have its own segment for the code  whereas  for data of the same type only one segment should be used  The names for the data segments  are given and so the  startup    function can initialise them properly  the IRQ driven serial I O  driver     LIB _ASS SERIOD S51   uses this technique to declare a byte variable in the  nearbss   seg
44. o the appropriate C symbol  because C adds an        WPM_BIT   WPM BIT      In the last step the new symbol must have a declaration for the  compiler  extern unsigned char bit WPM_BIT       The Second way is more easy  but it declares the new symbol only for C use  simply add the  definition to the declaration   unsigned char WPM_BIT   0x85    That s all     Overwriting library functions    You may overwrite C library functions  those with a    as first character      For instance if  you think you have a better  sin    function than ours  simply add your own as an   OBJ file to  your program  Symbols in objects files always have a higher priority than library symbols     If you overwrite an assembler symbol  the linker will use your definition  but it will present  you a warning  which you might ignore       The job of startup      The  startup    function is responsible for the initialisation of the microcontroller s stack and  all types of RAM  and even Bits   All variable spaces are either set to 0  or initialised by their  initial values  You may customise the startup   function to perform some extra work  find it  in    LIBILIB_CV  it is not a real C function  but it requires the C preprocessor      Sometimes the user might be interested to run one specific routine before doing all the initial   ising  One example is the C515   s impacient watchdog  It has a timeout of only 65 msec  But  if there is a lot of data to initialise  it might take longer than this period  The
45. omplementary documentation is available as separate files  Please read the documenta   tion carefully prior to the use of the software  You will find the  latest remarks  in the file   README TXT      Quick start   a micro tutorial    Installation    uC 51 will work on any    Win9x     or better  computer  There is no special requirement  For  installation simply follow the advices  again  wC 51 does not make any  hidden  changes on  the installed computer  like copying DLLs to the system directories  or writing unsolicited  entries in the registry      You can remove it 100      Important  Please note  that uC 51 must be installed in a path without    whitespace charac   ters     i e     C   MyFiles uC51         but not    C   My Files uC51          because wC 51   s    MAKE      system is currently not able to handle such filenames     WWW WICKENHAEUSER COM uC 51 V1 10 User s Manual    Microcontroller hardware   special development boards    As stated before  uC 51 is a development system for all 8051 family members  But for devel   oping and testing  a convenient way is  to use a  special  board  where you can download and  run binary files in an external RAM  Of course  there are alternatives  like using an    emula   tor    or doing a pure software simulation  decide this for your own     Later  if the program or the tested functions are running as expected  they might be directly  used on or programmed to the dedicated target system     Note  We recommend to use such a 
46. on for the assembler is in a later chapter     Reentrant functions    Reentrant functions are seldom required  To learn more about them  see   MISCFACULTY C   There is only one special case  where reentrant functions are really  required  this is  when a function is called indirect as well as direct  like  putc     it may be  used direct to send single chars to the UART  but it is also used as a parameter for the   printf    formatter  which calls it indirect  Our advice is  don t care about reentrant functions   unless the linker explicitly tells you to use them     On the 8051 reentrant functions are not allowed to have variable argument lists     The execution speed of reentrant functions is somewhat slower than non reentrant ones  if  there are local arguments to be saved  because all reentrant functions share one memory  space for local variables and passed non register arguments     Indirect functions    Indirect functions may be used in the common manner  there is only one limitation  indirect  functions are limited to 6 Bytes for arguments     All indirect functions will become a root of a call graph  so the linker will not share memory  for local variables between them     Variadic functions    Functions with variable argument lists are common C standard   like  printf      Variadic  functions must have a prototye  There is one special exception for arguments  variadic  arguments are always promoted to integrals  You need to consider this to access them later       I
47. or you will get a 12 digit code   that we will named    Key1    here     WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    Registering uC 51 is a two step process     1  First you must start    KEY51 EXE      If a valid license is found for this computer     the data will be displayed  else you must enter the    Keyl     With this information     KEY51 EXE    will collect some computer specific data and generate a new key  which  has 20 digits     Key2      This    Key2    must be sent to us by e mail  where it is processed by  a machine in short intervals  a few minutes   If you cannot send e mails from this  computer  you must send us the    Key2    manually  as an e mail      2  If everything is ok  you will receive a license file with the name  UC51 KEY    as a reply   You must copy this file into the  BIN    file of your uC 51 installation  After that program     KEY51 EXE    should find a valid license  if started again     Your privacy is not touched  The    Key2    contains only hardware specific information with a  strong redundancy  you may change quite a lot of system components before the license file  won t be recognised as valid any more       If you request more than two license files  you can only order them manually  by e mail to   serviceQwickenhaeuser de  and we might ask you for the reason          We have ensured by independent trustees  that uC 51 can be always distributed  maintained  and licensed   no matter what will happen     Documentation    The c
48. r s Manual    uC 51 does not make any  hidden  changes on the installed computer  like copying DLLs to  the system directories  or writing unsolicited entries in the registry      You can remove it  100   if using the included uninstaller      Sourcecode compatibility with other compilers    uC 51 is a full ANSI C compiler  So it will accept any ANSI C compliant sourecode  with  only a very few 8051 specific restrictions   However  due to the limitations of the 8051  each  manufacturer has made specific extensions to his implementation     One of our most important design topics was  to make wC 51 an highly portable and easy to   use compiler and not yet another clone of any other very specific implementation    But in most cases sourcecodes from other  8051  compilers can be compiled without any  problems  if only a few items are regarded More information about using sourcecodes from  other compilers with uC 51 can be found in the appendix and in the included demos     Full version   The full version is offered through our web shop and through different distributors  Please  visit our website for detailed information    Support   Versions    A license for uC 51 is valid for all    minor    releases of this version  here V1   You can  download new releases for free from our website  Questions about the actual release should  be sent to UC51 WICKENHAEUSER  DE  Support is only possible by e mail        You will find a list of improvements changes of new version   gt V1 10  in t
49. se you can tell Make to rebuilt the  whole project without regarding the dependencies     The place where a macro is defined  is not important  because first the make file is totally  read  It is allowed to overwrite macros or to use other macros as parameters  in brackets with  a leading       A simple      is replaced by the filename of the destination  without file exten   sion   a    lt   is replaced by all dependencies  for UmShell this is   lt F8 gt        It is possible to supply an own rule for a dependency  In this case a default rule will be  ignored  if there is one  An example for this may be found in  LIB LIB_ALL MAK      In a future version we will support UmShell with some kind of  Expert           Technical description of the compiler UC51 EXE    This chapter will work out some of the deeper details of the compiler  It will follow in an  later version of this documentation       Technical description of the assembler A51 EXE  The A51 is a macro assembler  It was designed as a reliable and stable workhorse and  as for    the compiler  the A51 is almost totally independent from the 8051 too  A51 operates as a  single pass assembler  Thus making it very fast     22    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    Mnemonics    The syntax uses the common standard Mnemonics and is sensitive  Mnemonics itself are not  case sensitive  but any used symbols  you may write  mov a  0  or  mov a  0   or  mov  ACC  0   but not  mov acc  0   because ACC is a symbol  def
50. set to 2  the compiler will  include more source info in the output  but the code might   be less optimised    Optimise for size  this is the default   Optimise for speed   Suppress strict warnings   Suppress all warnings   Define a Macro  to assign a value use   dMACRO VALUE    Use only register bank 0  by default 0 and 1 will be used   Disable the call graph  Will need a lot of RAM      Don t emit code for the macro   _line   You can supply an own  version for this macro  see  Technical description of the assembler        Some parameters are also available as   pragma s         pragma option  gX  Set debug level  X 1 or 2   Fpragma option  a  Suppress strict warnings      pragma option  a   Enable strict warnings       pragma option  w  Suppress all warnings       pragma option  w   Enable all warnings       pragma cpu  b0  Use only register bank 0      pragma cpu  b0   Use register bank 0 and 1      pragma cpu  noline  Don t emit   line  directives      pragma cpu  noline   Emit    line    directives       pragma cpu  nograph  Don t emit call graph information      pragma cpu  nograph   Emit call graph information      pragma cpu  large  Switch to large memory model      pragma cpu  small  Switch to small memory model      pragma cpu  labeldist X  Set new label distance for short jumps      pragma cpu  labeldist   Restore default label distance    The label distance is a number  currently set to 50 as default   Because uC 51 has no internal  assembler  it does not know  if
51. special development board for developing functions and  algorithms in the RAM  Finally  you may use them on the intended boards  where debugging  might be more difficult     Alternative  Some of our boards  like the FlexGate  offer two different memory models   memory model one allows download to RAM  like the following picture   memory model  two offers several different 64kB banks of Flash memory for the code  the RAM is totally  free for data  Switching between the two memory models is handled by our  0S535 BIN    together in combination with a programmable logic chip  That s why they are best suited for    development and field use     Here  we assume that you use a board with the following hardware structure  like our  MINI535  FLASH M1  FlexGate        where you can download the binary files with the    included tools  FLAsHMoN  M   and or   sLDS1 gt   dd  gt         SFFFF   Code  amp  Data joint tog    8000   as XRAM for download    S7FFF fe OS535 BIN   0000 p Eprom  Data Code                   The CPU should be a 80C535  C515  8051 compatible or a generic 8051  Most of the demos  require a 11 0592 to 12 0 MHz crystal  If you have an 80C535 or an C515 with 12 0 MHz   you can start immediately  Burn the file    SRC OS OS535 BIN    to an Eprom  format is     binary      For other commonly used CPUs or crystals  the    OS535 BIN    supports a switch   but nevertheless  it must be rebuilt  as shown below  The board must have a serial port   RS232   If your hardware does ha
52. sy  All parameters are passed in bank 0   There are 4 groups of each 2 Bytes  sstarting from R7 R6  L H  to R1 2  L H   Allocation is done left to right  where R7 is the first     If 1  Par  is a Byte it is in R7  if it is 2 Bytes it is in R6 R7  H L   The next Parameter will allocate R5 or R4 R5  H L   If a parameter has 4 Bytes it will allocate either R4  R7  HH  LL  if it is free or R3  RO    Results are passed in R7  R6 R7  H L  or R4  R7  HH  LL    The assembler function may change all registers and may use bank 1 for temporaries  if it is  sure  that the callers above have enabled bank 1 access  which is the default      If you pass more arguments to a function  they will be stored in local memory  for assembler  usage this is not recommended  it requires access to the call graph   in this case it is better to  pass a pointer to the assembler function     How to use assembler    There are two ways to write software in assembler     The first  put all assembler functions in one source file  extension   s51   a shown in some  demos  The second  embed a block of assembler instructions in an   asm      endasm  block of  a C file  This has the advantage  that the C Preprocessor may be used too  like in   SRC RS232_2 RS232 C2 C   If there is only one line of assembler  you can use the   Fasmline  directive  The instruction follow immediately      asmline nop   or in the next line       asmline   nop    It is possible to include assembler in a C function  but this is not recom
53. t assembler files to uC 51 is to use a text editor and some  bulk  search and replace      33    WWW WICKENHAEUSER COM uC 51 V1 10 User s Manual    Appendix B  A demo of uC 51 s optimisers    In this appendix  we made a comparison with the KXXX compiler V6 21  You can trace the  results  they offer a 2kB limited demo version       The test function is some kind of  bit banger   shift something in and out       This is the result of KXXX V6 21   it needs 35 bytes to solve the problem     bit out bit    bit in bit         Simple 8 Bit Banger  unsigned char test  unsigned char ob     int 17  unsigned char ib   for  i 0 1 lt 8 1i       out_bit  o0b amp 128     ib lt  lt  1   if in bit  ib  1   ob lt  lt  1      return ib      C51 COMPILER V6 21 BANG                            ASSEMBLY LISTING OF GENERATED OBJECT CODE    FUNCTION bang  BEGIN     22 Variable  ib  assigned to Register  R6          22 Variable  ob  assigned to Register  R7              Variable  i  assigned to Register  R2 R3        0000 E4 CLR A  0001 FB OV R3 A  0002 FA OV R2 A  0003 2C0001   0003 EF OV A R7  0004 33 RLC A  0005 9200 R OV out_bit C  0007 EE OV A R6  0008 25E0 ADD A  ACC  000A FE OV R6 A  000B 300003 R JNB in bit  C0004  000E 430601 ORL AR6   01H  0011 200004   0011 EF OV A R7  0012 25E0 ADD A  ACC  0014 FF OV R7 A  0015 OB INC R3  0016 BBOOOL CINE R3  00H   C0009  0019 OA INC R2  001A 200009   001A EB MOV A R3  001B 6408 XRL A   08H  001D 4A ORL A R2  001E 70E3 JNZ 2C0001  0020 200002   0020 AF06 M
54. tant header files  All functions work as the standard proposes     The following two defines simplify the use of the 8051 s  native  data type and are quite  common     typedef unsigned int uint   typedef unsigned char uchar     void putc  uchar  reentrant     reentrant because called indirect  uchar getc  void      30    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    uchar kbhit  void         printf   and sprintf   return the no  of characters printed  ANSI      read more about the format string in an earlier chapter       int printf  far char  pfmt            print using putc    int sprintf  far char  dest far char  pfmt            print to a string  int puts far char  ps      result is always 1  ANSI     The following two functions implement a pseudo random number generator  based on a  linear congruent algorithm  The sequence will always be the same  depending on  seed   A 4  Byte global variable will be used to keep the last result  sourcecode in   LIB LIB_C RAND C         unsigned int rand  void      pseudo random between 0  65535  void srand unsigned int seed      set starting value for the sequence    Remark  on a microcontroller a shifting register algorithm or one of the timer  registers may be better suited  we will show some alternatives in the next version       Conversion functions for strings to integer or long values    int atoi  far char  pc    long int atol  far char  pc      The following functions are non standard  but often quite useful   putsl   is l
55. te  library functions   in C and then optimise the compiler to produce    handcrafted    quality  Although it is more  difficult at first  it will pay of  because the optimiser will surely reuse  what he learnt by  this       More demos       In    SOURCES    some more demos are found  All of them can be compiled by loading their  Make file in UmShell  The folder    SRC A51    does contain only one Make file for different  projects  select the target in the selection box of UmShell     What s going on     Now  as you know how to write a C program  it might be interesting to track it s way to a  binary      In the first step all C files are translated by the compiler  UC51 EXE   The compiler may  require some system include files  usually  INCLUDE         The compiler produces a plain  assembler source file    S51   Immediately after that  the Assembler translates the compiler s  output to an object file    OBJ   So the first step is the transition from   C to   OBJ     For the next step the linker takes all object files at once and puts them together to a binary  file    BIN   If there are still references left open  the linker tries to get those missing refer   ences from the supported libraries    LIB   you may pass as many libraries as you want to the    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    linker   Together with the binary file a listing    LST  might be written and a memory map  file     MEM   Both are intended to be read by debuggers  or the user      Basi
56. th  FLASHMON or SLD51   Other 3 rd party downloaders might only support Hex files  To  instruct the UmShell to make a Hex file  from the always generated binary file   simply add a  new line in the makefile  Here  the additional line would be     hello hex  hello bin    More infos about makefiles is given in one of the following paragraphs     More about C  the ANSI compatibility of yC 51    To learn more about the C language  we recommend to contact a bookstore or a public  library  Another endless source of information is the Internet  Many primers and interesting  articles may be found  For the future a step by step manual   ideal for educational purposes    will be available     We have designed the uC 51 for easy use and we have tried to get optimal compatibility with  ANSI C  Of course  on a micro controller you won   t find functions for disk access or similar   But if you keep in mind  that a 8051 has only very limited resources  you could easily  develop algorithms on your PC and then later transfer the software to the 8051     Large parts of the floating point libraries and other stuff of uC 51 have been designed with  Borland C   5  the source code may be compiled with Borland C   as well as with uC 51   Because of wC 51   s optimiser  the generated code size is only slightly more than if coded by  hand in Assembler  Another example of portable code is the demo       SRC DFHT DFHT C    for  which the PC   s EXE is included    We think it is the best solution to wri
57. ve other memory layout  you can easily adapt the     OS535 BIN    by following the remarks in the source code  and the appropriate make file       OS535 BIN    expects a LED on port P3 5  to let it blink  if it is ready  After a hardware reset   the LED first flashes some times faster  then keeps flashing slower  If an error occurs  data  transmission   the LED will flash irregularly  In this case reset the hardware     Of course  the included demos for the two mixed signal micro controllers  can only be used  on their development boards     or similar boards     WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    Hello World     Now start    Edit      our enclosed editor  Enter the following      include  lt stdio h gt     void main void     printf   Hello World n          Save this text in  SRC HELLO HELLO C   might be already there      Don t close Edit     cm  Mm  S  Now start    UmShell      This is the second part of the current IDE  UmShell is based on  an industrial approved system named    Make     For a beginner it might look a little bit strange   but Make is a very powerful tool and in the background of most other IDE   s a Make tool is  working  Think of Make as just a simple    recipe    how to build a target  In this case the make  file has only one line     Hello bin  hello c       This tells Make  that    HELLO BIN    is to be made from    HELLO C        By default UmShell knows a set of rules how to translate one extension to another  i e    C to    BIN   In 
58. xadecimal digits  0 F   For example  the string  R3  can be written as   x5233  or    x52 x33   Octals are a backslash followed by up to three octal digits  1000   For example    R3  in octal could be written  11223  or  11221063      Mixing C and Assembler  Mixing C and Assembler is very easy in uC 51  The compiler itself was designed for easy  assembler usage  Up to 8 bytes of arguments are passed in registers     What s going on     After reset  the controller will jump to  main  trough a  ljmp   The first thing in  main   is to  call  startup     This routine will initialize the global data of the program and initialize the  stack pointer  Then it will return to  main     After  main    is done   startup    will be called  again       15    WWW WICKENHAEUSER COM wC 51 V1 10 User s Manual    So if you want to call assembler functions from C  you will find the controller s infra struc   ture well prepared  You even can even use this to get assembler data initialised by  startup      as we did in some demo and library functions      Because the user might define variable of the same name as CPU registers  like  A  and  B     we decided to user a leading     in all compiler exported definitions  A call from C to a  function  test    will result as an  Icall _test   the compiler will write an assembler source code  as outout   The assembler can access all global C variables and vice versa  but don t forget  the consider the             Parameter passing in registers is very ea
59. y determine the type of memory they are pointing to  That is  why they become   generic  pointers with a size of 32 Bit  By calling the function  say_hi  uC 51 automatically  extends a given pointer to a generic one if needed     You might recognise  that there is a 8 Bit overhead in the generic pointers  Well  you re  right  but we thought  that this extra byte does not hurt more than it might be worth  With  such a 32 Bit generic pointer you can access 256 different types of memory  each with a  linear size of up to 16 MB  We think this is  almost  flat too    On some of our boards  we  already use this extra byte  i e  the FlexGate  which has  V1 0  512kB of Flash memory or the  data loggers with 2MB     The access over generic pointers is done through library functions  You may find their source  code in  LIB LIB_ASS MEM32 S51   Feel free to add your own memory space  After that  you must rebuild the libraries  as described later in this document  For our data loggers  we  have mapped almost everything in this space  the Flash with 2MB  internal RAM  even the  PC peripherals have their own  selector        Summary  All unmodified constant  top level  integral data and strings will be placed in     code     all other unmodified  top level  data will be paced in  xram   All unmodified pointers    will become  generic  ones     And what about this  as a global definition      char  pc  HELLO         This is really difficult   HELLO  is a constant string  OK  So it will be lo
    
Download Pdf Manuals
 
 
    
Related Search
    
Related Contents
EMACO® T 903 Bordure Mortier    Nom de l`Institution utilisatrice Nom du Logiciel Nom du  Mode d`emploi - Sage Schweiz AG  Kenmore Elite 22 cu.ft. Capacity Side-by-Side Refrigerator w/ Dispenser ENERGY STAR Energy Guide  Sony VGC-LT32E Safety Information  DC電源駆動 小型電動バルブアクチュエータ ER−05D、DH(90°開閉用  Rapport annuel IRSST 1997 couv  Téléchargez le mémoire en PDF - Cefedem Rhône  ECOFIRE GIULIA - KELLY - TANIA IDRO    Copyright © All rights reserved. 
   Failed to retrieve file