Mod51 Structured Text Programming Language

Mandeno Granville Electronics are dedicated to providing 'best in class' tools for 80x51 controller development. As well as Hardware In Circuit Emulation, we provide high level languages tools. A Choice of Assembler, C, Pascal, or Modula-2/IEC1131.
IEC1131 is the PLC industry standard, and the ST (Structured Text) arm of this is very closely related to Modula-2. Modula-2 is also related to Borland's Pascal/Delphi, so there is a strong showing of similar languages, for a very wide application area.
The Programmable Logic Controller (PLC) market has dumped C as the user language, and chosen IEC-1131, for good reasons. Even the C++ market for PC's has largely moved to the more maintainable Delphi, and Visual Basic tools. The latest FLASH C51 variants, allow a complete PLC on a Chip!

IEC-1131 is optimised for Embedded Control, and easy Project control and Maintainance
- it does not take the bloated 'creeping featurism' direction of C++ or Java.

Users want a Language that is more efficent, re-usable, easily maintainable, easy to read, and easy to write code in.

Want to see some example / Benchmarks


Microcontroller projects have much more in common with PLC's than with an Internet browser running under Windows 2000 - choosing a language DESIGNED for control projects is simple common sense.

Mod51 is a combination of the structured text language of IEC1131, and ISO Modula-2, optimised for the worlds most popular 8 Bit controller - the Intel C51 core.

Mod51 is ideal for both Industry and Teaching, and includes simple teaching tutorials, for those new to embedded controllers.
We offer Complete Solutions - with Compiler, Debugger, Programmer, and ICE tools. Email your requirements to us today.



Feature Description
More Efficent Smallest Pgm is 9 Bytes
Smaller Works on 1K to > 64K Code Memory
Re-Usable Safe, and Structured makes re-use easy
Easily Maintained Separate Modules mean safer changes
Easy to Read Very clean, english syntax
Easy to Write Examples, and Source Simulator/Debuggers
Popular Targets the world's most popular Code - the C51
Portable Over 120 80x51 variants are available from > 20 Suppliers!




Rapid Applications Development for C51's

The 'best fit' High Level language for the Intel std 80x51 uC core is Mod51.

Modula-2 / IEC1131 is the new REAL WORLD programming standard, more productive and easier to maintain than C, and far in advance of Assembler.

Mod51 is optimised to fully utilise the BOOLEAN processor features of the C51 core.

Mod51 can be linked with intel std OBJ files, allowing legacy code in ASM, or C to be included within a project

Dual language packages of ANSI C51 and Modula-2 also available, for those with code inertia

  • Significantly more productive than Assembler or C
  • Extensive support for ALL '51 architecture variants
  • Full use of the C51 BOOLEAN engine, including DeMorgan optimise
  • Tight code, often smaller than legacy assembler
  • Smallest PGM is 9 bytes, KbdScan in 59 Bytes, i2c in 107 bytes
  • All 2051 libraries are written in Mod51, Source included
  • Extensive libraries, expecially on 89C2051 and common IO
  • PL/M 51, Pascal, C translator/converters now available
  • Clean, readable syntax, safe and programmer portable

Mod51 / IEC1131 Simple Structure examples

                                                                             

 Unlike C, Modula-2 has a NATIVE  BOOLEAN type. This fits well on
the boolean processor in the C51, and makes Embedded Control Programs easier
to code.
 Named BIT variables are much easier to use than cryptic mask values.

 PWMpin := (PWMCtr > CompareValue);

 The ELSIF and required END, make multi choice statements very clear,
