circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

December 2005, Issue 185

Assume Control with the MC104P


by Fred Eady


Start P Is For PC/104 Easy PIC Video MC104P Functions Be A Hero Sources and PDF

MC104P FUNCTIONS

The video driver firmware included with the MC104P makes putting alphanumeric video on a PC monitor a walk in the park on a beautiful sunny day. But I don’t want to spoil your walk. So, I’ll tell you that there are similarly simple function calls that enable you to easily access all of the PC/104 memory areas shown in Figure 1.

Let’s start at the top of the memory map graphic and work our way down. There are no MC104P utilities to read and write the PIC18F8722’s program flash memory area. However, you may manipulate the PIC18F8722’s program flash memory using its TBLRD (table read) and TBLWT (table write) assembler mnemonics.

The table read and table write mnemonics are easy to use. There are application notes and PIC18F8722 datasheet sections that explain how to use the table read and table write instructions. If you’ve ever written code for the old PIC17C4x parts, you’re already proficient with table reads and table writes.

Recall that the PC/104 I/O memory area is mapped into the MC104P memory space beginning at 0x20000. It has to be redirected programmatically to span the PC/104 I/O memory area of 0x0000–0xFFFF. Your burden of writing code to keep up with the offset calculations is lifted by the inportb and outportb functions that are part of the calmotion_MCP104P.lib library module. Reading 0x5555 is accomplished by simply executing a C statement such as input_value = inportb(0x5555). Note that the inportb function uses the actual PC/104 I/O address, not a representative offset address, to read the PC/104 I/O location.

The MC104P outputb function is called in a similar manner with the addition of the value to be written to the PC/104 I/O address. For instance, to write 0xAA to PC/104 I/O port 0x5555, you’d code outportb(0x5555,0xAA). Piece of cake.

Continuing down the memory map in Figure 1, the next memory area is the PC/104 memory area, which extends from 0x30000 to 0xFFFFF. The calmotion_MCP104P.lib inmemb and outmemb function calls directly access the PC/104 memory in this address range. Bytes can be read and written to the PC/104 memory area using the inmemb and outmemb functions, respectively. The syntax for the PC/104 memory area functions is identical to the syntax used by the PC/104 I/O functions. To read the 0x30000 address, you’d code input_value = inmemb(0x30000). Conversely, writing the 0x30000 address with 0x55 would result from coding the outmemb(0x30000,0x55) C statement.

Reading and writing the external 128 KB of SRAM attached to the PIC18F8722 is also accomplished using native PIC table read and table write assembler instructions. This chunk of SRAM lies outside the defined PC/104 memory space and belongs to the PIC exclusively. The PIC18F8722 datasheet contains a detailed external SRAM read and write how-to guide.

There’s one more MC104P library I want to talk about. The calmotion_utility.lib library supports a PC application called the MC104P Utility, which can run on a Windows or Palm OS platform. The application provides a low-speed snapshot of the MC104P’s PIC registers and a small portion of the beginning of the 128-KB block of external SRAM.

The MC104P Utility communicates with the MC104P serially via the MC104P’s COMM2 serial port. Various PIC registers and I/O ports are exposed on the MC104P Utility display. The experience is akin to looking at the standard Microchip debug displays with the difference being that the MC104P register and I/O port values are being updated periodically. Any of the PIC18F8722’s available registers and I/O ports that can be accessed via the MC104P Utility’s PC display can be updated from the MC104P Utility display.

For instance, the MC104P user LEDs are attached to bits 3 and 4 of the PIC18F8722’s port G. I was able to toggle the MC104P’s user LEDs by updating the values of the PIC18F8722’s TRISG and LATG registers from the MC104P Utility PC display. The MC104P Utility also contains a low-speed oscilloscope application that can be tapped into the PIC18F8722’s timers and I/O ports on the fly from the MC104P Utility screen.

There are only three functions in the calmotion_utility.lib library. Listing 2 shows the minimal set of code needed to transfer data between the MC104P and the MC104P Utility. The init_utility function initializes the MC104P’s COMM2 serial port for use by the MC104P Utility. The actual data handling is performed by the data_xfer function, which is placed within interrupt handler code. Here the PIC18F877’s EUSART2 receive interrupt flag is checked. If the receive buffer is full, the data_xfer function is called. Housekeeping and error-recovery chores are performed periodically by the MC104P_utility function. Ideally, the MC104P_utility function should be called every 2 ms or sooner.