PIC16F19197 Low-Power Touch Enabled LCD Demonstration

Giovanni Bernardo | September 17th, 2017
Categories: PIC® MCUs - Sensors

Microchip sent us a new demoboard equipped with a custom LCD display LCD and a PIC16F19197. It’s a good occasion for discovering some interesting peripherals such as the LCD Controller Module and the mTouch™ framework.

Board itself is not small : 126x144mm (with a weight of 315g batteries included), it’s a beautiful piece of furniture:

Hope my sons won’t blame me for stolen their bricks!

I’ve made a support using Legos and the whole thing is very cool on my desk! Now let’s go to discover hardware and software features of this beautiful demoboard.

Power supply

Board is powered by 3 AAA batteries or by a fuse-protected micro-usb port, a switch is used to toggle between sources. If board is unpowered, time is keeped by  CR2032 backup battery connected t0 VBAT (RA5) pin of the picmicro.

VBat pin consents secondary oscillator (SOSC) and Real Time Clock Calendar (RTCC) to be powered even if main power on VDD is lost. This feature has to be enabled in the config word:

#pragma config VBATEN = ON

The Picmicro runs at 3.3V, power from batteries or USB is sent to a MCP1703 voltage regulator that features a low quiescent curent  (2.0 µA) and a low tipical droput voltage (0,625V).

Display backlight come from an array of white leds. Leds are driven by a MIC2287 that gives a pwm voltage output of ~15V with no-load and ~12V with the backlight on.

I’ve measured a whole board consumption around 200mW:

Display -> LCD Controller Module

Display on the board is a custom one and is made by Varitronix. It hasn’t a controller such as common displays we normally use in our project (based on HD44780 / PCD8544 / KS0108 and so on… ).

This kind of displays has some advatages:

  • We can design our own fonts, icons specifying the design to the display manufacturer.
  • In big quantities, an LCD without a controller is cheapest.

Disavantadge of this kind of displays is that requires a lot of IOs for driving the segments and a Charge Pump with voltage ramps, but picmicro with LCD Controller module are designed for doing the dirty job!

This display has a central wheel made by segments used for showing the seconds, a central dot-matrix made by 7×28 pixels, used for showing time and a scrolling text. In the upper left and right corner there are Microchip and Varitronix logos. Below the dot-matrix zone there are 2 round icons: a right-hand arrow and a check symbol. Above the dot-matrix there are 4 icons: compass, stopwatch, clock and low battery (first and last icons are not used by demo v2).

Icons on display. Every icon is a segment.

So we have 60+(7×28)+2+2+4 = 264 elements arranged in a 33×8 matrix (33 segments-rows x 8 commons-columns). This kind of display is a 1/8 Multiplex.

The PIC16F19197 can control up to 368 dots (46 segments x 8 commons), and has a charge pump that rises the VDD to 5V required by segments. Charge pump requires a capacitor between 2 pins (RH2 and RH3). PICmicro generates also the bias voltages using an internal resistive ladder: for this feature, only 3 capacitors are required on VLCD1/2/3 pins.

Charge pump must be enabled in the config word:

#pragma config LCDPEN = ON

Some registers have to be configured in order to make LCD Control Module working. We must specify the number of commons:

LCDCONbits.LMUX = 0b1000;

Enable charge pump functions in the LCDVCON1 registry:

LCDVCON1bits.LPEN = 1;  // la pompa di carica lavora in modalità bassa corrente
LCDVCON1bits.EN5V = 1; // viene abilitato il range di 5V
LCDVCON1bits.BIAS = 0b111;  // la tensione di uscita della pompa di carica viene impostata a 5.1V

And bias voltages in the LCDVCON2 registry:

LCDVCON2bits.CPWDT = 0; // disabilita il watchdog timer del modulo LCD
LCDVCON2bits.LCDVSRC = 0b0110; // le rampe sono generate esclusivamente dalla rete resistiva interna, quindi sui pin VLCD1/2/3 andranno solo posti dei condensatori

Other settings are in the LCD_Initialize() function in lcd.c module. In the LCD.h module are placed all single pixel/segments definitions. Example:

#define S1 S19C7 // T1
#define S2 S41C7 // T2
#define S3 S27C7 // T3

S19C7 stands for Segment (row) 19, Common (column) 7 and is a mnemonic word defined in the XC8 pic16f19197 header.

Defines from S1 to S60 are for the seconds segments. Icons are defined with their names (ARROW, CHECK, MICROCHIP, VARITRONIX ecc). Dots of central matrix are defined as XnCm where n is a number from 1 to 7 and indexes the row (1 is the upper row) and m is the column, from 1 to 28.

I’ve included a space invader icon at startup writing a simple function:

void SpaceInvaderIcon(void)
X4C10=1; X5C10=1; X6C10=1;
X3C11=1; X4C11=1;
X2C12=1; X3C12=1; X4C12=1; X5C12=1; X6C12=1;
X1C13=1; X2C13=1; X4C13=1; X5C13=1; X7C13=1;
X2C14=1; X3C14=1; X4C14=1; X5C14=1; X7C14=1;
X2C15=1; X3C15=1; X4C15=1; X5C15=1;
X2C16=1; X3C16=1; X4C16=1; X5C16=1; X7C16=1;
X1C17=1; X2C17=1; X4C17=1; X5C17=1; X7C17=1;
X2C18=1; X3C18=1; X4C18=1; X5C18=1; X6C18=1;
X3C19=1; X4C19=1;
X4C20=1; X5C20=1; X6C20=1;

For the scrolling text banner a special function was written, is a little bit complex and you can read it in the banner.h and banner.c modules. In the banner_strings.h module you can change the text:

