Position: Index > Unclassified >

Adapting graphical LCD with touch screen to ChipKIT UNO32

2017-12-21 10:36  
Declaration:We aim to transmit more information by carrying articles . We will delete it soon, if we are involved in the problems of article content ,copyright or other problems.

ChipKIT is a great substitution board to Arduino. It offers better performance as it is based on PIC32MX320F128 microcontroller based on 32-bit architecture. Microcontroller has 128K of Flash and 16K of SRAM on board. Having Arduino Uno shape factor ChipKIT offers more 42 programmable pins.


ChipKIT like Arduino can be programmed with bootloader that communicates to PC through USB-to-USART converter chip FT232RQ. Digilent has developed an STK500v2 based bootloader that works on PIC so it is easy to program using AVRDUDE tool. Besides that they adapted an Arduino envoronemt to work with ChipKIT boards. It's called Mpide. It also support Arduino boards but it aim is to program ChipKIT boards. Progamming experience is pretty same as for Arduino and even most of examples written for Arduino works on ChipKIT. This is true since there is no specific hardware elements touched like program memory or EEPROM. As you know Arduino is rich in hardware support libraries as all shields are designed for arduino. Late comers like ChipKIT even if they are hardware compatible may have some difficulties with library integration due to different architecture.

But with little bit effort you can make everything work.

Today I am going to try to run ITDB02 LCD module shield from iteadstudio.com.

ITDB02 Arduino Shield

IT is basically an adapter for graphical color LCD with touchscreen/SD. Note! Touch screen and SC cannot work simultaneously due to shortage of pins. Anyway a little hack on ChipKIT would solve this problem. Lets see what is a starting point.Henning Karlsenhas nice written libraries for Arduino and even for ChipKIT. But this library won't work with ITDB02 shield as decided not to support this shield due to performance loss. Also he claims that this shield is not optimized for 3.3V power supply as there are resistors included. Instead he offers to make custom cable for interfacing LCD or use another shield for ChipKIT. I understand that move. If we look at ChipKIT pin layout we can clearly see that Arduino compatible pins aren't bit aligned as it is in Arduino:

chipKIT Uno32 Pin Mapping

In Arduino digital pins D7..D0 are all PORTD pins. So they can controlled with PORTD command that gives significant increase of performance comparing to individual digitalwrite() commands. ChipKIT as you can see have these pins scattered and cannot be controlled with port commands. Instead you can see inner pins of header being aligned [RE0..RE7]. This is why another shield is offered that allow controlling LCD data pins with single command. Anyway I already have my ITDB02 shield on my table and want to make it work on ChipKIT. As starting point I've chosen to muck around with Arduino library due to same pin connectivity.

The main problem with controlling LCD that we cannot use port commands here as port pins aren't aligned. To solve this I have written simple function that takes data byte and scatters them to d0..d7 pins according to layout:

void ITDB02::byteD0D7(unsigned char data)
  //ChipKIT pins DR9|RD2|RD1|RF1|RD0|RD8|RF3|RF2
  if((data)&(0b10000000)) digitalWrite(7, HIGH);
    else digitalWrite(7, LOW);
  if((data)&(0b01000000)) digitalWrite(6, HIGH);
    else digitalWrite(6, LOW);
  if((data)&(0b00100000)) digitalWrite(5, HIGH);
    else digitalWrite(5, LOW);
  if((data)&(0b00010000)) digitalWrite(4, HIGH);
    else digitalWrite(4, LOW);
  if((data)&(0b00001000)) digitalWrite(3, HIGH);
    else digitalWrite(3, LOW);
  if((data)&(0b00000100)) digitalWrite(2, HIGH);
    else digitalWrite(2, LOW);
  if((data)&(0b00000010)) digitalWrite(1, HIGH);
    else digitalWrite(1, LOW);
  if((data)&(0b00000001)) digitalWrite(0, HIGH);
    else digitalWrite(0, LOW);

This is the bottleneck of performance as each individual pin has to be set individually (read modify write operation), while in Arduino there were PORTD = VH; Anyway this workaround works. Also I've changed control pin manipulation with digitalWrite() commands. And surely as as all font/image arrays are stored in SRAM there is no need for pgm_read_byte() commands. Simply we replaced with array read statements.

Arduino based Touchscreen library works on ChipKIT out of box, so no modifications are needed.

Here are few images of working LCD:




Next logical step would be to adapt library for SD card. But this will be next time.

ITDB02_Shield_ChipKIT.zip118.74 KB

Reprinted Url Of This Article: