/*************************************************************** ADS7843 Touch Screen Controller Driver Tested on PIC32MX795F512L MPLAB C32 Written by Gobbledok This is a simple driver to use for a PIC32 and could easily be adapted to other PICs. Resources: Spare SPI Channel 6 I/O Pins: CLK DIN DOUT CS Busy PenIRQ Easy to use. Simply call 'Touch_Init()' during startup to set up I/O pins and SPI. To read the coordinates call 'ReadTouchXY()' The current coordinates are placed into: for the X channel: Touch_Buffer[0][Touch_Counter] for the Y channel: Touch_Buffer[1][Touch_Counter] You should call ReadTouchXY() regularly to check for a touch. 100Hz is practical (but probably overkill) but you can call it faster or slower if you wish. If there is no touch detected (i.e PenIRQ == 0) then the buffers are filled with 0's. Touch_Counter is a FIFO buffer. The buffer contents should be averaged when it is full. You should calibrate your own screen and place the values below. ***************************************************************/ // These are measured calibration values // Place your own measured calibration values here #define Xmin 320 #define Xmax 3744 #define Ymin 352 #define Ymax 3792 #define Xrange 0.093458 // =(num of x pixels/(Xmax-Xmin)) #define Yrange 0.069768 // =(num of y pixels/(Ymax-Ymin)) // #define Touch_PenIRQ !PORTBbits.RB0 #define Touch_PenIRQ_TRIS TRISBbits.TRISB0 #define Touch_PenIRQ_LAT LATBbits.LATB0 #define Touch_CS PORTGbits.RG12 #define Touch_CS_TRIS TRISGbits.TRISG12 #define Touch_Busy PORTGbits.RG13 #define Touch_Busy_TRIS TRISGbits.TRISG13 #define SpiChn SPI_CHANNEL2 unsigned short Touch_Buffer[2][30]; void Touch_Init(void); // Initialises the touch screen void ReadTouchXY(void); // Reads the touch screen and returns the coordinates void TDelay(void); // 200ns delay used to read and write to the touch chip BOOL UpdateTouchScreen; int Touch_Counter;