// Max number of character per line should be less than 70,
// up to 10 lines, and no more than 450 characters total
const char* stringArray[10] = {

Touch-Screen -> ADC Module + mTouch™ Framework

Above the display is placed a capacitive touch screen. Is not the same kind of touch screen we can find on our smartphone, where the finger pressure can be evaluated on every little spot on display (2D touchscreen), but is a  1D touchscreen type: pressure can be evaluated only on single spots (sensors). In the demoboard screen there are 8 sensors: 2 above the Arrow and Check icons and 6 are placed above the 60-segments crown forming a capacitive wheel.

Working principles of a capacitive touchscreen: touching the sensible area body adds a capacitance to the reference one. Voltage across the two capacitors is different while the charge is the same. ADC module compute the voltages.

Microchip has developed an ad-hoc framework for the 1D touch screens called mTouch™ (you can include this framework in your project using the Code Configurator in MPLAB X IDE). Library manages Buttons, Sliders (finger slide in two directions) and Wheels (finger slide in a circular pattern clockwise/counterclockwise). Library uses an A/D module with an Hardware Capacitance Voltage Divider (HCVD). Further informations about HCVD are in the datasheet at page 289.

8 buttons are defined in the firmware. Buttons 7 and 8 are connected to analog ports on RA2 and RB0 and represents the sensors above Arrow and Check icons. Buttons from 1 to 6 (RA7, RA6, RA3, RA1, RA0, RA4) are connected to sensor-pads around the 60-segments crown and are managed differently in order to recognize the clockwise or counterclockwise finger movement.

Capacitive Pads Layout. Thanks to Xiang Gao from Microchip

mTouch™ functions are called by the Timer4 interrupt every about 5mS. Timer4 is configured for using LFINTOSC (Low Frequency Internal Oscillator @ 31KHz). Pre and Post scaler are @ 1:1 and T4PR registry (Timer 4 Period) is loaded with the value of 154:

T4CLKCONbits.CS = 0b0100; // sorgente di clock: LFINTOSC (31KHz)
T4RST = 0x00; // Timer 4 resettato dal suo stesso interrupt
T4PR = 0x9A; // Timer 4 Period: 154

Using the 31KHz clock (period: about 32µS), counter increments by one every 32µS, every clock period counter is matched to PR4 register, so the match will happen at 32µS*154 = 4967µS ≅ 5mS. Enabling interrupt, Timer4 Interrupt Flag will be raised.


Buzzer is a passive one, so requires a square wave for emitting a sound. PWM3 is used to generate a 6.25Khz note. PWM3 output is configured on RC4 (RC4PPS=0x0B, datasheet pag. 448) and is clocked by Timer2. In the configuration files prescaler is 1:4, clock source is Fosc/4 and the period (PR2) is loaded to 79. PWM period is given bu the formula:

Tpwm = (PR2 + 1)*4*Tosc*Ps

Where Tosc=1/Fosc=1/8000000 (PICmicro uses internal clock @ 8MHz) and Ps is the Prescaler value (4). PWM period is so 0,00016sec (6.25KHz). Turning on the timer will make buzzer sound.

RTCC Module

RTCC Module (Real Time Clock Calendar) manage the time keeping and uses the external secondary oscillator (SOSC), given by an external 32.768KHz crystal with two load capacitors.

This module can also use the 50Hz or 60Hz from the power line using a zero cross detect internal circuitry.

SOSC and RTCC module works even if main power on VDD goes down, using the power from VBat pin. This module has separate registers for years, months, days, days of the week, hour, minutes and seconds and runs without CPU usage managing the leap year too. Every time register has an equivalent Alarm register for setting an Alarm rising an interrupt. Seconds alarm register is used to fire up an interrupt every second:

ALRMCONbits.AMASK = 0b0001;

Demo instructions

This demo has 3 operating modes: scrolling text, clock and stopwatch. To toggle between modes, press the arrow key.

  • Mode 1 – scrolling text: displays a message that lists features of PIC16(L)F19197 family
  • Mode 2 – clock: press both the “arrow” and “check” keys simultaneosly to adjust the time. The time can be changed by sliding your finger around the perimeter LCD segments. Use the “arrow” key to toggle between hours and minutes. Press the “check” key to set the time. To toggle between 12-hour and 24-hour format, touch che “check” key after the time has been set.
  • Mode 3 – stopwatch: press the “check” key to start/stop the timer. To clear the timer, press both “arrow” and “check” keys simultaneosly.


External links

Questo articolo ti è stato utile? Ti ha permesso di risolvere un problema o di migliorare le tue applicazioni? Ci lavori? Ti ha permesso di scrivere la tua tesina? Ti ha semplicemente fatto spendere un po' del tuo tempo in maniera costruttiva? Allora clicca il banner qui sotto:

Settorezero.com è un blog personale di Giovanni Bernardo aperto dal 25 Ottobre 2007. Non è una testata giornalistica né un sito a carattere commerciale.
Settorezero.com, il logo Zroid™ e la tagline "Play embedded electronics™" sono copyright ©2007÷2019 Giovanni Bernardo.
La navigazione su settorezero.com e la fruizione dei contenuti ivi presenti sono soggette ai seguenti Termini di utilizzo - Informativa sulla privacy - Utilizzo dei Cookie.
Il tema di questo sito è basato sul tema Fusion per wordpress, realizzato originariamente da digitalnature e fa uso del plugin Wassup per il computo delle statistiche.
Per poter contattare il gestore del sito potete utilizzare la sezione contatti o inviare una email a gianni[at]settorezero[dot]com.
Per seguire gli aggiornamenti del blog Settorezero, oltre al feed RSS, puoi anche seguire la pagina Facebook o iscriverti al canale Telegram.
Su Twitter, invece, pubblico un po' di tutto e, quando mi va, uso anche Tumblr - Google+ - Blogspot - Youtube.