Positron Compiler Documentation

Touch_Read

Positron16 · Revision 1.1.3.5 · PDF pages 292–293

Assignment Variable = Touch_Read

Get the X and Y pixel coordinates from the graphic LCD's resistive touch membrane.

None Assignment Variable can be any valid variable type and holds 1 if the touch screen membrane has been touched within its bounds. Two variables are loaded with the X and Y pixel coordinates. These are: Touch_Xpos holds the X position of the touch (0 to 239) Touch_Ypos holds the Y position of the touch (0 to 319)

' Demonstrate the Touch_Read command
'
  Device = 24HJ128GP502               ' Select the device to compile for
  Declare Xtal = 79.23
'
' 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

' Configure the internal oscillator to operate the device at 79.23MHz
'
  PLL_Setup(43, 2, 2, $0300)
  Do
     If Touch_Active = 1 Then          ' Has the LCD been touched?
       If Touch_Read = 1 Then         ' Is the touch within bounds?
          HRSOut "X Touch = ", Dec Touch_Xpos, 13
          HRSOut "Y Touch = ", Dec Touch_Ypos, 13
          DelayMs 200
       EndIf
     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
View original PDF page 292Open page in PDFOriginal PDF page 292

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.

See Also. Touch_Active, Touch_HotSpot

View original PDF page 293Open page in PDFOriginal PDF page 293