實驗目的:

1.瞭解觸摸屏基本概念與原理。

2.理解觸摸屏與LCD 的密切配合。

3.編程實現對觸摸屏的控制。

本次實驗編寫一個觸摸屏中斷程式和一個應用程式,兩程式通過消息佇列通訊.

每次按下觸摸屏,觸摸屏每次中斷發送一個消息給應用程式,應用程式每接受到

一個消息,應用程式在LCD上顯示按下的座標.

 

#include    "../ucos-ii/includes.h"               /* uC/OS interface */

#include "../common/msg.h"

 

#include "../target/option.h"

#include "../target/2410lib.h"

 

#include "../drv/driver.h"

 

#include"Keyb_ps2.c"

 

//task stack size

#ifdef SEMIHOSTED

    #define TASK_STACK_SIZE (64+SEMIHOSTED_STACK_NEEDS)

#else

    #define     TASK_STACK_SIZE 10*1024

#endif

 

 

//LCD task QUEUE

OS_EVENT *pLcdTask_MsgQueue=0;

#define LCDTASK_MSG_QUEUE_SIZE (256*4*5)

void    *paLCD_MsgQueueTbl[LCDTASK_MSG_QUEUE_SIZE];

 

 

 

OS_STK Uart_Stack[TASK_STACK_SIZE];

extern void Uart_Task(void *Id);

#define UART_PRIO 18

OS_EVENT    *pUart_MsgQueue=0;

#define Uart_MSG_QUEUE_SIZE (256 )

void    *paUart_MsgQueueTbl[Uart_MSG_QUEUE_SIZE];

 

 

//Main Task

OS_STK Main_Stack[TASK_STACK_SIZE]= {0, };

extern void Main_Task(void *Id);

#define Main_PRIO       8

 

 

//Lcd Task

OS_STK LcdTask_Stack[TASK_STACK_SIZE]= {0, };

extern void Lcd_Task(void *Id);

#define LcdTask_PRIO       19

 

 

 

//Task1

OS_STK Task1_Stack[TASK_STACK_SIZE]= {0, };

extern void Task1_Task(void *Id);

#define Task1_PRIO       20

 

//Task2

OS_STK Task2_Stack[TASK_STACK_SIZE]= {0, };

extern void Task2_Task(void *Id);

#define Task2_PRIO       21

 

//Task3

OS_STK Task3_Stack[TASK_STACK_SIZE]= {0, };

extern void Task3_Task(void *Id);

#define Task3_PRIO       22

//Task definition

//Can task

 

extern void SM_Init(void);

 

void Task1_Task(void *Id)

{

    int i;

    while(1)

    {

        i++;

        OSTimeDly(10);

    }

}

void Task2_Task(void *Id)

{

    int i;

    while(1)

    {

        i++;

        OSTimeDly(20);

    }

}

void Task3_Task(void *Id)

{

    int i;

    while(1)

    {

        i++;

        OSTimeDly(30);

    }

}

 

static INT32U ulRectWidth =18*8;

static INT32U ulRectHeight =16;

void Lcd_DispTouchPos(INT32U x, INT32U y)

{

    static INT32U ulPrevX = 0;

    static INT32U ulPrevY = 0;

    static INT8U  first=1;

    INT32U ulX,ulY,ulWidth,ulHeight;

    INT8U ch;

    if(first!=1)

    Lcd_FillRect(ulPrevX,ulPrevY,ulPrevX+ulRectWidth,ulPrevY+ulRectHeight,BLUE);

    else

        first=0;

    ulX = x;

    ulY = y;

    if( ulX+ulRectWidth >= LCD_XSIZE_TFT)

        ulX = ulX - ulRectWidth;

    else

        ulX = ulX;

 

    if( ulY + ulRectHeight >= LCD_YSIZE_TFT )

        ulY = ulY - ulRectHeight;

    else

        ulY = ulY;

   

    Lcd_Printf(ulX,ulY,WHITE,"(X = %3d, Y = %3d)",x,y);

    ulPrevX = ulX;

    ulPrevY = ulY;

}

void Lcd_Task(void *Id)

