You have no items in your shopping cart.

Subtotal: 0.00

Abstract

A touch screen is an electronic visual display that can detect the presence and location of a touch within the display area. The term generally refers to touching the display of the device with a finger or hand. Touch screens can also sense other passive objects, such as a stylus. Fig. 1 shows how to interface the touch panel into microcontroller. To read the position of the touch, we have to first read touch position sequentially i.e. first read X position and then read the Y position. To do this, connect X1 and Y2 pins of touch screen to ADC multiplexed GPIO pins of the controller. And connect X2 and Y1 pins of touch screen to simple GPIO pins of the microcontroller.

Fig. 1 Interfacing Touch panel to Microcontroller





Introduction to touch screen





A touch screen is an electronic visual display that can detect the presence and location of a touch within the display area. The term generally refers to touching the display of the device with a finger or hand. Touch screens can also sense other passive objects, such as a stylus. Touch screens are common in devices such as game consoles, all-in-one computers, tablet computers, and phones. The touch screen has two main attributes. First, it enables one to interact directly with what is displayed, rather than indirectly with a pointer controlled by a mouse or touchpad. Secondly, it lets one do so without requiring any intermediate device that would need to be held in the hand (other than a stylus, which is optional for most modern touch screens). Such displays can be attached to computers, or to networks as terminals. They also play a prominent role in the design of digital appliances such as the personal digital assistant (PDA), satellite navigation devices, mobile phones, and video games. A touch screen is a computer display screen that is also an input device. The screens are sensitive to pressure; a user interacts with the computer by touching pictures or words on the screen.

Principle of operation

A resistive touch panel consists of two transparent rigid foils, forming a “sandwich” structure, that have resistive layers on their inner sides. The resistance of these layers usually does not exceed 1Kohm. the opposite sides of the foils have contacts available for use through a fl at cable. The process of determining coordinates of the point in which the touch panel is pressed can be broken up into two steps. The first one is the determination of the X coordinate and the second one is the determination of the Y coordinate of the point. In order to determine the X coordinate, it is necessary to connect the left contact on the X surface to ground and the right contact to the power supply. This enables a voltage divider to be obtained by pressing the touch panel. The value of the divider is read on the bottom contact of the Y surface. Voltage can be in the range of 0V to the power supply and depends on the X coordinate. If the point is closer to the left contact of the X surface, the voltage will be closer to 0V. In order to determine the Y coordinate, it is necessary to connect the bottom contact on the Y surface to ground, and the upper contact to power supply





Graphics Mode

These LCDs have a graphics and a text mode, so I decided to use it in graphics mode and draw the text manually. This would only be practical on an Arduino Mega (or compatible) as I would need 1KB (128x64/8 = 1024 bytes) of memory for a screen buffer, plus memory for the characters.

Specifications

  • Voltage: 5V
  • With Chinese font
  • Blue backlit
  • Controller: ST7920
  • Size: 93x70mm

 

Connecting to microcontroller





In order to connect a touch panel to the microcontroller it is necessary to create a circuit for touch panel control. By means of this circuit, the microcontroller connects appropriate contacts of the touch panel to ground and the power supply (as described above) in order to determine the X and Y coordinates The bottom contact of the Y surface and left contact of the X surface are connected to the microcontroller’s A/D converter. The X and Y coordinates are determined by measuring voltage on these contacts, respectively. The software consists of writing a menu on graphic LCD, turning the circuit for touch panel control on/off (driving touch panel) and reading the values of A/D converter which actually represent the X and Y coordinates of the point. Once the coordinates are determined

Interfacing Touch panel with LPC2148

To Interface touch screen with a microcontroller, we will need a two or more channels of Analog-to-Digital converter. This is needed because, the touch screen will provide data in terms of an analog voltage on two different pins, using which, we have to determine position of the touch. Also, ADC input pins of the microcontroller should be configurable as General Purpose I/O (GPIO).The ARM7 LPC2148 Evaluation Board has four numbers of Touch panel connections, connected with I/O Port lines (P1.20 – P1.21 && P0.29 – P0.30) to make touch panel output.

