Use a touch panelA touch panel is a thin, self-adhesive transparent panel placed over the screen of a graphic LCD. It is very sensitive to pressure so that even a soft touch causes some changes on the output signal. There are a few types of touch panel. The simplest one is a resistive touch panel.
'Header****************************************************** program example_15 ' Name of program dim GLCD_DataPORT as byte at PORTD ' GLCD module connections dim GLCD_CS1 as sbit at RB0_bit GLCD_CS2 as sbit at RB1_bit GLCD_RS as sbit at RB2_bit GLCD_RW as sbit at RB3_bit GLCD_EN as sbit at RB4_bit GLCD_RST as sbit at RB5_bit dim GLCD_CS1_Direction as sbit at TRISB0_bit GLCD_CS2_Direction as sbit at TRISB1_bit GLCD_RS_Direction as sbit at TRISB2_bit GLCD_RW_Direction as sbit at TRISB3_bit GLCD_EN_Direction as sbit at TRISB4_bit GLCD_RST_Direction as sbit at TRISB5_bit ' End Glcd module connections dim x_coord, y_coord, x_coord128, y_coord64 as longint ' Scaled x-y position sub function GetX() as word ' Reading X PORTC.0 = 1 ' DRIVEA = 1 (LEFT drive on, RIGHT drive on, TOP drive off) PORTC.1 = 0 ' DRIVEB = 0 (BOTTOM drive off) Delay_ms(5) result = ADC_Read(0) ' READ-X (BOTTOM) end sub sub function GetY() as word ' Reading Y PORTC.0 = 0 ' DRIVEA = 0 (LEFT drive off, RIGHT drive off, TOP drive on) PORTC.1 = 1 ' DRIVEB = 1 (BOTTOM drive on) Delay_ms(5) result = ADC_Read(1) ' READ-X (LEFT) end sub main: ' Start of program PORTA = 0x00 TRISA = 0x03 ' RA0 i RA1 are analog inputs ANSEL = 0x03 ANSELH = 0 ' Configure other analog pins as digital I/O PORTC = 0 TRISC = 0 ' PORTC pins are configured as outputs Glcd_Init() ' Glcd_Init_EP5 Glcd_Set_Font(@font5x7, 5, 7, 32) ' Choose font size 5x7 Glcd_Fill(0) ' Clear GLCD Glcd_Write_Text("TOUCHPANEL EXAMPLE",10,0,1) Glcd_Write_Text("MIKROELEKTRONIKA",17,7,1) Glcd_Rectangle(8,16,60,48,1) ' Outline two ‘buttons’ on GLCD: Glcd_Rectangle(68,16,120,48,1) Glcd_Box(10,18,58,46,1) Glcd_Box(70,18,118,46,1) Glcd_Write_Text("BUTTON1",14,3,0) Glcd_Write_Text("RC6 OFF",14,4,0) Glcd_Write_Text("BUTTON2",74,3,0) Glcd_Write_Text("RC7 OFF",74,4,0) while TRUE ' Read X-Y and convert it to 128x64 space x_coord = GetX() y_coord = GetY() x_coord128 = (x_coord * 128) / 1024 y_coord64 = 64 -((y_coord *64) / 1024) ' If BUTTON1 is selected: if ((x_coord128 >= 10) and (x_coord128 <= 58) and (y_coord64 >= 18) and (y_coord64 <= 46)) then if(PORTC.6 = 0) then PORTC.6 = 1 Glcd_Write_Text("RC6 ON ",14,4,0) else PORTC.6 = 0 Glcd_Write_Text("RC6 OFF",14,4,0) end if end if ' If BUTTON2 is selected: if ((x_coord128 >= 70) and (x_coord128 <= 118) and (y_coord64 >= 18) and (y_coord64 <= 46)) then if(PORTC.7 = 0) then PORTC.7 = 1 Glcd_Write_Text("RC7 ON ",74,4,0) else PORTC.7 = 0 Glcd_Write_Text("RC7 OFF",74,4,0) end if end if Delay_ms(100) wend ' While true end. ' End of programIn order to make this example work properly, it is necessary to check the following libraries in the Library Manager prior to compiling: