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