Accessing the VEX Microcontroller I/O Ports
Now that we know that the standard VEX
microcontroller uses two PIC18F8520 microcontrollers, the
question is which of the external controller I/O pins
correspond to the internal PIC18F8520 pins. To answer this
question, refer to Table 3. IFI uses different names (aliases)
for the ports than those specified in the PIC18F8520
datasheet. This can be a source of confusion since the
PIC18F8520 port registers PORTA through PORTH are
mapped to the VEX 16 digital and analog I/O, eight PWM
ports, and five interrupts. Table 3 is the Rosetta stone for
being able to carry out advanced VEX microcontroller
experiments by allowing you to use the internal PIC
peripherals and registers directly in your application.
Another resource available from Microchip is their
application notes specific to the PIC18F8520. These notes
provide details on using the PIC timers, PWM, and PIC
peripherals including the USART, I2C, SPI, and interrupts.
You may also want to learn the PIC assembly language
which gives you access to almost all the registers and
peripherals, and also allows you to write very fast code
needed for Interrupt Service Routines (ISRs). Assembly
language routines can also be called from C (mixed mode
programming).
IFI aliases for the direction register are defined as
follows:
• Pin directions IO1 to IO16.
• Inputs as rc_dig_in01 to rc_dig_in16.
• Outputs as rc_dig_out01 to rc_dig_out16.
The code to turn the LEDs on or off is leds.c which is
available in the downloads for this article at
www.servomagazine.com. It was developed using
MPLAB and the PIC18 C compiler. It configures the VEX
controller’s digital ports to outputs and sets each LED
segment to the desired state. In the code, you see an
infinite while loop and an inner loop that toggles the LEDs
in binary from 0 to 255. Once compiled, the leds.hex file is
generated that is used to program the VEX controller. The
leds.hex file is provided as well so that it can be used
without having to compile it.
You’ll need programming cable to download the
necessary firmware.
Programming the VEX Controller
To program the microcontroller for semi-autonomous or
fully autonomous operation, there are a few programming
tool options which include Easy C 2.0, Easy C Professional,
ROBOT C, and PIC18 C with MPLAB. The firmware code
generated by these compilers can be downloaded using the
IFI bootloader or the loader application that comes with
each product. Firmware files have the extension
filename.hex; they are not easy to read since they are in
hexadecimal format.
VEX PIC18F8520
PIN
DIRECTION
INPUT
OUTPUT
1
TRISAbits.TRISA0 PORTAbits.RA0 LATAbits.LATA0
2
TRISAbits.TRISA1 PORTAbits.RA1 LATAbits.LATA1
3
TRISAbits.TRISA2 PORTAbits.RA2 LATAbits.LATA2
4
TRISAbits.TRISA3 PORTAbits.RA3 LATAbits.LATA3
5
TRISAbits.TRISA5 PORTAbits.RA5 LATAbits.LATA5
6
TRISFbits.TRISF0 PORTFbits.RF0
LATFbits.LATF0
7
TRISFbits.TRISF1 PORTFbits.RF1
LATFbits.LATF1
8
TRISFbits.TRISF2 PORTFbits.RF2
LATFbits.LATF2
9
TRISFbits.TRISF3 PORTFbits.RF3
LATFbits.LATF3
10
TRISFbits.TRISF4 PORTFbits.RF4
LATFbits.LATF4
11
TRISFbits.TRISF5 PORTFbits.RF5
LATFbits.LATF5
12
TRISFbits.TRISF6 PORTFbits.RF5
LATFbits.LATF6
13 TRISHbits.TRISH4 PORTHbits.RH4
LATHbits.LATH4
14 TRISHbits.TRISH5 PORTHbits.RH5 LATHbits.LATH5
15 TRISHbits.TRISH6 PORTHbits.RH6
LATHbits.LATH6
16 TRISHbits.TRISH7 PORTHbits.RH7
LATHbits.LATH7
TABLE 2. This table is the Rosetta stone for being able to
carry out advanced VEX microcontroller experiments since it
shows the mapping of the PIC18F8520 ports to the
controller’s digital input/output pins located on the block
on top of the VEX controller. The firmware defines aliases
for each of the PIC18F4520 port registers in the
ifi_aliases.h file.
The next step is to download the provided led.hex
application into the controller and run it. Start by copying it
to your laptop or PC hard disk and place it in a folder.
Once the led.hex file has been downloaded to the VEX;
the LEDs should start flashing in a pattern.
That’s a Wrap
This experiment — while relatively simple — can be used
in VEX-based projects and provide status indicators using
discrete LEDs, display voltage levels and motor speed using
the LED BAR, and even display eight to 10-bit numeric
quantities in binary. I hope you’ve gained insight in how the
VEX digital and analog outputs are mapped.
See you “vex” time. SV
SERVO 03.2010 53