16x2 LCD Display

To have a nice output device, it is quite common to connect a simple Text-LCD with two lines and 16 characters per line. As the ChipKit project aims for high compatibility with the Arduino world, the example is quite the same as for the Arduino setup:

The code only requires the definition of the correct pins:

/*
Code based on: LiquidCrystal Library - Hello World

 Library originally added 18 Apr 2008 by David A. Mellis
library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009 by Tom Igoe
modified 22 Nov 2010 by Tom Igoe
modified for HelvePic32 30 Dec 2014 by Mathias Wilhelm
This example code is in the public domain.
*/
const uint8_t LEFT=0;
const uint8_t RIGHT=1;
uint8_t nP[2][8] = {{0,17, 9,10,11,12,13,14},{18,17, 1, 2, 3, 6, 7, 8}};

#define RS nP[RIGHT][0]
#define EN nP[RIGHT][1]
#define D4 nP[RIGHT][2]
#define D5 nP[RIGHT][3]
#define D6 nP[RIGHT][4]
#define D7 nP[RIGHT][5]

#include <Wire.h> #include <LiquidCrystal.h> LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
void setup() {
  lcd.begin(16, 2);
  lcd.print("hello, world!");
}

void loop() {
  lcd.setCursor(0, 1);
  lcd.print(millis()/1000);
}

The #defines used are only there to ease the readybility of the code.

Please note: The poti used to set the contrast via the pin V0 of the LCD has to be driven to the edge with 3.3Volt. I used a 10kOhm poti. Using a 5kOhm poti did not give me a contrast at all, the LCD stayed clear and it took me some hours to find out that the contrats voltage was not high enough. In this example, the LCD backlight is not used.