4 Wire resistive touch screen, Need help


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    Join Date
    Nov 2009
    Location
    London
    Posts
    251

    Default 4 Wire resistive touch screen, Need help

    Hi, I have been trying to figure out the 4 wire resistive touch screen concept from last few days. Though I have kind of understood the basics of how it operates, but need some jump start on the PBP code side of it. I am struggling to understand on what to do exactly to get the X,Y co-ordinates, how to turn an analog input pin to provide full 5V? may be there is a separate circuit to it or not. A brief idea of the code to start with will be a great help, I have few 16f676 to play with and will try them to get the ball rolling. Thanks

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire resistive touch screen, Need help

    Hmmmm , I am trying to post some code but when I go back to the editing window all I see is the following, everything after "TRISA =" is missing.

    START:
    '################ START READING AVERAGE PRESSURE VALUE ################
    TRISA =
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire resistive touch screen, Need help

    1. Click on GO ADVANCED at bottom right.

    2. Click on the leftmost icon, it is two A; it will say SWITCH EDITOR TO SOURCE MODE when you mouse over.

    3. Click on the CODE icon at far right in the middle row.

    4. Paste your code within those tags.

    WYSIWYG mode gives unpredictable results when you paste code, always switch to source mode first.

    Robert

  4. #4
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire resistive touch screen, Need help

    Quote Originally Posted by Demon View Post
    1. Click on GO ADVANCED at bottom right.

    2. Click on the leftmost icon, it is two A; it will say SWITCH EDITOR TO SOURCE MODE when you mouse over.

    3. Click on the CODE icon at far right in the middle row.

    4. Paste your code within those tags.

    WYSIWYG mode gives unpredictable results when you paste code, always switch to source mode first.

    Robert
    Wow, that fixed it. It was driving me nuts . Thank you.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire resistive touch screen, Need help

    Quote Originally Posted by rsocor01 View Post
    Wow, that fixed it. It was driving me nuts . Thank you.

    1. Click on SETTINGS at top right.

    2. Click on General Settings at left.

    3. Scroll down to Miscellaneous Options.

    4. Select Standard Editor.

    You will now be in SOURCE mode by default when you post and not have to worry about code.

    Robert

  6. #6
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire resistive touch screen, Need help

    Well, I tried in a second computer and it didn't work either. Somehow when I copy-paste the code from MCS into the editor window and press the button "Go Advanced" all the code after "TRISA =" is missing in my editor window and the window kind of freezes up. Is this some kind of bug, because I tried it in two different computers? So, I will attach the code as a txt file.

    Megahertz,

    I wrote a program a while back to control a 4-wire touchscreen in a 320x240 color GLCD. The program worked great. I used a PIC18F4550. The wiring that I used was

    PortA.0, AN0 ---> X+
    PortA.1, AN1 ---> X-
    PortA.2, AN2 ---> Y+
    PortA.3, AN4 ---> Y-


    First, you need to "monitor" the touchscreen to find out if it has been touched. Then if it has been touched you find the coordinates for the point were the screen was touched.

    Also, in this program I had a calibration routine. I displayed in the screen two crosses, one at the upper left corner and the other one at the lower right corner. The user had to touch one cross first and then the other cross to save the optimum parameters for the touchscreen.

    The program is attached as a txt file. Review the program and if you have any questions let me know.

    Touchscreen_Code.txt

    Robert
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire resistive touch screen, Need help

    Quote Originally Posted by rsocor01 View Post
    ...
    The program is attached as a txt file. Review the program and if you have any questions let me know.
    ...
    Tadaa!

    Code:
    '****************************************************************
    '*         MAIN PROGRAM                                         *
    '**************************************************************** 
    
    START:
    
        '################ START READING AVERAGE PRESSURE VALUE ################    
    
        TRISA = %00001001           ' Set Y+ (portA.2, AN2) and X- (portA.1, AN1) as outputs 
                                    ' and Y- (portA.3, AN3) and X+ (portA.0, AN0) as inputs 
        
        low PORTA.1                 ' Set X- = 0V    
        high PORTA.2                ' Set Y+ = 5V     
        ADCON0 = %00000001          ' Bits(5-2): 0000=AN0. Start sampling at X+   
        pauseus 10        
        ADCON0.1 = 1                ' Stops or continues sampling depending on ADCON2 bits(5-3), 
                                    ' then begins conversion         
        
        GOSUB CONVERSION_ROUTINE    ' Obtain value for A/D conversion resolution
        PRESSURE_XP = RESOLUTION    ' Obtain PRESSURE_XP from X+ sampling, X- = 0V, and Y+ = 5V  
        
        ADCON0 = %00001101          ' Bits(5-2): 0011=AN3. Start sampling at Y-   
        pauseus 10        
        ADCON0.1 = 1                ' Stops or continues sampling depending on ADCON2 bits(5-3), 
                                    ' then begins conversion         
    
        GOSUB CONVERSION_ROUTINE    ' Obtain value for A/D conversion resolution
        PRESSURE_YM = RESOLUTION    ' Obtain PRESSURE_YM from Y- sampling, X- = 0V, and Y+ = 5V 
    
        IF (PRESSURE_XP > 24) AND (PRESSURE_YM < 1000) THEN         ' THE TOUCHSCREEN HAVE BEEN TOUCHED         
            GOSUB READ_COORDINATES
            gosub CALIBRATE_TOUCHSCREEN 
        ENDIF      
    
        LCDOUT $FE, 1                                                       ' Clear LCD                               
        LCDOUT $FE,2,"X=",DEC5 X_VALUE,", Y=",DEC5 Y_VALUE                  ' DISPLAYS A/D CONVERSION VALUES            
        LCDOUT $FE,$C0,"P1=",DEC4 PRESSURE_XP,", P2=",DEC4 PRESSURE_YM   
        
        GOTO START
    
    
    '****************************************************************
    '*         READ X AND Y VALUES SUBROUTINE                       *
    '**************************************************************** 
    READ_COORDINATES:
        ' PORTA.0 (AN0) -> X+
        ' PORTA.1 (AN1) -> X-
        ' PORTA.2 (AN2) -> Y+
        ' PORTA.3 (AN3) -> Y-
    
        '################ READ AVERAGE X-VALUE ################
    
        TRISA = %00000011                   ' Set X+ (portA.0, AN0) and X- (portA.1, AN1) as inputs 
                                            ' and Y+ (portA.2, AN2) and Y- (portA.3, AN3) as outputs 
    
        low PORTA.3                         ' Set Y- = 0V    
        high PORTA.2                        ' Set Y+ = 5V      
        ADCON0 = %00000001                  ' Bits(5-2): 0000=AN0. Start sampling at X+    
        pauseus 10        
        ADCON0.1 = 1                        ' Stops or continues sampling depending on ADCON2 bits(5-3), 
                                            ' then begins conversion         
        GOSUB CONVERSION_ROUTINE            ' Obtain value for A/D conversion resolution  
        X_VALUE = RESOLUTION                ' Obtain X_VALUE from X+ sampling, Y- = 0V, and Y+ = 5V  
      
        ADCON0 = %00000101                  ' Bits(5-2): 0001=AN1. Start sampling at X-    
        pauseus 10        
        ADCON0.1 = 1                        ' Stops or continues sampling depending on ADCON2 bits(5-3), 
                                            ' then begins conversion          
        GOSUB CONVERSION_ROUTINE            ' Obtain value for A/D conversion resolution   
        X_VALUE = (X_VALUE + RESOLUTION)      ' Obtain X_VALUE from X- sampling, Y- = 0V, and Y+ = 5V  
        
        '################ READ AVERAGE Y-VALUE ################    
    
        TRISA = %00001100                   ' Set X+ (portA.0, AN0) and X- (portA.1, AN1) as outputs 
                                            ' and Y+ (portA.2, AN2) and Y- (portA.3, AN3) as inputs 
    
        low PORTA.1                         ' Set X- = 0V    
        high PORTA.0                        ' Set X+ = 5V      
        ADCON0 = %00001001                  ' Bits(5-2): 0010=AN2. Start sampling at Y+    
        pauseus 10        
        ADCON0.1 = 1                        ' Stops or continues sampling depending on ADCON2 bits(5-3), 
                                            ' then begins conversion         
        GOSUB CONVERSION_ROUTINE            ' Obtain value for A/D conversion resolution
        Y_VALUE = RESOLUTION                ' Obtain Y_VALUE from Y+ sampling, X- = 0V, and X+ = 5V    
      
        ADCON0 = %00001101                  ' Bits(5-2): 0011=AN3. Start sampling at Y-    
        pauseus 10        
        ADCON0.1 = 1                        ' Stops or continues sampling depending on ADCON2 bits(5-3), 
                                            ' then begins conversion         
        GOSUB CONVERSION_ROUTINE            ' Obtain value for A/D conversion resolution
        Y_VALUE = (Y_VALUE + RESOLUTION)      ' Obtain Y_VALUE from Y- sampling, X- = 0V, and X+ = 5V 
       
    
    RETURN
    
    '****************************************************************
    '*         CONVERSION SUBROUTINE                                *
    '**************************************************************** 
    CONVERSION_ROUTINE:
        REPEAT          ' Wait until conversion is finished. When finished ADCON0.1 will be =0        
            PAUSEUS 10
            CONV_STATUS = ADCON0.1    
        UNTIL CONV_STATUS = 0
        
        RESOLUTION.BYTE0 = ADRESL : RESOLUTION.BYTE1 = ADRESH       ' READ A/D CONVERSION VALUE
    
    RETURN
    
    
    '****************************************************************
    '*         CALIBRATION SUBROUTINE                               *
    '**************************************************************** 
    CALIBRATE_TOUCHSCREEN:
    
        IF X_VALUE < 250 THEN 
            X_VALUE = 0
        ELSE
            X_VALUE = (X_VALUE - 250) * 22
        ENDIF
        
        IF Y_VALUE < 250 THEN 
            Y_VALUE = 0
        ELSE
            Y_VALUE = (Y_VALUE - 250) * 25
        ENDIF    
    
        IF X_VALUE > 32750 THEN X_VALUE = 32750
        IF Y_VALUE > 32750 THEN Y_VALUE = 32750
        
        X_VALUE = ABS (X_VALUE - 32750)    
        'Y_VALUE = ABS (Y_VALUE - 32750)
    
    RETURN
    
    
    
    end
    Robert

  8. #8
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire resistive touch screen, Need help

    Thanks a lot. I am sorry for not replying upto now, I just got my touch screen today (4wire), will study the whole code tonight and update the progress in couple of days. Thanks again for the code.

  9. #9
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire resistive touch screen, Need help

    Okkkk, I have read the code and tried to digest it. Few questions:
    1) Can you please explain how is "Start reading average pressure value" routine is working. Upto now I have only encountered putting 5v on y+ or x+ and corresponding y- or x- to be 0v. What is 5v @ y+ and 0v and x- doing?
    2) Any ideas on how to change the circuit to add an interrupt on RA2 when touchscreen is pressed, unlike monitoring it continuesly?
    3) Please explain the calibrate routine, this is the hardest bit of the code which I am failing to understand.
    Many Thanks

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts