Modula-2 : I2C test program

In the end of the 90's I created a debugger for I2C circuits. It was a success among the hardware engineers of this special field. Yes, all 12 of them (measured wrldwide) like the program. I should have extended the program to also accomodate CAN, SPI and USB but I didn't. Friends told me it was useless.

The original program was written in assembler. Consult the 80x86 assembler section elsewhere on this site. Here is the source for IIC01:

MODULE IIC01;

(*   version 0.1 : create user interface                                     completed :        *)

FROM    VgaLib3         IMPORT  COLOUR, WinData, SetVGA, SetColour, SetMask, Plot, DrawH, DrawV, PlotChar,
                                PlotText, MakeBox, Center, EraseBox, FillBox, WriteNumber;
FROM    LowLevel        IMPORT  InPort, OutPort;
FROM    Mouse           IMPORT  MouseRecord, InitMouse, ShowMouse, HideMouse, GetMouseStatus, SetMouseCursor,
                                ConfineMouse;
FROM    Xchar           IMPORT  KeyW8;


TYPE    LogicState      = (Low, High);


VAR     MainScreen, SdaWin, SclWin, BitWin, IntWin, StatWin,
        BotLin, PortWin, TraceWin, MouseWin, TopWin                 : WinData;

        mouse                                                       : MouseRecord;

        IOport, OldMode                                             : CARDINAL;


PROCEDURE   InitWins;                   (*  Initialize window-parameters.       *)

BEGIN
(*  MainScreen is a dummy for the all around framework.     *)

    MainScreen.TopX   :=   0;       MainScreen.TopY   :=  20;
    MainScreen.Width  := 640;       MainScreen.Height := 437;
    MainScreen.CurX   :=   0;       MainScreen.CurY   :=   0;
    MainScreen.DeltaX :=   0;       MainScreen.DeltaY :=   0;
    MainScreen.Indent :=   5;
    MainScreen.TexCol := GREEN;     MainScreen.BoxCol := YELLOW;
    MainScreen.BckCol := black;     MainScreen.MnuCol :=    red;

(*  TopWin describes the upper status bar for action keys.  *)

    TopWin.TopX     :=   0;         TopWin.TopY     :=   0;
    TopWin.Width    := 640;         TopWin.Height   :=  20;
    TopWin.CurX     :=   0;         TopWin.CurY     :=   0;
    TopWin.DeltaX   :=   0;         TopWin.DeltaY   :=   0;
    TopWin.Indent   :=   4;
    TopWin.TexCol   := RED;         TopWin.BoxCol   := green;
    TopWin.BckCol   := pink;        TopWin.MnuCol   :=   RED;

(*  SdaWin describes the state of the SDA line              *)

    SdaWin.TopX     :=   5;         SdaWin.TopY     := 425;
    SdaWin.Width    :=  80;         SdaWin.Height   :=  25;
    SdaWin.CurX     :=   0;         SdaWin.CurY     :=   0;
    SdaWin.DeltaX   :=   0;         SdaWin.DeltaY   :=   0;
    SdaWin.Indent   :=   4;
    SdaWin.TexCol   := WHITE;       SdaWin.BoxCol   := green;
    SdaWin.BckCol   := black;       SdaWin.MnuCol   :=   RED;

(*  SclWin describes the state of the SCL line              *)

    SclWin.TopX    :=  90;          SclWin.TopY    := 425;
    SclWin.Width   :=  80;          SclWin.Height  :=  25;
    SclWin.CurX    :=   0;          SclWin.CurY    :=   0;
    SclWin.DeltaX  :=   0;          SclWin.DeltaY  :=   0;
    SclWin.Indent  :=   4;
    SclWin.TexCol  :=  WHITE;       SclWin.BoxCol  :=  green;
    SclWin.BckCol  :=  black;       SclWin.MnuCol  := YELLOW;

(*  BitWin describes the state of the last valid BIT        *)

    BitWin.TopX    := 175;          BitWin.TopY    := 425;
    BitWin.Width   :=  80;          BitWin.Height  :=  25;
    BitWin.CurX    :=   0;          BitWin.CurY    :=   0;
    BitWin.DeltaX  :=   0;          BitWin.DeltaY  :=   0;
    BitWin.Indent  :=   4;
    BitWin.TexCol  :=  WHITE;       BitWin.BoxCol  :=  green;
    BitWin.BckCol  :=  black;       BitWin.MnuCol  := YELLOW;

(*  IntWin describes the state of the INT line              *)

    IntWin.TopX    := 260;          IntWin.TopY    := 425;
    IntWin.Width   :=  80;          IntWin.Height  :=  25;
    IntWin.CurX    :=   0;          IntWin.CurY    :=   0;
    IntWin.DeltaX  :=   0;          IntWin.DeltaY  :=   0;
    IntWin.Indent  :=   4;
    IntWin.TexCol  :=  WHITE;       IntWin.BoxCol  :=  green;
    IntWin.BckCol  :=  black;       IntWin.MnuCol  := YELLOW;

(*  StatWin describes the window for I2C status information *)

    StatWin.TopX    := 345;         StatWin.TopY    := 425;
    StatWin.Width   := 200;         StatWin.Height  :=  25;
    StatWin.CurX    :=   0;         StatWin.CurY    :=   0;
    StatWin.DeltaX  :=   0;         StatWin.DeltaY  :=   0;
    StatWin.Indent  :=   4;
    StatWin.TexCol  := YELLOW;      StatWin.BoxCol  := cyan;
    StatWin.BckCol  :=  black;      StatWin.MnuCol  :=  red;

