B.Lo.C Language for PIC Micro

Contents


Zip File (Programs, Documentation and Hi- Res Drawings 250k) File Formats


Fast Development On - Time

BLOC

C like language

Designed for PIC architecture

Contents


But, What is BLOC ?

BLOC allows you to write what I regard as Plain English Assembler. It is a code generator, that produces assembler from its C-like input. It allows you to write code, with the control and precision of assembler, but in the easy to understand format of a high level language. Object code is produced by the Microchip assembler, from the BLOC output.

Contents

How similar is it to C ?

BLOC ("Below C") is similar to C syntax, a C programmer will feel at home, and rapidly write and understand BLOC code. However, it is written for a processor with negligible stack, 32 bytes of variable space, and an unusual register-register instruction architecture. Whereas I developed a 68hc05 application, completely in C++ under windows, and recompiled it for the 6805. This will not work well on the PIC. The processor is simply too different from the conventional architectures, and too limited in memory resources. Efficient PIC code can only be written PIC style. BLOC facilitates this.

Contents

What about Optimisation ?

Risc architectures and optimising compilers are buzzwords of the day. Unfortunately, real optimising has two hooks. Firstly real optimising actually means, re-arranging your instruction sequence or algorithm, and chopping pieces out, to speed it up. So the code you end up with is not what you wrote, bad news for bit-bashing pins and critical timing. The other catch is more subtle. Optimisers are very complicated. They detect many unique instruction sequences, then substitute others. They are to compiler bugs like the back of a fridge is to cockroaches! Optimiser bugs are unpredictable, and can be triggered by code hundreds of lines from the problem caused. (I know)

Contents

So how efficient can it be?

BLOC allows you to generate precisely the sequence of assembler instructions you want. It contains new operators and constructs to explicitly support the effficient PIC instruction set. These include Bit Test, Bit Set, Shift, Swap Nibbles, and Inline Functions. For example the Atomic Conditional statement, is much faster and smaller that the alternative If..{} else {} construct.

(a> > =1, STATUS ? CARRY) ++i;   //shift and inc if carry set
rrf       a
btfsc     STATUS,0
incf      i,1

BLOC will not compile poor programming techniques. For example it will not compile expressions that require intermediate storage. You must explicitly code this.

To give you an idea of how efficient it is I have a DTMF generator that runs on the pic 16C54, using Direct Digital Waveform Synthesis, a software PWM output from one pin, makes no use of timers or hardware, and can run at 8MHz using about 180 instructions of code space, including all tables. It is entirely written in BLOC.

Contents

How do I learn BLOC ?

The best way is too learn BLOC and the PIC instruction set together. BLOC will work in line-by-line mode. You type a single line of code, It spits out the assembler ! This makes it easy to find out how various jobs can be done on the PIC, and how to write the most efficient BLOC programs.

a=b+c;
movf      b,0
addwf     c,0
movwf     a

takes more code than a+=b

a+=b;
movf      b,0
addwf     a,1

If you use windows, you can keep the compiler live, in interactive mode, whilst writing and compiling programs from within your editor.

Contents

But I already have code written in Assembler!

Because of its nature as an assembler generator, it is extremely easy to add BLOC code into an existing project, or to take the BLOC generated assembler, and distribute it, or incorporate it in assembler code.

Assembler can be directly, and painlessly mixed with BLOC code, even within statements.

%{ DECFSZ Cntr }% ++HiCount;

Contents

What are the limitations ?

BLOC requires a 386, 1Mb, DOS to run on. It will run under Windows. BLOC is simple. It will not give you sophisticated C features like structures, data types, preprocessing and so on. Version 5 BLOC generates assembler for PIC16C5X, 16CXX, and 17XX parts.

What Support is there ?

We get immediate support on-line from Canada for the compiler. We have had significant input into the compilers evolution ourselves already. It has a good manual, and we supply it with examples and a complete set of PIC application notes from the Microchip BBS. It is our goal to make BLOC the preferred code platform for the Microchip parts. BLOC was released quietly, without fanfare or repeated delays, and has been in use for over a year. BLOC is written by a company that uses it in signal processing applications themselves.

Your compiler, and documentation, is shipped directly through the Internet, and is always the latest available.

Contents

But Why ?

Time, Reliability, Delivery!

Costs.

The reality has been, that with small run sizes, consumer micro-controllers had big overheads. Now BLOC brings together high-volume processors and low-volume development costs

Contents

Reliability ?

BLOC is simple in concept and implementation. It has far less potential for bugs than more sophisticated compilers. With the release of Version 5, BLOC is a mature product.

BLOC is not a port of C to yet another processor, by a company with many different versions of its C compiler on different processors to support. It is conceived and written specifically for the PIC.

28 day Money Back Guarantee : Try it, Like it, or return it.

Contact Us and Try BLOC Now

Contents


Sorry, my html editor seems to have problems with symbols, so the demo code is 'Odd' and shortened. Printable PS doc's and the demoare in the zip archive

BLOC Demo:

BLOCDEMO is a severely crippled compiler, but it is helpful in understanding the PIC instruction set.

BLOC has a Total Satisfaction Guarantee. This allows you to try a full featured compiler, at no risk. If you are not totally satisfied, we will happily refund.

Both the demo and full compiler will run in Interactive mode. Just type BLOCDEMO.

Now you see how the compiler generates assembler from code.

Make some Variables. Make the status register a variable S for easy use

int8 S@3;
int8 PORTA@5;
int8 a, b, c;

Make some constants (carry and zero) for bit testing the status register

const C=0, Z=2;
const Switch5=3;

OK, lets make some code!

a=b+c;
a=a+b;
a+=b;
a|=0xE3;
a+=1;
++a; 
swap(a); clear(a);
a|=0x0F; b^=%10001000

You can evaluate expressions directly into the working register (W) and use its previous contents in expressions.

eval( > > a +b ^c);
eval(a & = 2);
a= eval()^3;

BLOC allows very efficient code using direct bit tests for set (?) and clear (?!) These are somewhat novel

if  (b+c, S?C) {++a} else {--a};
do {
  ++a;
} while (S ?! Z);

BLOC supports a special sort of if. The conditional statement can be used where a single word instruction follows the conditional. This can be very efficient. It is also symmetrical, for use in software timing loops.

Instead of

if (S?Z) {a=0};

try

(S?Z) clear(a);
const LED=2;
if (PORTA ? Switch5) {
    PORTA/=LED
  } else {
    PORTA\=LED
};

The following code will execute faster, as GOTO's take 2 cycles in the PIC

(PORTA ? Switch5) PORTA/=LED; 
(PORTA ?! Switch5) PORTA\=LED; 

Functions are really beyond the scope of this. BLOC supports functions, and your code becomes more readable.

a=I2CRead(74);

BLOC also has INLINE Functions, that read like functions, but are really macros. They allow structuring of your code, without stack or time overhead.

There is much, much more to BLOC, and it comes with a detailed 70 page manual, but this should have given you a feel for the easy to understand way to program the PIC

Contents Home


Contact Us