⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bsp_touchscr.c

📁 lpc2478+ucosII+ucgui源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*                                              uC/OS-II
*                                        The Real-Time Kernel
*
*                          (c) Copyright 2004-2008; Micrium, Inc.; Weston, FL               
*
*               All rights reserved.  Protected by international copyright laws.
*
*               uC/OS-II is provided in source form for FREE evaluation, for educational
*               use or peaceful research.  If you plan on using uC/OS-II in a commercial    
*               product you need to contact Micrium to properly license its use in your     
*               product.  We provide ALL the source code for your convenience and to        
*               help you experience uC/OS-II.  The fact that the source code is provided
*               does NOT mean that you can use it without paying a licensing fee.
*
*               Knowledge of the source code may NOT be used to develop a similar product.
*
*               Please help us continue to provide the Embedded community with the finest
*               software available.  Your honesty is greatly appreciated.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                 BOARD SUPPORT PACKAGE (LCD TOUCH SCREEN)
*
*                                             NXP LPC2478
*                                                on the
*                                      IAR LPC2478 SK Kickstart Kit
*
* Filename      : bsp_touchscr.c
* Version       : V1.00
* Programmer(s) : FT
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                             INCLUDE FILES
*********************************************************************************************************
*/

#define  BSP_TOUCH_SCR_MODULE
#include <includes.h>


/*
*********************************************************************************************************
*                                            LOCAL DEFINES
*********************************************************************************************************
*/
                                                                          /* ------------- IODIR REGISTER BIT DEFINES------- */
#define  BSP_TOUCH_SCR_IO0DIR_X1               DEF_BIT_24
#define  BSP_TOUCH_SCR_IO0DIR_X2               DEF_BIT_21             //原来是p022
#define  BSP_TOUCH_SCR_IO0DIR_X_GRP            BSP_TOUCH_SCR_IO0DIR_X1 | \
                                               BSP_TOUCH_SCR_IO0DIR_X2

#define  BSP_TOUCH_SCR_IO0DIR_Y1               DEF_BIT_25          //原来的是p023 p021
#define  BSP_TOUCH_SCR_IO0DIR_Y2               DEF_BIT_26
#define  BSP_TOUCH_SCR_IO0DIR_Y_GRP            BSP_TOUCH_SCR_IO0DIR_Y1 | \
                                               BSP_TOUCH_SCR_IO0DIR_Y2
                                                                          /* ----------- PINSEL REGISTER BIT DEFINES ------- */
#define  BSP_TOUCH_SCR_PINSEL1_X1_ADC          DEF_BIT_16                 /* PINSEL[17:16] = '01' = AD0[1]                   */
#define  BSP_TOUCH_SCR_PINSEL1_X1_MASK        (DEF_BIT_17 | DEF_BIT_16)   /* Bits 16 and 17 define  P0.24 function           */
#define  BSP_TOUCH_SCR_PINSEL1_X2_MASK      (DEF_BIT_11 | DEF_BIT_10)   //(DEF_BIT_13 | DEF_BIT_12)  修改了--- /* Bits 12 abd 13 define  P0.22 function           */                                              
                                                  
#define  BSP_TOUCH_SCR_PINMODE1_X2_PULL_DOWN (DEF_BIT_11 | DEF_BIT_10)  // ----修改了(DEF_BIT_13 | DEF_BIT_12)   /* PINMODE[13:12] = '11' Pull-Down resistor enable */
#define  BSP_TOUCH_SCR_PINMODE1_X1_MASK       (DEF_BIT_17 | DEF_BIT_16)   /* Bits 17 and 16 define P0.24 mode                */
#define  BSP_TOUCH_SCR_PINMODE1_X2_MASK       (DEF_BIT_11 | DEF_BIT_10)   //(DEF_BIT_13 | DEF_BIT_12)   修改了  /* Bits 12 and 10 define P0.22 mode                */

#define  BSP_TOUCH_SCR_PINSEL1_Y1_ADC              DEF_BIT_18                     //  DEF_BIT_14  修改了               /* PINSEL[15:14] = '01' = AD0[0]        修改了           */
#define  BSP_TOUCH_SCR_PINSEL1_Y1_MASK     (DEF_BIT_19 | DEF_BIT_18)  // (DEF_BIT_15 | DEF_BIT_14)  --- 修改了 /* Bits 14 and 15 define   P0.23 function          */
#define  BSP_TOUCH_SCR_PINSEL1_Y2_MASK      (DEF_BIT_21 | DEF_BIT_20)   //  (DEF_BIT_11 | DEF_BIT_10) ---修改了  /* Bits 10 and 11 define   P0.21 function          */
                                                  
#define  BSP_TOUCH_SCR_PINMODE1_Y2_PULL_DOWN  (DEF_BIT_21 | DEF_BIT_20)//(DEF_BIT_11 | DEF_BIT_10) ----修改了  /* PINMODE[11:10] = '11' Pull-down resistor enable */
#define  BSP_TOUCH_SCR_PINMODE1_Y1_PULL_DOWN  (DEF_BIT_19 | DEF_BIT_18) //(DEF_BIT_15 | DEF_BIT_14) ----修改了  /* PINMODE[11:10] = '11' Pull-down resistor enable */
#define  BSP_TOUCH_SCR_PINMODE1_Y1_MASK      (DEF_BIT_19 | DEF_BIT_18)  //(DEF_BIT_15 | DEF_BIT_14) 修改了  /* bits 14 and 15 define   P0.23 mode              */
#define  BSP_TOUCH_SCR_PINMODE1_Y2_MASK        (DEF_BIT_21 | DEF_BIT_20)//(DEF_BIT_11 | DEF_BIT_10)  修改了 /* bits 10 and 11 define   P0.21 mode              */

                                                                          /* ------------- TOCUH SCREEN CONSTANTS  --------- */