and safe to edit. 

 IF BoolExp THEN
  ..
 ELSIF BoolExp2 THEN
  ..
 ELSE
  ..
 END

 REPEAT
  ..
 UNTIL BoolExp;

 WHILE BoolExp DO
  ..
 END;

 FOR Counter := 0 TO SIZE(Array)-1 BY 2 DO
  INC(Array[Counter]);
 END;

 LOOP
  ..
  IF ExitCond THEN EXIT END;
  ..
  IF ExitCondB THEN EXIT END;
 END

 CASE CaseVar OF
 | Value : DoThis;
 | Low..Upper : Range;
 ELSE
  OtherValues;
 END;

 The BITSET type, allows collections of BITs within a Byte 

 IE := {EA,ES,ET0};

 IF 3 IN BitSetV THEN
   INCL(BitSetV,7);
 ELSE
   EXCL(BitSetV,7);
 END;

 BITSETs also allow Arrays of BIT at high level, not ASM.

 INCL (RxAry[BitPtr DIV 8],BitPtr);   (* SET BitNo  (BitPtr MOD 8), array *)

 Function Procedures RETURN a type, in CY, ACC etc so are C, ASM linkable 

 PROCEDURE IsLessThan(Lh : SHORTCARD REGISTER_2,
                      Rh : SHORTCARD REGISTER_3; ) : BOOLEAN;
 BEGIN
   RETURN  (Lh < Rh );
 END IsLessThan;



 VAR
  Overlay : BYTE AT P3
  BitOvl  : BOOLEAN AT P3.2;
  Reg2 : SHORTCARD REGISTER_2;

 CONST
  StringH = '0123456789ABCDEF';
  BinC = 2#1101_0110;  (* IEC1131 allows clear bit allocates, '_' is skipped *)
  HexC = 0FFEFH;
  NumC = 31300;
  FloatC = 3.14159278;

 IE := {EA,ET0,ES};

  

Mod51 / IEC1131 Keywords

                                                                             
Structure Keywords  
 DEFINITION,IMPLEMENTATION,MODULE
 FROM,IMPORT
 EXPORT,
 PROCEDURE,
 TYPE,VAR,CONST
 FALSE,TRUE,Mod51,NIL,

Types 

 BOOLEAN, CHAR,SET,
 SHORTCARD,BYTE,BYTE_BA,BITSET,
 INTEGER,CARDINAL,WORD,
 LONGCARD,LONGWORD,LONGINT,
 REAL,
 MAXINT,

 ARRAY,OF
 RECORD,WITH
 CODE,CMEM,CMEMW,XMEMW,XMEM,
 PROCESS,NEWPROCESS,TRANSFER,
 POINTER,ADDRESS,PROC,EXEC

Function Operators  

 LENGTH,SIZE,ADR,MAX,MIN,INT,
 TRUNC,FLOAT,ORD,VAL,ROUND,
 ODD,CHR,
 INC,DEC,ABS,
 INCL,EXCL,IN
 CAP,SHIFT,ROTATE,SHR,SHL

Operators 

 AND,OR,XOR,NOT
 MOD,DIV

Program Flow 

 IF,THEN,ELSE,ELSIF
 FOR,TO,BY
 BEGIN,END
 RETURN
 LOOP,EXIT,
 CASE
 WHILE,DO
 REPEAT,UNTIL


The C51 + Modula-2 BOOLEAN edge

                                                                             
This is the Mod51 approach, on a C51

CONST  On = TRUE; Off = FALSE;
VAR    DivValveForward : BOOLEAN AT P1.6;
..
DivValveForward := On;   (* 2 Bytes, 1 Cycle *) 
DivValveForward := Off;  (* 2 Bytes, 1 Cycle *)

and even

DivValveForward := (Pressure < MinP);

Very simple, and efficent.
Contrast with below, an example from the web, of typical ANSI C code,
on another controller :

// Macros for setting/clring IO bits
// a=[sfr name] ,b[bit number]

#define set_sfrbit(a,b) ( (a) |= (1<<(b)))
#define clr_sfrbit(a,b) ( (a) &= (~(1<<(b))) )
#define test_sfrbit(a,b) ( (a) & (1<<(b)) )

#define DIVVALVE_PORT       PORTB
#define DIVVALVE_FOR        6       // Port B.6

void DivValveOnForward(void)
{
    set_sfrbit(DIVVALVE_PORT, DIVVALVE_FOR);
}
//  This generates an sbi or cbi instruction.

     DivValveOnForward;


 Complicated enough to express, but it gets worse..