Pin Assignment with LPC 2148

 

LPC 2148 TOUCH PANEL P0.30 LEFT P1.21  DRIVE-B

P0 P0.29  BOTTOM
 P0  P1.20  DRIVE-A

 

Circuit Diagram to Interface Touch panel with LPC2148





Source Code

/*
* Project name:
* Description:
 This is a simple demonstration of the GLCD library routines:
 - Init and Clear (pattern fill)
 - Image display
 - Draw on GLCD using Touch-panel
* Test configuration:
 MCU: LPC2148
 Dev.Board: Easy ARM
 Oscillator: 12.0 MHz (cclk = 60.0 MHz, Fcco = 240.0 MHz)
 Ext. Modules: GLCD 128x64 Display with Touch-panel
 SW: KEIL uVision3 v3.62c
* NOTES:
 - Place Pull-up Jumper J16 at PORT0[15..8]
 - Connect PORT0[15..8] and PORT1[23..16] with IDC10 cable (bypass ports)
 - Turn ON four Touch-panel switches (Switch SW3).
 - The LEDs on all ports OFF!
*/
#include 
#include "Glcd.h"
#include "Utility.h"
#define Ctrl_IOPIN IOPIN0
#define Ctrl_IOCLR IOCLR0
#define Ctrl_IOSET IOSET0
#define Pin_CS1 10 
#define Pin_CS2 11
#define Pin_RS 12
#define Pin_RW 13
#define Pin_EN 14
#define Pin_RST 15
#define Panel_IOPIN IOPIN0
#define Panel_IODIR IODIR0
#define Panel_IOCLR IOCLR0
#define Panel_IOSET IOSET0
#define Pin_DrvA 12
#define Pin_DrvB 13
//--- CONSTANTS
char
 write_msg[] = "WRITE", // GLCD menu messages
 clear_msg[] = "CLEAR",
 erase_msg[] = "ERASE";
const unsigned long
 ADC_THRESHOLD = 960; // Threshold value for press detection
//--- VARIABLES
unsigned char GLCD_CSstat, write_erase, pen_size;
unsigned long
 x_coord, y_coord,
 x_coordOLD, y_coordOLD,
 x_coordD, y_coordD;
long
 // scaled x-y position
 x_coord128, y_coord64,
 // calibration constants
 cal_x_min, cal_y_min,
 cal_x_max, cal_y_max;
void ADC_Init()
{
 // AD0.2 [P0.29] as TP-BOTTOM analog pin
 // AD0.3 [P0.30] as TP-LEFT analog pin

 // Initial AD0.2,AD0.3 (P0.29,P0.30) By Set PINSEL1[29:28=01, 27:26=01]
 // xx01 01xx xxxx xxxx xxxx xxxx xxxx xxxx
 PINSEL1 &= 0xD7FFFFFF;
 PINSEL1 |= 0x14000000;
 // set PDA0 (Enable Power to ADC0)
 PCONP |= (unsigned long)(0x00000001) << 12;
 // Enable ADC0
 AD0CR &= 0x00000000; // Clear All Bit Control
 AD0CR |= 0x00000008; // Select ADC = AD0.3
 AD0CR |= 0x00000700; // ADC Clock = VBP(PCLK) / 8
 AD0CR &= 0xFFFEFFFF; // Busrt = 0  - Conversions are software controlled and reguire 11 clocks
 AD0CR &= 0xFFF1FFFF; // CLKS = 000 - 10Bit : 11 Cycle Clock Conversion
 AD0CR |= 0x00200000; // PDN = 1 - Active ADC Module
 // Disable ADC1
 AD1CR = 0;
}

