Next: , Previous: , Up: Top   [Index]


12 PIC-INTERCAL

INTERCAL-72 C-INTERCAL CLC-INTERCAL J-INTERCAL
no version 0.26+ no no

PIC-INTERCAL is a simplified version of INTERCAL designed especially for embedded systems, designed to minimise code and data usage by INTERCAL programs so that they can fit on devices whose memory is measured in bytes rather than megabytes. (It is named after the first microcontroller for which code was successfully generated, and which influenced the choices of commands, the PIC16F628 manufactured by Microchip, and is most likely to be portable to other microcontrollers in the same range.) C-INTERCAL only compiles as far as C code when producing PIC-INTERCAL; it is up to the user to find the appropriate cross-compiler to translate this C into the relevant dialect of machine code. (Two header files in the distribution, src/pick1.h and src/pick2.h, don’t have any effect on the compiler but are referenced by the generated code, and the intent is for the user to change them to suit the behaviour of the PIC compiler used, because these are not as standardised as C compilers for everyday systems.)

There are several restrictions on PIC-INTERCAL programs:

In order to provide I/O capabilities, a new command PIN is available. It controls up to 16 I/O pins on the PIC or other embedded system; an I/O pin is capable of receiving or sending voltages to an electrical or electronic circuit. This explanation assumes that the device being controlled is a PIC16F628A, and therefore has its pins in two blocks of 8 named ‘PORTA’ and ‘PORTB’; for other microcontrollers, adapting the code in src/pick1.h is likely to be necessary to tell the compiler how to control the I/O pins, and the way in which this done will affect which I/O pins it is that the program will end up being able to communicate with.

The PIN command takes one twospot variable as its argument, like this:

DO PIN :2

The twospot variable is conceptually divided into 4 blocks of 8 bits. The highest two blocks control the directions of the pins in PORTB (most significant block) and PORTA (second most significant block); a 1 on any bit means that the corresponding I/O pin should be set to send data, and a 0 means that it should be set to receive data. The lower two blocks control the values on the pins that are sending (and are ignored for receiving pins); the second least significant block controls PORTB and the least significant block controls PORTA, with a 1 causing the program to set the output voltage to that of the microcontroller’s negative voltage supply rail, and a 0 causing the program to set the output voltage to that of the microcontroller’s positive voltage supply rail. (These voltages may vary on other systems; consult your system’s datasheet and the changes you made to the header files.) After setting the pins, the PIN command then reads them as part of the same operation, this time setting the values of the lower blocks that are receiving, rather than setting the pins from the lower blocks that are sending. However, 1 and 0 bits on all bits of the twospot variable have the opposite meaning when doing this, so that 1 means receiving/positive voltage rail and 0 means sending/negative voltage rail. There is no way to input without output, or vice versa, but it’s trivial to just send the same output again (which has no effect, because the voltage on sending pins is maintained at the same level until it is changed), or to ignore the input received.


Next: , Previous: , Up: Top   [Index]