Saturday, March 24, 2012

Controlling the Explorer 16 On-board Truly LCD

The Explorer 16 board comes equipped with a small LCD display controlled by a Novatek NT7603 LCD Controller. There are four signals used to control the NT7603 from the PIC32 (marked MPU in the diagram):
  • RS - Register select: Selects between the Instruction and Data registers.
  • E - Enable: Asserted high to start a read/write transaction.
  • RW - Read not Write: When asserted indicates a read, de-asserted indicates a write.
  • DATA - Data Bus: An 8-bit bus containing the data to be read/written to the indicated register.
For my purposes I connected these signals to General Purpose I/O (GPIO) on the PIC32 as follows:

  RS <-> RB15
  E  <-> RD4
  RW <-> RD5
  DATA <-> RE0 - RE7   


The databook describes the protocol for a read and write operation and describes a basic initialization flow. The code linked below shows my implementation of that flow, along with a puts_lcd(char* string) helper function which can be used to write a string to the display. 

The biggest challenge with implementing this code was figuring out what controlled the LCD screen on the Explorer 16 and finding a databook for that controller. I also found this controller a little difficult to work with as it seems to be very sensitive to the timings of the various commands. If you run into trouble use a Logic Analyzer to ensure that you are meeting the minimum delays after each command type before issuing the next command. Also ensure you are meeting the minimum timings for the write and read operations. These delays and timings are all listed in the databook.

Code:
References:

Friday, December 16, 2011

Using the UART on the PIC32 Explorer 16 Board

Using the LEDs and buttons on the Explorer 16 development board gives a user the ability to interact with a program running on the PIC32, but it is a brutally limited form of interaction. To do any serious interaction one would want some kind of console environment. An easy way to create that is to use the RS232 port on the Explorer 16 board to create a communications link with the Windows host system. Unfortunately my Windows system does not have any RS232 ports (they are becoming increasingly rare on new motherboards). To get around this I am using a USB to RS232 adapter that runs some variant of the Prolific USB to RS232 chipset. I also needed a terminal emulator to run on my Windows system so I could communicate on the RS232 port. Hyperterminal, the old terminal emulator of choice, has been removed from recent version of windows, so after some web searching I found a replacement called RealTerm. This program has some powerful features for controlling an RS232 connection and I found it very easy to use. Now armed with an RS232 connection and a terminal emulator I programmed the PIC32 with a UART demo program from the C32 compiler's peripheral library demo folder. The demo is called "uart_basic" and is found in the:
<install path>\Microchip\MPLAB C32 Suite\examples\plib_examples\uart\uart_basic 
directory. The demo is supposed to present the user with a menu of commands where the user selects one by entering the number given for that command. Unfortunately, after programming the PIC32, connecting the RS232 cable, and starting the terminal emulator, nothing happened. After some debugging I tried restarting the Prolific device driver by disabling it and then enabling it in the Windows Device Manager. That solved the problem and the demo performed as expected.
Tip:
RealTerm is an excellent replacement for Hyperterminal, offering some powerful RS232 debugging tools.

Tip:
If you are having trouble using a USB to RS232 adapter, try restating its device driver by disabling and then enabling the device in the Windows Device Manager.

Friday, November 25, 2011

First Program on the Explorer 16 Board

For my first program I wanted to use the push-buttons and LEDs on the Explorer 16 development board as this would make the program easy to test. The goal is to make the lights blink when a button is pressed. Peripherals like buttons and LEDs are trivial to use on the Explorer 16 board, each are wired directly to a primary I/O pin on the PIC. The LEDs are activated by writing a logical 1 to their output pin. The buttons are active low, so a button press can be detected by seeing a logical 0 on their input pin. The code first disables the JTAG port. This is needed because one of the LEDs is wired to a pin also used for JTAG. It then configures the LED pins as outputs and the button pins as inputs. The rest of the program is an infinite loop that detects if any of the buttons are pressed, toggling the LED state if a button is pressed, and clearing the LED state if one is not pressed. The loop also contains a busy loop to cause a delay before the buttons are checked again. This delay is needed to hold the LEDs in their current state for a while so that they are clearly blinking to the human eye. Without it the LEDs would blink so fast they would just look very dimly lit.

Code:
Tip:
The Microchip peripheral library uses a lot of macro functions. The lowercase 'm' in the function name indicates that it is a really a C pre-processor macro and not a true C function. Macro calls can not have line breaks in them so the line break must be escaped with a '\' (back-slash). For example:

 mPORTAClearBits(BIT_7 | BIT_6 | BIT_5 | BIT_5 | BIT_4 | \
   BIT_3 | BIT_2 | BIT_1 | BIT_0 );