(*  PortWin describes the actual LPT port number            *)

    PortWin.TopX    := 555;         PortWin.TopY    := 425;
    PortWin.Width   :=  80;         PortWin.Height  :=  25;
    PortWin.CurX    :=   0;         PortWin.CurY    :=   0;
    PortWin.DeltaX  :=   0;         PortWin.DeltaY  :=   0;
    PortWin.Indent  :=   4;
    PortWin.TexCol  :=  WHITE;      PortWin.BoxCol  :=  green;
    PortWin.BckCol  :=  black;      PortWin.MnuCol  := YELLOW;

(*  TraceWin describes the I2C active trace window          *)

    TraceWin.TopX    :=   5;        TraceWin.TopY    := 160;
    TraceWin.Width   := 630;        TraceWin.Height  := 200;
    TraceWin.CurX    :=   0;        TraceWin.CurY    :=   0;
    TraceWin.DeltaX  :=   0;        TraceWin.DeltaY  :=   0;
    TraceWin.Indent  :=   4;
    TraceWin.TexCol  :=  WHITE;     TraceWin.BoxCol  :=  green;
    TraceWin.BckCol  :=  black;     TraceWin.MnuCol  := YELLOW;

(*  BotLin describes the Copyright notice.                  *)

    BotLin.TopX     :=   5;         BotLin.TopY     := 460;
    BotLin.Width    := 620;         BotLin.Height   :=  20;
    BotLin.CurX     :=   0;         BotLin.CurY     :=   0;
    BotLin.DeltaX   :=   0;         BotLin.DeltaY   :=   0;
    BotLin.Indent   :=   4;
    BotLin.TexCol   := brown;       BotLin.BoxCol   := green;
    BotLin.BckCol   := black;       BotLin.MnuCol   := green;

END InitWins;


PROCEDURE   PlotSymbol ();

BEGIN
    MainScreen.CurX := 10;
    MainScreen.CurY := 10;      PlotChar (MainScreen, CHR (179));
    DEC (MainScreen.CurX);      PlotChar (MainScreen, CHR (180));
    DEC (MainScreen.CurX);      PlotChar (MainScreen, CHR (181));
    DEC (MainScreen.CurX);      PlotChar (MainScreen, CHR (182));

    MainScreen.CurX := 10;
    MainScreen.CurY := 26;      PlotChar (MainScreen, CHR (183));
    DEC (MainScreen.CurX);      PlotChar (MainScreen, CHR (184));
    DEC (MainScreen.CurX);      PlotChar (MainScreen, CHR (185));
    DEC (MainScreen.CurX);      PlotChar (MainScreen, CHR (186));       (*  Plot I2C symbol *)

    MainScreen.CurX := 10;
    MainScreen.CurY := 50;      PlotChar (MainScreen, CHR (188));
(*                                PlotText (MainScreen, 'Device    Description     Size    Page    Delay');     *)
    MainScreen.CurX := 10;
    MainScreen.CurY := 67;      PlotChar (MainScreen, CHR (187));
    MainScreen.CurX := 10;
    MainScreen.CurY := 84;      PlotChar (MainScreen, CHR (189));       (*  Plot scrollmarkers  *)

END PlotSymbol;


PROCEDURE   FillBoxes ();

BEGIN
    SdaWin.CurX := 5;
    SdaWin.CurY := 5;           PlotText (SdaWin, 'SDA =');
    SclWin.CurX := 5;
    SclWin.CurY := 5;           PlotText (SclWin, 'SCL =');
    BitWin.CurX := 5;
    BitWin.CurY := 5;           PlotText (BitWin, 'BIT =');
    IntWin.CurX := 5;
    IntWin.CurY := 5;           PlotText (IntWin, 'INT =');
    PortWin.CurX := 5;
    PortWin.CurY := 5;          PlotText (PortWin, 'LPT =');
    StatWin.CurX := 5;
    StatWin.CurY := 5;          PlotText (StatWin, 'Bus is IDLE');
END FillBoxes;


PROCEDURE   InitScreen () : CARDINAL;     (*  Set up userinterface                *)

VAR     mode            : CARDINAL;

BEGIN
    mode := SetVGA (12H);
    InitMouse (mouse);
    InitWins;
        MakeBox (MainScreen);
        MakeBox (SdaWin);
        MakeBox (SclWin);
        MakeBox (BitWin);
        MakeBox (IntWin);
        MakeBox (StatWin);
        MakeBox (PortWin);
        MakeBox (TraceWin);
        Center (TopWin, 'I2C_control: Select Manual Port Read Write ESC_=_Exit');
        Center (BotLin, 'Copyright_2002: Jan_Verhoeven jan@verhoeven272.fol.nl');
        PlotSymbol;
        FillBoxes;
    SetMouseCursor (60, 60);
    ShowMouse ();
    RETURN mode
END InitScreen;


PROCEDURE   FindInterface () : CARDINAL;    (*  Find LPT port which has I2C hardware    *)

BEGIN
    RETURN 0
END FindInterface;


BEGIN
    OldMode := InitScreen ();
    IOport  := FindInterface ();

    KeyW8 (15C);

    OldMode := SetVGA (OldMode)
END IIC01.
   
The program heavily relies on VGAlib3 and its proprietary character set.

Page created September 15, 2012 and