This C code is a function call, uses 1 stack level.
For an on/off pair, it costs 8 bytes + 2 or 4 per usage, and
takes 3+2+4 = 9 (!) cycles per operation.

Some Example Mod51 Object Libraries

Source to all these is included.
This list is expanding all the time, so check for latest libraries. Suggestions for new libraries are welcome.

MODULE MultiI2C;
Sw i2c Control, with support for multi i2c bus ( up to 8 separate i2c BUS lines supported ) allowing greatly expanded IO capability. Size : 145/ 107 bytes CODE, and 1 bit of RAM resource.
MODULE KeyPad;
Sw KeyPAD scanning, with KEY decoding. Designed for 89C1051, and up, for small keypads This example has a 4 x 5 ( 20 keys) matrix keyboard wired to HiNibble p1, and Low Nibble P3. Overhead is just 59 bytes CODE and 1 Byte + Bit DATA
MODULE Ser_Kbd;
This is a simple KBD interface, based on 4094 and 4021 shift registers. Size : 62 Bytes
MODULE MIRROR;
Used : Anywhere you want to FLIP the BIT order, typically, for SPI interfaces on the '51 UART
MODULE Analog;
Sw A to D designed for 80x51 variants with ANALOG Comparitor systems. This is a very simple, A/D solution. Uses as External MUX, and Sample / Hold, a 4051 / 4351 8:1 MUX. One channel is used for HOLD (if fast Analogs) leaving up to 7 MUX'd inputs.
MODULE InitLCD;
Emul517C LCD display Init, as 4 bit mode, example, Sets up a LCD Display in 4 Bit mode, allowing a SINGLE PORT to interface to STD LCD modules.
MODULE SPI_WR;
Sw SPI bus, for WRITE only CHIPS. THis one is 15 Bits, then LE.
MODULE SPI_51;
80x51 Serial Port SPI mode0 operation. Code below will require editing, depending on your SPI hardware, this example works with the MGE SPI_51 PAL.
MODULE HEF4x94;
Sw For WRITE to Philips 4094, 4794, 4894 parts - very useful for Port Expansion for 89C1051 / 89C2051 - 4794 is a 20mA open drain pin clone of 4094, 4894 is a 20mA open drain 20 Pin, 12 Output 4094 Pin resource required is 3 pins, with option to save the LE pin, if shift refresh rates can be kept low. Code Size 17 Bytes for 8 bit, 35 Bytes for 12 bit.
MODULE MotorPWM;
Purpose :- Using the low cost 89C2051 as PWM motor drive chip, allowing distributed power control of high power motors. The small, low cost 89C2051 is then used one per motor as a slave driver. Using a 24MHz clock, 89C2051 can resolve 0.5uS, on timers. * 16KHz PWM frequency
MODULE Delta;
Sw DELTA Modulation for high precision A/D - in region of 12..16 Bits. Uses charge balancing technique, which requires an external Integrator ( OPAMP + Cap )
MODULE FastComm;
Template module for 89C2051 UART Mode, using 9th BIT as Address marker.
MODULE Quad2051;
Purpose :- Comparing the low cost 89C2051 as Quad ctr, with PLD designs. A ATV750 can support 15 bit QUADCTR operation, at high frequencies. The uC can perform more maths, but has problems at very high count rates ( > 50KHz ).
MODULE SW232;
Sw UART RS232 Rx, in MODULA 2, > 9600K BAUD Overhead is only 59 BYTES !! Suggested for 89C1051,80CL410, or Second UART
MODULE SAA1064;
i2c and Segment drive tables for Philips i2c BUS LED driver. Has RS232 simple terminal support, and can drive 32 SAA1064's. Under 1K total program.
MODULE PCF8577;
i2c and Segment drive tables for Philips i2c BUS LCD driver.

To Order,Contact: Sales

E-Mail: [remove reverse spam] MODinfo_2006@DesignTools.maps.co.nz

HomePage: MGE DesignTools Page

FAX: +64 9 6301 720

Modula-2 webring logo Modula-2 Webring
[ List all | Random | << Prev | Next >> | Join | ]