{

    INT8U err;

    void *pMsg;

    PSTRU_TOUCH_MSG pStru_TouchMsg;

    INT32U x,y;

    INT8U ch;

    Lcd_Clr(BLUE);

    //ShowCanBanner();

    //ShowTitle();

    while(1)

    {

        pMsg = (void *)OSQPend(pLcdTask_MsgQueue,0,&err);

        pStru_TouchMsg = (PSTRU_TOUCH_MSG)pMsg;

        if( MSG_TYPE_TOUCH == pStru_TouchMsg->ulType )

        {

           

            x = pStru_TouchMsg->ulPara1;

            y = pStru_TouchMsg->ulPara2;

           

                Lcd_DispTouchPos(x,y);

        }

       

        if( MSG_TYPE_REC_CHAR == pStru_TouchMsg->ulType )

        {

            ch=pStru_TouchMsg->ulPara1;

            ShowChar(ch);

        }

    }

}

STRU_TOUCH_MSG  StruMsg_Uart;

void Uart_Task(void *Id)

{

//  static INT32U ulTimes = 0;

    INT8U err;

    void *pMsg;

    int ix=0;

    int presscode;

    char c;

    STRU_UART_MSG* pUartMsg;

    int nindex=0;

    int twice=0;

    while(1)

 

    {

        pMsg = OSQPend(pUart_MsgQueue, 0, &err);

        pUartMsg=(STRU_UART_MSG*)pMsg;

        presscode=pUartMsg->ulPara1;

 

        c=handle_rawcode(presscode);

        if(c==K_NONE)

            continue;

        if(twice==0)

            {

                twice++;

                continue;

            }

        c=ps2kbd_sysrq_xlate[c];

        if(c=='\r')

            c='\n';

        AddToPs2Buffer(c);

    /*  Uart_Printf("%c",c);

        Uart_Printf("\n");

        */

        twice=0;

 

   

        StruMsg_Uart.ulType=MSG_TYPE_REC_CHAR;

        StruMsg_Uart.ulPara1=c;

        OSQPost(pLcdTask_MsgQueue, (void*)(&StruMsg_Uart));

        }

 

}

 

void Main_Task(void *Id)

{

    //OSStatInit();

    /* Start the S3C44B0X BSP Running */

    ARMTargetStart();

 

    OSTaskCreate(Task1_Task, (void *)0, (OS_STK *)&Task1_Stack[TASK_STACK_SIZE-1],  Task1_PRIO);

    OSTaskCreate(Task2_Task, (void *)0, (OS_STK *)&Task2_Stack[TASK_STACK_SIZE-1],  Task2_PRIO);

    OSTaskCreate(Task3_Task, (void *)0, (OS_STK *)&Task3_Stack[TASK_STACK_SIZE-1],  Task3_PRIO);

 

    while (1)

    {

        OSTimeDly(40);

    }

}  

//===================================================================

void Main(void)

    Led_Display(15);

   

//    MMU_Init();

  

#if ADS10 

    __rt_lib_init();                //for ADS 1.x

#endif

 

    ChangeClockDivider(1,1);          // 1:2:4

    ChangeMPllValue(0xa1,0x3,0x1);    // FCLK=202.8MHz

   

    ARMTargetInit();

   

    // Init uCOS-II

    OSInit();

     pUart_MsgQueue = OSQCreate(&paUart_MsgQueueTbl[0], Uart_MSG_QUEUE_SIZE);

 

    pLcdTask_MsgQueue = OSQCreate(&paLCD_MsgQueueTbl[0],LCDTASK_MSG_QUEUE_SIZE);

       

  

 

 

    //Create the Main Task

  //  OSTaskCreate(Main_Task, (void *)0, (OS_STK *)&Main_Stack[TASK_STACK_SIZE-1],  Main_PRIO);

        //Create the Task

   

   

    OSTaskCreate(Uart_Task, (void *)0, (OS_STK *)&Uart_Stack[TASK_STACK_SIZE-1],      UART_PRIO);

 

    OSTaskCreate(Lcd_Task,(void *)0, (OS_STK *)&LcdTask_Stack[TASK_STACK_SIZE-1], LcdTask_PRIO);

 

 

   

   

    // Start uCOS-II

    OSStart();

 

 

}

 

void PrintfBanner()

{

    Uart_Printf("(1)Start   CAN1    Send\n");

    Uart_Printf("(2)Stop    CAN1    Send\n");

    Uart_Printf("(3)Start   CAN2    Send\n");

    Uart_Printf("(4)Stop    CAN2    Send\n");

}