System Unit | Documentation

boolean byte code data dptr file function high idata lcall memory module procedure record register segment type value xdata 8051
General System unit

# System Unit

System unit implements Turbo51 runtime library and defines some special function registers (SFR), bits and interrupt addresses that are present in all microcontrollers based on 8051 core. It is implicitly used by the compiler. Usually it is loaded from the library (Turbo51.l51) which is a binary concatenation of units (currently only system unit is included).
There is also the Turbo51A.l51 library which contains the system unit compiled with the $A+ switch and has no LCALL/LJMP instructions (to use it use the /LA command line option). Warning: until the compiler will reach some more stable state some declarations in this this unit might change.

    Unit System;

    Interface

    Const

      BELL = $07;
      BS   = $08;
      TAB  = $09;
      LF   = $0A;
      CR   = $0D;
      EOF  = $1A;
      ESC  = $1B;
      DEL  = $7F;

    { Interrupt addresses valid for all 8051 microcontrollers }

      External0 = $0003;
      Timer0    = $000B;
      External1 = $0013;
      Timer1    = $001B;
      Serial    = $0023;

    Type TDeviceWriteProcedure = Procedure;

         TDeviceReadFunction = Function: Char;

         TFileRecord = Record
                         WriteProcedure: TDeviceWriteProcedure;
                         ReadFunction:   TDeviceReadFunction;
                       end;

    Var

    { Direct access to 8051 registers R0 to R7, exact address is bank dependent and will be set by the linker }

      AR0:      Byte absolute 0;
      AR1:      Byte absolute 1;
      AR2:      Byte absolute 2;
      AR3:      Byte absolute 3;
      AR4:      Byte absolute 4;
      AR5:      Byte absolute 5;
      AR6:      Byte absolute 6;
      AR7:      Byte absolute 7;

    { SFRs present in all 8051 microcontrollers }

      P0:       Byte absolute $80; Volatile;
      SP:       Byte absolute $81; Volatile;
      DPL:      Byte absolute $82;
      DPH:      Byte absolute $83;
      PCON:     Byte absolute $87; Volatile;
      TCON:     Byte absolute $88; Volatile;
      TMOD:     Byte absolute $89; Volatile;
      TL0:      Byte absolute $8A; Volatile;
      TL1:      Byte absolute $8B; Volatile;
      TH0:      Byte absolute $8C; Volatile;
      TH1:      Byte absolute $8D; Volatile;
      P1:       Byte absolute $90; Volatile;
      SCON:     Byte absolute $98; Volatile;
      SBUF:     Byte absolute $99; Volatile;
      P2:       Byte absolute $A0; Volatile;
      IE:       Byte absolute $A8; Volatile;
      P3:       Byte absolute $B0; Volatile;
      IP:       Byte absolute $B8; Volatile;
      PSW:      Byte absolute $D0; Volatile;
      ACC:      Byte absolute $E0;
      B:        Byte absolute $F0;

      DPTR:     Pointer absolute $82;

    { TCON }
      TF1:      Boolean absolute TCON.7;
      TR1:      Boolean absolute TCON.6;
      TF0:      Boolean absolute TCON.5;
      TR0:      Boolean absolute TCON.4;
      IE1:      Boolean absolute TCON.3;
      IT1:      Boolean absolute TCON.2;
      IE0:      Boolean absolute TCON.1;
      IT0:      Boolean absolute TCON.0;

    { SCON }
      SM0:      Boolean absolute SCON.7;
      SM1:      Boolean absolute SCON.6;
      SM2:      Boolean absolute SCON.5;
      REN:      Boolean absolute SCON.4;
      TB8:      Boolean absolute SCON.3;
      RB8:      Boolean absolute SCON.2;
      TI:       Boolean absolute SCON.1;
      RI:       Boolean absolute SCON.0;

    { IE }
      EA:       Boolean absolute IE.7;
      ES:       Boolean absolute IE.4;
      ET1:      Boolean absolute IE.3;
      EX1:      Boolean absolute IE.2;
      ET0:      Boolean absolute IE.1;
      EX0:      Boolean absolute IE.0;

    { P3 }
      RD:       Boolean absolute P3.7;
      WR:       Boolean absolute P3.6;
      T1:       Boolean absolute P3.5;
      T0:       Boolean absolute P3.4;
      INT1:     Boolean absolute P3.3;
      INT0:     Boolean absolute P3.2;
      TXD:      Boolean absolute P3.1;
      RXD:      Boolean absolute P3.0;

    { IP}
      PS:       Boolean absolute IP.4;
      PT1:      Boolean absolute IP.3;
      PX1:      Boolean absolute IP.2;
      PT0:      Boolean absolute IP.1;
      PX0:      Boolean absolute IP.0;

    { PSW }
      CY:       Boolean absolute PSW.7;
      AC:       Boolean absolute PSW.6;
      F0:       Boolean absolute PSW.5;
      RS1:      Boolean absolute PSW.4;
      RS0:      Boolean absolute PSW.3;
      OV:       Boolean absolute PSW.2;
      P:        Boolean absolute PSW.0;

      MemCODE:  Array [$0000..$FFFF] of Byte CODE  absolute $0000;
      MemDATA:  Array [  $00..  $FF] of Byte DATA  absolute   $00;  { Present in all 8051 microcontrollers, addresses from $80 and above access SFRs }
      MemIDATA: Array [  $00..  $FF] of Byte IDATA absolute   $00;  { IDATA memory from $80..$FF is not present in all 8051 microcontrollers }
      MemXDATA: Array [$0000..$FFFF] of Byte XDATA absolute $0000;  { Not present in all 8051 microcontrollers, usually added externally }

    Var  XDATA_StackStart: Word XDATA;  { Used for XSP and XBP initialization }
         StackStart:   Byte DATA;       { Used for SP initialization }
         R8, R9:       Byte DATA;       { Used for LongInt set 1 }
         TempRegister: Byte DATA;

       { Used for recursion stack and local variables in XDATA }

         XSP, XBP:     Pointer DATA;

       { Used for heap management }

         HeapOrg,
         HeapPtr,
         HeapEnd:      Pointer DATA;
         FreeList:     Pointer XDATA;
         HeapError:    Procedure DATA;

         RandomSeed:   LongInt DATA;    { Used for random numbers }

       { Used for file I/O }

         CurrentIO:    File DATA;
         SystemIO:     Text DATA;       { Used for Read/Readln/Write/Writeln }
         Input:        Text absolute SystemIO;
         Output:       Text absolute SystemIO;

       { Used for sysReadCharFromCurrentDevice }

         LastCharacterBuffer:      Char;
         LastCharacterBufferValid: Boolean;

       { Used for some arithmetic functions }

         Overflow: Boolean;
         ResultSign: Boolean;
         TempBool0: Boolean;
         TempBool1: Boolean;
         TempWord:  Word DATA;
         TempByte0: Byte DATA;
         TempByte1: Byte DATA;
         TempByte2: Byte DATA;
         TempByte3: Byte DATA;
         TempByte4: Byte DATA;
         TempByte5: Byte DATA;
         TempByte6: Byte DATA;
         TempByte7: Byte DATA;
         TempByte8: Byte DATA;
         TempByte9: Byte DATA;

    Var RealSigns: Byte DATA;
        RealResult: LongInt DATA;
        RealResultCarry: Byte DATA;

    Const Pi_2:     Real = Pi / 2;
          Pi_24:    Real = Pi / 24;
          _Pi:      Real = Pi;
          _2Pi:     Real = 2 * Pi;
          _2_Pi:    Real = 2 / Pi;
          _0_5:     Real = 0.5;
          _1:       Real = 1;
          Sqrt2:    Real = Sqrt (2);
          _1_Sqrt2: Real = 1 / Sqrt (2);
          Ln2:      Real = Ln (2);
          Ln2_2:    Real = Ln (2) / 2;