Positron Compiler Documentation

Touch_Active

Source: Positron16 Compiler User Manual, PDF page 290

Syntax

Assignment Variable = Touch_Active

Overview

Indicates if the graphic LCD's resistive touch membrane has been touched.

Parameters

None Assignment Variable can be any valid variable type and holds 1 if the touch screen membrane has been touched with sufficient force.

Example

' Demonstrate the Touch_Active command
'
  Device = 24HJ128GP502
                                     ' Select the device to compile for
  Declare Xtal = 79.23
  Declare Hserial_Baud = 9600
                                     ' USART1 Baud rate
  Declare Hrsout1_Pin = PORTB.14
                                     ' Select the pin used for TX with USART1
'
' Setup the ADS7846 touch screen chip's pins
'
  Declare Touch_DINPin = PORTB.13  ' Connect to the ADS7846 DIN pin
  Declare Touch_DOUTPin = PORTB.12 ' Connect to the ADS7846 DOUT pin
  Declare Touch_CLKPin = PORTB.11  ' Connect to the ADS7846 CLK pin
  Declare Touch_CSPin = PORTB.9
                                     ' Connect to the ADS7846 CS pin
  Include "TouchScreen.inc" ' Load the touch screen routines into the program
'--------------------------------------------------------------------------
Main:
' Configure the internal oscillator to operate the device at 79.23MHz
'
  PLL_Setup(43, 2, 2, $0300)
  RPOR7 = 3
                                     ' Make Pin RP14 U1TX
  Do
     If Touch_Active = 1 Then
                                     ' Has the LCD been touched?
       HRSOut "LCD is Touched\r"
                                     ' Yes. So transmit a message serially
       DelayMs 200
     EndIf
  Loop
'--------------------------------------------------------------------------
' Configure for internal 7.37MHz oscillator with PLL
' OSC pins are general purpose I/O
'
  Config FBS = BWRP_WRPROTECT_OFF, BSS_NO_FLASH, BSS_NO_BOOT_CODE
  Config FSS = SWRP_WRPROTECT_OFF, SSS_NO_FLASH, RSS_NO_SEC_RAM
  Config FGS = GWRP_OFF, GCP_OFF
  Config FOSCSEL = FNOSC_FRCPLL, IESO_ON
  Config FOSC = POSCMD_NONE, OSCIOFNC_ON, IOL1WAY_OFF, FCKSM_CSDCMD
  Config FWDT = WDTPOST_PS256, WINDIS_OFF, FWDTEN_OFF
  Config FPOR = FPWRT_PWR128, ALTI2C_OFF
  Config FICD = ICS_PGD1, JTAGEN_OFF

RF filter +3v3 100nF 10uF/6.3v

VCC VCC 10KΩ CS Vref SCK DIN RB9 RB11 RB13 DOUT PENIRQ RB12 BUSY X- From LCD YU X+ Y+ Vbat AUX Y- From LCD XR From LCD YD From LCD XL GND ADS7846

ADS7846 Touch controller circuit

Notes.

The touch screen commands used by the compiler are for use with an ADS7846 touch screen controller device. This device uses an SPI interface and connects to a 4-wire resistive touch screen membrane to give X and Y coordinates, as well as touch pressure.

The routines must be incorporated into the BASIC program by use of an include file named "TouchScreen.inc". This is written in Positron16 BASIC so that modifications or improvements are easy. It also exposes how the touch screen is interfaced with.

A suitable circuit for the ADS7846 touch screen controller is shown below:

See Also. Touch_Read, Touch_HotSpot