The StatiC Compiler & Language

by Pete Gray



Example 1:

(a)



procedure procedurename ( [parameter_list] )

begin

  [local variable declarations]

  statements

end





(b)



program

begin

  [local variable declarations]

  statements

end







Listing One



// port A definitions for GPIO (LEDs)

#define PAPUR   $0FB0

#define PADR    $0FB1

#define PADDR   $0FB2

#define PAPER   $0FB3

#define PAIAR   $0FB4

#define PAIENR  $0FB5

#define PAIPOLR $0FB6

#define PAIPR   $0FB7

#define PAIESR  $0FB8



// SCI0 definitions for terminal (RS232) interface

#define SCI0BR  $0F00

#define SCI0CR  $0F01

#define SCI0SR  $0F02

#define SCI0DR  $0F03



// constants - the welcome message

const msg1 "LEDs on/off 1/2=Green 3/4=Yellow 5/6=Red."

const msge 13,10,0



// output a null-terminated string to SCI0

procedure sci0output (optr)

begin

  word ostat 1



  while ^optr

    ostat = ^SCI0SR

    while ( ostat & $C000 ) <> $C000

      ostat = ^SCI0SR

    endwhile

    ^SCI0DR = ^optr

    optr = optr + 1

  endwhile

end



// read a character from SCI0

procedure sci0input (rchar)

begin

  word ostat 1



  ostat = ^SCI0SR

  while ( ostat & $3000 ) <> $3000

    ostat = ^SCI0SR

  endwhile

  ^rchar = ^SCI0DR

end



// the main program

program

begin

  word ichar 1



  ^SCI0BR = 260              // baud 9600

  ^SCI0CR = 12               // 8N1

  ^PAIAR = 0                 // enable LEDs

  ^PAIENR = 0

  ^PAIPOLR = 0

  ^PAIESR = 0

  ^PAPER = $00F8

  ^PADDR = $0007

  ^PAPUR = $00FF

  call sci0output (@msg1)    // display message

  ^PADR = 0                  // LEDs off

  while 1                    // loop forever

    call sci0input (@ichar)

    if ( ichar = '1' ) ^PADR = ^PADR | $0004 endif

    if ( ichar = '2' ) ^PADR = ^PADR & $00FB endif

    if ( ichar = '3' ) ^PADR = ^PADR | $0002 endif

    if ( ichar = '4' ) ^PADR = ^PADR & $00FD endif

    if ( ichar = '5' ) ^PADR = ^PADR | $0001 endif

    if ( ichar = '6' ) ^PADR = ^PADR & $00FE endif

  endwhile



end



Listing Two



// definitions for SCI (RS232)

#define SCI0BR  $0F00

#define SCI0CR  $0F01

#define SCI0SR  $0F02

#define SCI0DR  $0F03



// global variables

word appstate 1

word appchar 1



// application control definitions

#define APPSTATEINPUT 1

#define APPSTATEOUTPUT 2



// constants

const msg1 "StatiC FSM SCI Demo Ready."

const msg2 13,10,0



// the application states

statelist waitappinput waitinput waitappoutput doappoutput



// the transitions

transition waitappinput

begin

  condition appstate = APPSTATEINPUT

  causes

    nextstate = waitinput

  endcondition

end



transition waitinput

begin

  condition ( ^SCI0SR & $3000 ) = $3000

  causes

    appchar = ^SCI0DR

    appstate = APPSTATEOUTPUT

    nextstate = waitappinput

  endcondition

end



transition waitappoutput

begin

  condition appstate = APPSTATEOUTPUT

  causes

    nextstate = doappoutput

  endcondition

end



transition doappoutput

begin

  condition ( ^SCI0SR & $C000 ) = $C000

  causes

    ^SCI0DR = appchar

    appstate = APPSTATEINPUT

    nextstate = waitappoutput

  endcondition

end



// define the machines

machine inputmachine 10 waitappinput

machine outputmachine 10 waitappoutput



// a procedure used at start-up, to display welcome message

procedure sci0output (optr)

begin

  word ostat 1



  while ^optr

    ostat = ^SCI0SR

    while ( ostat & $C000 ) <> $C000

      ostat = ^SCI0SR

    endwhile

    ^SCI0DR = ^optr

    optr = optr + 1

  endwhile

end



// the main program

program

begin

  ^SCI0BR = 260                // baud rate 9600

  ^SCI0CR = 12                 // 8N1

  call sci0output (@msg1)      // display welcome message

  appstate = APPSTATEINPUT     // the initial app state

end



// at this point, all of the defined machines are 'running'













4