//---------------------------------------------------------------
// Read Analog Value from AD0.2 [P0.29] = TP-BOTTOM analog pin
//---------------------------------------------------------------
unsigned long ADC_Get2()
{
 unsigned long
 val;
 // Select ADC = AD0.2
 AD0CR &= 0xFFFFFF00;
 AD0CR |= 0x00000004;
 // START = 001 = Start Conversion Now
 AD0CR |= 0x01000000;
 // Wait ADC Conversion to Complete and Read A/D Data Register
 do {
 DelayProc(25.0E-06 * CCLOCK);
 } while ((AD0GDR & 0x80000000) == 0);
 // Shift ADC Result to Integer
 val = (AD0DR2 >> 6) & 0x000003FF;
 AD0CR &= 0xF8FFFFFF;
 return (val);
}
//---------------------------------------------------------------
// Read Analog Value from AD0.3 [P0.30] = TP-LEFT analog pin
//---------------------------------------------------------------
unsigned long ADC_Get3()
{
 unsigned long
 val;
 // Select ADC = AD0.3
 AD0CR &= 0xFFFFFF00;
 AD0CR |= 0x00000008;
 // START = 001 = Start Conversion Now
 AD0CR |= 0x01000000;
 // Wait ADC Conversion to Complete and Read A/D Data Register
 do {
 DelayProc(25.0E-06 * CCLOCK);
 } while ((AD0GDR & 0x80000000) == 0);
 // Shift ADC Result to Integer
 val = (AD0DR3 >> 6) & 0x000003FF;
 AD0CR &= 0xF8FFFFFF;

 return (val);
}
//---------------------------------------------------------------
// Disconnect GLCD module
//---------------------------------------------------------------
void Untouch_GLCD()
{
 // Store state of GLCD pins CS1#, CS2#, RS and R/W.
 GLCD_CSstat = 0;
 if (((Ctrl_IOPIN) & ((unsigned long)(1) << Pin_CS1)) != 0)
 GLCD_CSstat |= 0x01;
 if (((Ctrl_IOPIN) & ((unsigned long)(1) << Pin_CS2)) != 0)
 GLCD_CSstat |= 0x02;
 if (((Ctrl_IOPIN) & ((unsigned long)(1) << Pin_RS)) != 0)
 GLCD_CSstat |= 0x04;
 if (((Ctrl_IOPIN) & ((unsigned long)(1) << Pin_RW)) != 0)
 GLCD_CSstat |= 0x08;
 // Set CS1# and CS2# to disconnect GLCD module
 Ctrl_IOSET |= ((unsigned long)(1) << Pin_CS1);
 Ctrl_IOSET |= ((unsigned long)(1) << Pin_CS2);
}
//---------------------------------------------------------------
// Connect GLCD module
//---------------------------------------------------------------
void Touch_GLCD()
{
 // R/W
 if ( (GLCD_CSstat & 0x08) == 0 )
 Ctrl_IOCLR |= ((unsigned long)(1) << Pin_RW);
 else
 Ctrl_IOSET |= ((unsigned long)(1) << Pin_RW);
 // RS
 if ( (GLCD_CSstat & 0x04) == 0 )
 Ctrl_IOCLR |= ((unsigned long)(1) << Pin_RS);
 else
 Ctrl_IOSET |= ((unsigned long)(1) << Pin_RS);

 // CS2#
 if ( (GLCD_CSstat & 0x02) == 0 )
 Ctrl_IOCLR |= ((unsigned long)(1) << Pin_CS2);
 else
 Ctrl_IOSET |= ((unsigned long)(1) << Pin_CS2);
 // CS1#
 if ( (GLCD_CSstat & 0x01) == 0 )
 Ctrl_IOCLR |= ((unsigned long)(1) << Pin_CS1);
 else
 Ctrl_IOSET |= ((unsigned long)(1) << Pin_CS1);
}
char PressDetect()
{
 unsigned long
 adc_val;
 Untouch_GLCD();

 // PRESS detecting
 Panel_IODIR |= (unsigned long)(1) << Pin_DrvA;
 Panel_IOCLR |= (unsigned long)(1) << Pin_DrvA; // DRIVEA (P0.12) = 0 (LEFT drive off, RIGHT drive off, TOP drive on)
 Panel_IODIR |= (unsigned long)(1) << Pin_DrvB;
 Panel_IOCLR |= (unsigned long)(1) << Pin_DrvB; // DRIVEB (P0.13) = 0 (BOTTOM drive off)
 DelayProc(500.0E-06 * CCLOCK);

 adc_val = ADC_Get3(); // Read AD0.3 (READ-Y)
 Touch_GLCD();
 return (adc_val > ADC_THRESHOLD);
}
unsigned long GetX()
{
 unsigned long
 adc_val;
 Untouch_GLCD();
 // reading X
 Panel_IODIR |= (unsigned long)(1) << Pin_DrvA;
 Panel_IOSET |= (unsigned long)(1) << Pin_DrvA; // DRIVEA (P0.12) = 1 (LEFT drive on, RIGHT drive on, TOP drive off)
 Panel_IODIR |= (unsigned long)(1) << Pin_DrvB;
 Panel_IOCLR |= (unsigned long)(1) << Pin_DrvB; // DRIVEB (P0.13) = 0 (BOTTOM drive off)
 DelayProc(500.0E-06 * CCLOCK);
 adc_val = ADC_Get2(); // reading X value from AD0.2 (BOTTOM)
 Touch_GLCD();
 return adc_val;
}

