Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

4-Wire Resistive Touch Screen Interfacing with PIC Micro-Controller

Status
Not open for further replies.

xpress_embedo

Advanced Member level 4
Joined
Jul 5, 2011
Messages
1,154
Helped
161
Reputation
396
Reaction score
189
Trophy points
1,353
Location
India
Activity points
10,591
Hello! Everyone

I am using this touch screen driver circuit

https://researchdesignlab.com/4-wire-resistive-touch-screen-driver.html

It works fine, and i am getting adc values in the range 100(minimum) - 700(maximum) for both axis.
Is this the normal, as i was expecting 0-1023 adc values.

The program i am using as follow:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <stdint.h>
#include <stdio.h>
 
// Glcd module connections
char GLCD_DataPort at PORTD;
 
sbit GLCD_CS1 at RB1_bit;
sbit GLCD_CS2 at RB0_bit;
sbit GLCD_RS  at RC1_bit;
sbit GLCD_RW  at RC0_bit;
sbit GLCD_EN  at RC2_bit;
sbit GLCD_RST at RB5_bit;
 
sbit GLCD_CS1_Direction at TRISB1_bit;
sbit GLCD_CS2_Direction at TRISB0_bit;
sbit GLCD_RS_Direction  at TRISC1_bit;
sbit GLCD_RW_Direction  at TRISC0_bit;
sbit GLCD_EN_Direction  at TRISC2_bit;
sbit GLCD_RST_Direction at TRISB5_bit;
// End Glcd module connections
 
// Touch Panel module connections
sbit DriveA at RB2_bit;
sbit DriveB at RB3_bit;
sbit DriveA_Direction at TRISB2_bit;
sbit DriveB_Direction at TRISB3_bit;
// End Touch Panel module connections
 
 
char glcd_data[16] = {0};
 
uint16_t Get_X( void );
uint16_t Get_Y( void );
 
void main()
{
  static uint16_t x_pos_prev, y_pos_prev = 0;
  TRISB2_bit = 0;
  TRISB3_bit = 0;
  RB2_bit = 0;
  RB3_bit = 0;
  Glcd_Init();
  Delay_ms(100);
  // Initialize ADC
  //////////////////////////////////////////////////////////////////////////////
  ADCON0.ADON = 1;
  // Set Reference Voltage
  ADCON1.VCFG1  = 0;    // Vss
  ADCON1.VCFG0  = 0;    // Vdd
  // Configure ADC Channels
  TRISA |= 0x1F;  // AN0-AN4 as Input Pins
  // Channel 0-6 as Analog Channels
  ADCON1.PCFG0 = 0;
  ADCON1.PCFG1 = 0;
  ADCON1.PCFG2 = 0;
  ADCON1.PCFG3 = 1;
  // Clock Configuration
  ADCON2.ADFM   = 1;    // Right Justified
  // Acquisition Time 2TAD
  ADCON2.ACQT0 = 1;
  ADCON2.ACQT1 = 0;
  ADCON2.ACQT2 = 0;
  // Clock Source FOSC/64
  ADCON2.ADCS0 = 0;
  ADCON2.ADCS1 = 1;
  ADCON2.ADCS2 = 1;
  //////////////////////////////////////////////////////////////////////////////
  Glcd_Fill(0);
  Delay_ms(1000);
  Glcd_Fill(0xFF);
  Delay_ms(1000);
  Glcd_Fill(0);
  Glcd_Write_Text("Touch Screen",0,0,1);
  TP_Init(128,64,0,1);
  TP_Set_ADC_Threshold(700);
 
  while(1)
  {
    /*
    uint16_t x_pos, y_pos;
    x_pos = Get_X();
    y_pos = Get_Y();
    if( x_pos > 100 && x_pos < 700 && y_pos > 100 && y_pos < 700 )
    {
      uint32_t temp1, temp2;
      temp1 = x_pos - 100;
      temp1 = temp1*128/600;
      temp2 = y_pos - 100;
      temp2 = temp2*64/600;
      sprintf(glcd_data,"%.4d    %.4d    ",x_pos,y_pos);
      Glcd_Write_Text(glcd_data,0,0,1);
      Glcd_Dot((uint8_t)temp1,(uint8_t)temp2,1);
      //Delay_ms(100);
    }
    */
    uint16_t adc_value = 0;
    adc_value = Adc_Read(4);
    sprintf(glcd_data,"Adc Value = %.4d",adc_value);
    Glcd_Write_Text(glcd_data,0,1,1);
 
    adc_value = Get_X();
    if( (abs(adc_value - x_pos_prev) > 10) && adc_value )
    {
      sprintf(glcd_data,"X Value = %.4d",adc_value);
      Glcd_Write_Text(glcd_data,0,2,1);
      x_pos_prev = adc_value;
    }
 
    adc_value = Get_Y();
    if( (abs(adc_value - y_pos_prev) > 10) && adc_value )
    {
      sprintf(glcd_data,"Y Value = %.4d",adc_value);
      Glcd_Write_Text(glcd_data,0,3,1);
      y_pos_prev = adc_value;
    }
    Delay_ms(10);
  }
}
 
uint16_t Get_X( void )
{
  uint16_t x_cor = 0;
  RB2_bit = 1;
  RB3_bit = 0;
  Delay_ms(5);
  x_cor = Adc_Read(0);
}
uint16_t Get_Y( void )
{
  uint16_t y_cor = 0;
  RB3_bit = 1;
  RB2_bit = 0;
  Delay_ms(5);
  y_cor = Adc_Read(1);
}



I want that my program draw using whatever i draw using fingers on the glcd using touch screen.
For that i used this code, but it fails, it just displaying some random dots.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
uint16_t x_pos, y_pos;
    x_pos = Get_X();
    y_pos = Get_Y();
    if( x_pos > 100 && x_pos < 700 && y_pos > 100 && y_pos < 700 )
    {
      uint32_t temp1, temp2;
      temp1 = x_pos - 100;
      temp1 = temp1*128/600;
      temp2 = y_pos - 100;
      temp2 = temp2*64/600;
      sprintf(glcd_data,"%.4d    %.4d    ",x_pos,y_pos);
      Glcd_Write_Text(glcd_data,0,0,1);
      Glcd_Dot((uint8_t)temp1,(uint8_t)temp2,1);
      
    }

 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top