How to wok TFT or Touchscreen?
A 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 output signal.
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 _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 _rst 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.
Connecting to micro controller(PIC18F):
Microcontroller used PIC18F458
VCC=5V
GND=0V
CRYSTAL USED 8 MHz
//////////////////////////////////////////////////////
////////PIN DESCRIPTION OF PIC18F458/////////////////
////////////////////////////////////////////////////
PIN1: RESTART OF MICROCONTROLLER
PIN2: READ X(TFT) A/D
PIN3: READ Y(TFT) A/D
PIN4: ANALOG CONVERSION (VREF(-) USED AS GND)
PIN5: ANALOG CONVERSION (VREF(+))
PIN6: SENSOR(S3)
PIN7: SENSOR(S1)
PIN8: SENSOR(S2)
PIN9:
PIN10:
PIN11: VCC(+5V)
PIN12: GND(GND)
PIN13: XT (CRYSTAL OSCILLATOR) USED 8 MHz
PIN14: XT (CRYSTAL OSCILLATOR)
PIN15: RC0 USED FOR DRIVE A OF TFT
PIN16: RC1 USED FOR DRIVE B OF TFT
PIN17:
PIN18: USB VOLTAGE (3.3V) NC
PIN19: D0 OF TFT (DATA PORT USING FOR TFT)
PIN20: D1 OF TFT
PIN21: D2 OF TFT
PIN22: D3 OF TFT
PIN23: INPUT1 FOR H BRIDGE1
PIN24: INPUT2 FOR H BRIDGE1
PIN25: INPUT1 FOR H BRIDGE2
PIN26: INPUT2 FOR H BRIDGE2
PIN27: D4 OF TFT
PIN28: D5 OF TFT
PIN29: D6 OF TFT
PIN30: D7 OF TFT
PIN31: GND (0V)
PIN32: VDD(+5V)
PIN33: CS1 OF TFT
PIN34: CS2 OF TFT
PIN35: RS OF TFT
PIN36: R/W OF TFT
PIN37: ENABLE OF TFT
PIN38: RST OF TFT
PIN39:
PIN40:
//////////////////////////////////////////////////////////
////////// DESCRIPTION OF TFT TOUCH PANEL////////////////
////////////////////////////////////////////////////////
////////IN GENERAL CONFFIGHRATION OF RESISTIVE TOUCH PANEL////////
PIN1: CS1 CONNECTED WITH RB0
PIN2: CS2 CONNECTED WITH RB1
PIN3: GND
PIN4: VCC
PIN5: VO
PIN6: RS(REGISTER SELECTION) CONNECTED WITH RB2
PIN7: R/W(READ OR WRITE) CONNECTED WITH RB3
PIN8: ENABLE CONNECTED WITH RB4
PIN9: D0 CONNECTED WITH RD0
PIN10: D1 CONNECTED WITH RD1
PIN11: D2 CONNECTED WITH RD2
PIN12: D3 CONNECTED WITH RD3
PIN13: D4 CONNECTED WITH RD4
PIN14: D5 CONNECTED WITH RD
PIN15: D6 CONNECTED WITH RD6
PIN16: D7 CONNECTED WITH RD7
PIN17: RST(RESTART) CONNECTED WITH RB5
PIN18: VEE
PIN19: LED(+) VCC
PIN20: LED(-) GND
RIGHT(1): RIGHT SHIFT CONNECTED WITH RC0 DRIVE A
TOP(2): TOP SHIFT CONNECTED WITH RC0 DRIVE A
LEFT(3): LEFT SHIFT CONNECTED WITH RC0 DRIVE A
BUTTOM(4):BUTTOM SHIFT CONNECTED WITH RC1 DRIVE B
DRIVE A: CONNECTED WITH RC0
DRIVE B: CONNECTED WITH RC1
READ X: READING X (DRIVEA = 1 (LEFT drive on, RIGHT drive on, TOP drive off ) , DRIVEB = 0 (BOTTOM drive off ),reading X value from RA0/ANO (BOTTOM))
REDY Y: READING Y (DRIVEA = 0 (LEFT drive off , RIGHT drive off , TOP drive on), DRIVEB = 1 (BOTTOM drive on),reading Y value from RA1/AN1 (from LEFT))
SEE THE PDF FOR UNDERSTANDING THE CONNECTION.
///////////////////////////////////////////////////////
////////// SENSOR MODULE AND H BRIDGE CONNECTION///////
///////////////////////////////////////////////////////
Here control d.c motor both manual and automatic using Touch Screen.
Programming:
void main() {
unsigned char x;
TRISD=0x00;
TRISB=0x00;
TRISA5_bit=1;
TRISE0_bit=1;
TRISA0_bit=1;
TRISA4_bit=1;
TRISA1_bit=1;
TRISC4_bit=0;
TRISC5_bit=0;
TRISC6_bit=0;
TRISC7_bit=0;
TRISC1_bit=0;
TRISC0_bit=0;
TRISB6_bit=1;
GLCD_CS1 = 1; // De-Activate both chips
GLCD_CS2 = 1;
GLCD_RST = 1;
GLCD_ON();
GLCD_Set_Font(Font_Glcd_5x7, 5, 7, 32); // Choose font
GLCD_Fill(0); // Clear GLCD
CopyConst2Ram(msg,msg1); // Copy “COUNTER= ” string to RAM
Glcd_Write_Text(msg,10,0,1);
//Display Buttons on GLCD: ////////
GLCD_Rectangle(3,10,50,35,1);
GLCD_Rectangle(7,16,35,45,1);
GLCD_Rectangle(68,16,120,48,1);
GLCD_Box(10,18,58,46,1);
GLCD_Box(70,14,90,44,1);
GLCD_Box(50,16,70,48,1);
CopyConst2Ram(msg,msg2); // Copy “BUTTON1” string to RAM
GLCD_Write_Text(msg,14,3,0);
CopyConst2Ram(msg,msg4);
GLCD_Write_Text(msg,14,4,0);
CopyConst2Ram(msg,msg3); // Copy “BUTTON2” string to RAM
GLCD_Write_Text(msg,74,3,0);
CopyConst2Ram(msg,msg5); // Copy “MOTOR ANTICLOCKWISE” string to RAM
GLCD_Write_Text(msg,74,5,0);
CopyConst2Ram(msg,msg9); // Copy “BUTTON3” string to RAM
GLCD_Write_Text(msg,82,3,0);
CopyConst2Ram(msg,msg6); // Copy “STOP” string to RAM
GLCD_Write_Text(msg,82,4,0);
Label:
SWITCH1=0;
switch(SWITCH1)
{
case 0: ////FOR AUTOMOMATIC////
if (S1==1 && S2==1)
MOTOR_CLOCKWISE();
else if(S1==1 && S2==0)
MOTOR_ANTICLOCKWISE();
else if(S1=0 && S2==0)
MOTOR_STOP();
else
MOTOR_STOP();
break;
case 1: //////FOR MANNUAL///
if (TP_Press_Detect())
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) && (x_coord128 <= 58) && (y_coord64 >= 18) && (y_coord64 <= 46)) {
{
{
MOTOR_CLOCKWISE();
CopyConst2Ram(msg,msg7); // Copy “CLOCKWISE ON “ string to RAM
Glcd_Write_Text(msg,14,4,0);
}
if ((x_coord128 >= 70) && (x_coord128 <= 90) && (y_coord64 >= 14) && (y_coord64 <= 44)){
MOTOR_ANTICLOCKWISE();
CopyConst2Ram(msg,msg8); // Copy “ANTICLOCKWISE ON “ string to RAM
Glcd_Write_Text(msg,74,4,0);
}
if ((x_coord128 >= 70) && (x_coord128 <= 90) && (y_coord64 >= 14) && (y_coord64 <= 44)) {
MOTOR_STOP();
CopyConst2Ram(msg,msg10); // Copy “STOP “ string to RAM
Glcd_Write_Text(msg,74,4,0);
}
else
MOTOR_STOP();
}
}
break;
T0CON=0x68;
TMR0L=0;
if (S1==1){
do{
T0CON.TMR0ON=1;
x=TMR0L;
}
while(INTCON.TMR0IF==0);
T0CON.TMR0ON=0;
INTCON.TMR0IF==0;
}
CopyConst2Ram(msg,msg1);
GLCD_Write_Data(x);
}
if (x=200) ////8 bit counter so 25 maxima
MOTOR_STOP();
else
goto Label;
}
Thank You.