unsigned long GetY()
{
 unsigned long
 adc_val;
 Untouch_GLCD();
 // reading Y
 Panel_IODIR |= (unsigned long)(1) << Pin_DrvA;
 Panel_IOCLR |= (unsigned long)(1) << Pin_DrvA; // DRIVEA (P0.12) = 0 (LEFT drive off, RIGHT drive off, TOP drive on)
 Panel_IODIR |= (unsigned long)(1) << Pin_DrvB;
 Panel_IOSET |= (unsigned long)(1) << Pin_DrvB; // DRIVEB (P0.13) = 1 (BOTTOM drive on)
 DelayProc(500.0E-06 * CCLOCK);
 adc_val = ADC_Get3(); // reading X value from AD0.3 (LEFT)
 Touch_GLCD();
 return adc_val;
}
void Calibrate()
{
 GLCD_Dot(0,63,1);
 Glcd_Write_Text("TOUCH BOTTOM LEFT",10,3,1);
 while ( !PressDetect() );
 // get calibration constants (reading and compensating TouchPanel nonlinearity)
 cal_x_min = GetX() - 10;
 cal_y_min = GetY() - 10;
 DelayProc(0.5 * CCLOCK);
 Glcd_Fill(0);
 GLCD_Dot(127,0,1);
 Glcd_Write_Text("TOUCH UPPER RIGHT",10,4,1);
 while ( !PressDetect() );
 // get calibration constants (reading and compensating TouchPanel nonlinearity)
 cal_x_max = GetX() + 5;
 cal_y_max = GetY() + 5;
 DelayProc(0.5 * CCLOCK);
}
int main (void)
{
 PINSEL0 = 0;
 PINSEL1 = 0;
 PINSEL2 &= 0x0000000C;
 PINSEL2 |= 0x00000030;
 DelayProc(0.2 * CCLOCK);
 // Initialize Internal ADC
 ADC_Init();
 // Initialize GLCD (Control port is bypassed)
 IODIR0 = 0;
 Glcd_Init(&Ctrl_IOPIN, // Control lines Port
 &IOPIN0, // Data Lines Port
 Pin_CS1, // CS1#
 Pin_CS2, // CS2#
 Pin_RS, // RS
 Pin_RW,  // R/W#
 Pin_RST, // RST
 Pin_EN, // EN
 16); // D0 data line position
 Glcd_Fill(0);
 Glcd_Write_Text("CALIBRATION", 24, 3, 1);
 DelayProc(1.5 * CCLOCK);
 Glcd_Fill(0);
 Calibrate();
 Glcd_Fill(0);
 Glcd_Write_Text("WRITE ON SCREEN", 24, 4, 1) ;
 DelayProc(1.0 * CCLOCK);
 Glcd_Fill(0);
 Glcd_Fill(0);
 Glcd_V_Line(0,7,0,1);
 Glcd_Write_Text(clear_msg,1,0,0);
 Glcd_V_Line(0,7,97,1);
 Glcd_Write_Text(erase_msg,98,0,0);
 // Pen Menu:
 Glcd_Rectangle(41,0,52,9,1);
 Glcd_Box(45,3,48,6,1);
 Glcd_Rectangle(63,0,70,7,1);
 Glcd_Box(66,3,67,4,1);
 Glcd_Rectangle(80,0,86,6,1);
 GLCD_Dot(83,3,1);
 write_erase = 1;
 pen_size = 1;
 x_coordOLD = 0;
 y_coordOLD = 0;
 while(1)
 {
 if (PressDetect())
 { // after a PRESS is detected read X-Y and convert it to 128x64 space
 x_coord = GetX() - cal_x_min;
 y_coord = GetY() - cal_y_min;
 if (x_coordOLD >= x_coord)
 x_coordD = x_coordOLD - x_coord;
 else
 x_coordD = x_coord - x_coordOLD;
 if (y_coordOLD >= y_coord)
 y_coordD = y_coordOLD - y_coord;
 else
 y_coordD = y_coord - y_coordOLD;
 x_coordOLD = x_coord;
 y_coordOLD = y_coord;
 if ((x_coordD > 25) || (y_coordD > 25))
 continue;
 x_coord128 = (x_coord * 128l) / (cal_x_max - cal_x_min);
 y_coord64 = (64 -(y_coord *64) / (cal_y_max - cal_y_min));
 if ((x_coord128 < 0) || (x_coord128 > 127))
 continue;
 if ((y_coord64 < 0) || (y_coord64 > 63))
 continue;
 // if clear is pressed
 if ((x_coord128 < 31) && (y_coord64 < 8))
 {
 Glcd_Fill(0);
 // Pen Menu:
 Glcd_Rectangle(41,0,52,9,1);
 Glcd_Box(45,3,48,6,1);
 Glcd_Rectangle(63,0,70,7,1);
 Glcd_Box(66,3,67,4,1);
 Glcd_Rectangle(80,0,86,6,1);
 GLCD_Dot(83,3,1);
 Glcd_V_Line(0,7,0,1);
 Glcd_Write_Text(clear_msg,1,0,0);
 Glcd_V_Line(0,7,97,1);
 if (write_erase)
 Glcd_Write_Text(erase_msg,98,0,0);
 else
 Glcd_Write_Text(write_msg,98,0,0);
 }
 // if write/erase is pressed
 if ((x_coord128 > 96) && (y_coord64 < 8))
 {
 if (write_erase)
 {
 write_erase = 0;
 Glcd_Write_Text(write_msg,98,0,0);
 DelayProc(0.5 * CCLOCK);
 }
 else
 {
 write_erase = 1;
 Glcd_Write_Text(erase_msg,98,0,0);
 DelayProc(0.5 * CCLOCK);
 }
  }
 // if pen size is selected
 if ((x_coord128 >= 41) && (x_coord128 <= 52) && (y_coord64 <= 9))
 pen_size = 3;
 if ((x_coord128 >= 63) && (x_coord128 <= 70) && (y_coord64 <= 7))
 pen_size = 2;
 if ((x_coord128 >= 80) && (x_coord128 <= 86) && (y_coord64 <= 6))
 pen_size = 1;
 if (y_coord64 < 11)
 continue;
 switch (pen_size)
 {
 case 1:
 GLCD_Dot(x_coord128, y_coord64, write_erase);
 break;
 case 2:
 Glcd_Box(x_coord128, y_coord64, x_coord128 + 1, y_coord64 + 1, write_erase);
 break;
 case 3:
 Glcd_Box(x_coord128-1, y_coord64-1, x_coord128 + 2, y_coord64 + 2, write_erase);
 break;
 }
 }
 }
}

Conclusion

Touch screen interface with Arm 7 microcontroller is very intuitive easy to use as the user simply touches what he or she sees on the display. Save space as no keyboard or mouse is required. We think this product have high potential for marketing in the future.