#define  BSP_TOUCH_SCR_NBR_SAMPLES                     32                 /* Number of samples for Touch screen measurements */
#define  BSP_TOUCH_SCR_SETUP_DLY_uS                   100                 /* Setup delay (us) for I/O pins                   */
#define  BSP_TOUCH_SCR_ADC_DLY_uS                       3                 /* convertion time (ns) for ADC ADC_clk = 4.5 Mhz  */
#define  BSP_TOUCH_SCR_DFLT_DLY_uS                    200                 /* Maximum delay in case the Timer #2 is stopped...*/
                                                                          /* ...in the application.                          */

#define  BSP_TOUCH_SCR_H_SIZE                         320                 /* LCD Display Horizontal size in pixels           */
#define  BSP_TOUCH_SCR_V_SIZE                         240                 /* LCD Display Vertical   size in pixels           */
 
#define  BSP_TOUCH_SCR_MIN_X_ADC                    0x065
#define  BSP_TOUCH_SCR_MAX_X_ADC                    0x385
#define  BSP_TOUCH_SCR_MAX_Y_ADC                    0x35C
#define  BSP_TOUCH_SCR_MIN_Y_ADC                    0x07F

#define  BSP_TOUCH_SCR_DELTA_X_ADC             BSP_TOUCH_SCR_MAX_X_ADC - BSP_TOUCH_SCR_MIN_X_ADC
#define  BSP_TOUCH_SCR_DELTA_Y_ADC             BSP_TOUCH_SCR_MAX_Y_ADC - BSP_TOUCH_SCR_MIN_Y_ADC

/*
*********************************************************************************************************
*                                          LOCAL DATA TYPES
*********************************************************************************************************
*/

//extern  FontType_t            Terminal_9_12_6;
/*
*********************************************************************************************************
*                                            LOCAL TABLES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                       LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                      LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/

static void  BSP_TouchScr_Dly_uS    (CPU_INT32U  us);
static void  BSP_TouchScr_IO_Init   (void);

/*
*********************************************************************************************************
*                                     LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*********************************************************************************************************
**                                         GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                             BSP_TouchScr_Init()
*
* Description : Initialize the Touch Screen I/O.
*               
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : Application
*
* Note(s)     : none.
*********************************************************************************************************
*/

void  BSP_TouchScr_Init (void)
{
    BSP_TouchScr_IO_Init(); 

    PCONP |=  DEF_BIT_23;    
}



/*
*********************************************************************************************************
*                                            BSP_TouchScr_MeasureX()
*
* Description : Measure the X coordinate of the Touch Screen.
*               Touch Screen Hardware on the LPC2478-SK
*
*                                     (Y2) P0.21
*                                      |
*                            +---------|----------+
*                            |         |          |
*                            |      +==|==+       |
*                            |      |     |       |     
*                            |  +===============+ |       
*              P0.22  (X2)<--|--|      R1       |-|-->(X1) P0.24/AD[1]
*                            |  +===============+ |       
*                            |      | R2  |       |       
*                            |      |     |       |       
*                            |      +==|==+       |       
*                            +=========|==========+     
*                                      |
*                                     (Y1) P0.23/AD[0]
*              (1) Set X1 and X2 as pull-up outputs and Y2 as pull-down input and Y1 as ADC channel 0.
*              (2) If X2 is LOW the Touch screen is not being pressed go to step 5.
*              (3) Measure ADC Channel 1 input BSP_TOUCH_SCR_NBR_SAMPLES times.
*              (4) Average the result and return the data.
*              (5) Set Y1, Y2, X1, X2 as inputs with pull-up resistor.
*  
* Argument(s) : p_status  Pointer to the BSP_TOUCH_SCR_STATUS structure.                   
*
* Return(s)   : none.
*
* Caller(s)   : Application
*               
* Note(s)     : none.
*********************************************************************************************************
*/

void  BSP_TouchScr_MeasureX (BSP_TOUCH_SCR_STATUS  *p_status)
{
    CPU_INT32U   adc_acc;
    CPU_INT32U   i;
    
    
    IO0DIR   |= BSP_TOUCH_SCR_IO0DIR_X_GRP;                      /* Configure X1 and X2 as outputs                             */
    IO0SET    = BSP_TOUCH_SCR_IO0DIR_X_GRP;                      /* Set X1 and X2 to '1'                                       */
    PINMODE1 |= BSP_TOUCH_SCR_PINMODE1_Y2_PULL_DOWN;             /* Configure Y2 with a Pull-Down resistor                     */     
    PINSEL1  |= BSP_TOUCH_SCR_PINSEL1_Y1_ADC;                    /* Select Y1 as ADC channel 1                                 */    

    BSP_TouchScr_Dly_uS(BSP_TOUCH_SCR_SETUP_DLY_uS); 
    
    if (DEF_BIT_IS_CLR(IO0PIN, BSP_TOUCH_SCR_IO0DIR_Y2)) {       /* If Y2 is LOW the Touch Screen is not being pressed         */
        p_status->TouchScrIsPressed = DEF_FALSE;
    } else {                                                     /* If Y2 is HIGH the Touch Screen is being pressed            */
        IO0CLR  = BSP_TOUCH_SCR_IO0DIR_X2;                       /* Reset X2 to '0' so current will drain between X1->X2       */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -