?? touchscr.c
字號:
//****************************************************************************
//
// TOUCHSCR.C - Uses the SPI ADC to sample the value of the touch screen on
// the EP7312 evaluation board.
//
// Copyright (c) 1998-1999 Cirrus Logic, Inc.
//
//****************************************************************************
#include "lib7312.h"
#include "touchscr.h"
//****************************************************************************
//
// The following arrays contain the value of the samples taken at the four
// corners of the touch screen. They are used for converting the touch
// screen coordinates to LCD screen coordinates.
//
//****************************************************************************
unsigned long ulCornerX[4], ulCornerY[4];
//****************************************************************************
//
// ReadSample reads the X/Y coordinate pair from the touch screen.
//
//****************************************************************************
void
ReadSample(unsigned long *pulX, unsigned long *pulY)
{
unsigned long ulADS7846ctl;
//
// Create the control byte for x channel, differential
//
ulADS7846ctl = ADS7846E_S |
(ADS7846E_ADD_DFR_X << ADS7846E_ADD_SHIFT) |
(ADS7846E_PD_LPWR << ADS7846E_PD_SHIFT);
//
// Get the x position using differential mode.
// The lower 4 bits are padding.
//
*pulX = (ADCGetData(ulADS7846ctl) >> 4);
//
// Create the control byte for y channel
ulADS7846ctl = ADS7846E_S |
(ADS7846E_ADD_DFR_Y << ADS7846E_ADD_SHIFT) |
(ADS7846E_PD_LPWR << ADS7846E_PD_SHIFT);
//
// Get the Y position using differential mode.
// The lower 4 bits are padding.
//
*pulY = (ADCGetData(ulADS7846ctl) >> 4);
}
//****************************************************************************
//
// This program draws circles on the LCD panel at the returned touch location
// from the Burr Brown ADC, ADS7846E, on the EP7312 evaluation board
//
//****************************************************************************
void
entry(void)
{
unsigned long ulXPos, ulYPos;
long lIter;
long lPosX[4] = {0, 312, 312, 0}, lPosY[4] = {0, 0, 232, 232};
CPixel sColor;
char cButtons[6];
int i;
//
// Enable the LCD controller, clear the frame buffer, and turn on the LCD
// panel.
//
LCDColorEnable();
LCDColorCls();
LCDColorOn();
LCDColorBacklightOn();
LCDColorContrastEnable();
//
// Initialze the ADC
//
ADCEnable();
//
// Set the pixel color to white.
//
sColor.r = 15;
sColor.g = 15;
sColor.b = 15;
//
// Set the entire screen to white
//
for(ulYPos = 0; ulYPos < 240; ulYPos++)
{
for(ulXPos = 0; ulXPos < 320; ulXPos++)
{
LCDColorSetPixel(ulXPos, ulYPos, sColor);
}
}
//
// Set the pixel color to green.
//
sColor.r = 0;
sColor.g = 0;
sColor.b = 15;
//
// Tell the user what to do.
//
LCDColorPrintStringX2("Touch the screen", 20, 85, sColor);
LCDColorPrintStringX2("in each box.", 20, 105, sColor);
LCDColorPrintString("This calibrates the touch screen to", 20, 132, sColor);
LCDColorPrintString("the LCD coordinates", 20, 142, sColor);
//
// Read screen touches from the four corners of the screen. This is used
// to calibrate the touch screen to the LCD screen coordinate transformation.
//
for(lIter = 0; lIter < 4; lIter++)
{
//
// Set the pixel color to red.
//
sColor.r = 15;
sColor.g = 0;
sColor.b = 0;
//
// Draw a box in the appropriate corner of the screen
//
LCDColorLine(lPosX[lIter] + 0, lPosY[lIter] + 0,
lPosX[lIter] + 7, lPosY[lIter] + 0, sColor);
LCDColorLine(lPosX[lIter] + 7, lPosY[lIter] + 0,
lPosX[lIter] + 7, lPosY[lIter] + 7, sColor);
LCDColorLine(lPosX[lIter] + 7, lPosY[lIter] + 7,
lPosX[lIter] + 0, lPosY[lIter] + 7, sColor);
LCDColorLine(lPosX[lIter] + 0, lPosY[lIter] + 7,
lPosX[lIter] + 0, lPosY[lIter] + 0, sColor);
//
// Wait until the touch screen has been touched.
//
while(1)
{
//
// Sample the touch screen
//
ReadSample(&ulXPos, &ulYPos);
//
// Stop waiting if a valid sample was read.
//
if(lIter < 2)
{
if(ulYPos > 1436)
{
break;
}
}
else
{
if(ulYPos < 200)
{
break;
}
}
}
//
// Save the sample.
//
ulCornerX[lIter] = ulXPos;
ulCornerY[lIter] = ulYPos;
//
// Fill in the box in the corner of the screen.
//
for(ulXPos = 0; ulXPos < 8; ulXPos++)
{
LCDColorLine(lPosX[lIter] + ulXPos, lPosY[lIter] + 0,
lPosX[lIter] + ulXPos, lPosY[lIter] + 7, sColor);
}
//
// Wait until the screen is not being touched.
//
while(1)
{
//
// Sample the touch screen.
//
ReadSample(&ulXPos, &ulYPos);
//
// Stop waiting if an invalid sample was read.
//
if(lIter < 2)
{
if(ulYPos < 1436)
{
break;
}
}
else
{
if(ulYPos > 150)
{
break;
}
}
}
//
// Set the pixel color to white.
//
sColor.r = 15;
sColor.g = 15;
sColor.b = 15;
//
// Clear the box in the corner of the screen.
//
for(ulXPos = 0; ulXPos < 8; ulXPos++)
{
LCDColorLine(lPosX[lIter] + ulXPos, lPosY[lIter] + 0,
lPosX[lIter] + ulXPos, lPosY[lIter] + 7, sColor);
}
}
//
// Clear the screen to white
//
for(ulYPos = 0; ulYPos < 240; ulYPos++)
{
for(ulXPos = 0; ulXPos < 320; ulXPos++)
{
LCDColorSetPixel(ulXPos, ulYPos, sColor);
}
}
//
// Set the pixel color to red.
//
sColor.r = 15;
sColor.g = 0;
sColor.b = 0;
//
// Give the user some instruction
//
LCDColorPrintStringX2("Touch the screen.", 17, 10, sColor);
LCDColorPrintString("Press a user button on the keypad", 17, 35, sColor);
LCDColorPrintString(" to exit the demo", 17, 45, sColor);
//
// Program loop. The exit condition is within the loop.
//
while (1)
{
//
// Sample the touch screen.
//
ReadSample(&ulXPos, &ulYPos);
//
// Convert the touch screen coordinate to a screen coordinate
//
ulXPos = 320 - ((320 * (ulXPos - ulCornerX[1])) / (ulCornerX[0] - ulCornerX[1]));
ulYPos = 240 - ((240 * (ulYPos - ulCornerY[3])) / (ulCornerY[0] - ulCornerY[3]));
//
// Pixel color is already red. Draw a red circle at the touched position
// with a radius of 10.
//
LCDColorFillCircle(ulXPos, ulYPos, 10, sColor);
//
// Delay for readability
//
for (ulXPos = 0; ulXPos < 0x10000; ulXPos++){}
//
// Check for a user button to be pressed.
//
KPRead(cButtons);
for(i = 0; i < 6; i++)
{
if(cButtons[i])
{
break;
}
}
if(i != 6)
{
break;
}
}
//
// Disable the LCD controller.
//
LCDColorContrastDisable();
LCDColorBacklightOff();
LCDColorOff();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -