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

📄 test.c

📁 常用外围接口的程序设计
💻 C
📖 第 1 页 / 共 2 页
字号:
    PC_DispStr( 0, 17, "                                                                                ", DISP_FGND_WHITE);
    PC_DispStr( 0, 18, "0x50                                       0xD0                                 ", DISP_FGND_WHITE);
    PC_DispStr( 0, 19, "                                                                                ", DISP_FGND_WHITE);
    PC_DispStr( 0, 20, "0x60                                       0xE0                                 ", DISP_FGND_WHITE);
    PC_DispStr( 0, 21, "                                                                                                                                                                ", DISP_FGND_WHITE);
    PC_DispStr( 0, 22, "0x70                                       0xF0                                                                                                                 ", DISP_FGND_WHITE);
    PC_DispStr( 0, 23, "                                                                                ", DISP_FGND_WHITE);
    PC_DispStr( 0, 24, "                            <PRESS ANY KEY TO QUIT>                             ", DISP_FGND_YELLOW + DISP_BGND_BLUE + DISP_BLINK);
    for (y = 0; y < 8; y++) {
        for (x = 0; x < 16; x++) {
            PC_DispChar(x * 2 + 5, y * 2 + 8, y * 16 + x, DISP_FGND_YELLOW + DISP_BGND_BLUE);
        }
    }
    for (y = 8; y < 16; y++) {
        for (x = 0; x < 16; x++) {
            PC_DispChar(x * 2 + 48, (y - 8) * 2 + 8, y * 16 + x, DISP_FGND_YELLOW + DISP_BGND_BLUE);
        }
    }
    while (PC_GetKey(&key) == FALSE) {
        ;
    }
    PC_DispClrScr(DISP_FGND_WHITE);
}

/*$PAGE*/    
/*
*********************************************************************************************************
*                                   EMBEDDED SYSTEMS BUILDING BLOCKS
*                                         Modules Initialization
*********************************************************************************************************
*/

static  void  TestInitModules (void)
{
    PC_ElapsedInit();

#if MODULE_KEY_MN
    KeyInit();                                             /* Initialize the keyboard scanning module  */
#endif

#if MODULE_LED
    DispInit();                                            /* Initialize the LED module                */
#endif

#if MODULE_LCD
    DispInit(4, 20);                                       /* Initialize the LCD module (4 x 20 disp.) */
#endif

#if MODULE_CLK
    ClkInit();                                             /* Initialize the clock/calendar module     */
#endif

#if MODULE_TMR
    TmrInit();                                             /* Initialize the timer manager module      */
#endif

#if MODULE_DIO
    DIOInit();                                             /* Initialize the discrete I/O module       */
#endif

#if MODULE_AIO
    AIOInit();                                             /* Initialize the analog I/O module         */
#endif

#if MODULE_COMM_BGND
    CommInit();                                            /* Initialize the buffered serial I/O module*/
#endif

#if MODULE_COMM_RTOS
    CommInit();                                            /* Initialize the buffered serial I/O module*/
#endif

#if MODULE_COMM_PC
    CommCfgPort(COMM1, 9600, 8, COMM_PARITY_NONE, 1);      /* Initialize COM1 on the PC                */
    CommSetIntVect(COMM1);                                 /* Install the interrupt vector             */
    CommRxIntEn(COMM1);                                    /* Enable Rx interrupts                     */
#endif
}
/*$PAGE*/
/*
*********************************************************************************************************
*                             TEST 'Asynchronous Serial Communication' TASK
*                                         DATA RECEPTION TASK
*********************************************************************************************************
*/

void  TestRxTask (void *data)
{
    INT8U  err;
    INT8U  nbytes;
    INT8U  c;
    char   s[81];
    char  *ps;
    
    
    data   = data;                                                   /* Prevent compiler warning       */
    for (;;) {
        ps     = s;
        nbytes = 0;
        do {
            c     = CommGetChar(COMM1, OS_TICKS_PER_SEC, &err);
            *ps++ = c;
            nbytes++;
        } while (c != '\n' && nbytes < 20);
        *ps = NUL;                                                   /* NUL terminate received string  */
        PC_DispStr(49, 17, s, DISP_FGND_YELLOW + DISP_BGND_BLUE);
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                            STATISTICS TASK
*
* Note(s) : 1) This function calls TestInitModules() which is used to initialize all the building blocks
*              used in this sample code.  Note that some of the building blocks actually create tasks
*              and thus require that you assign priorities.  All priorities of tasks are assigned in 
*              CFG.H.
*********************************************************************************************************
*/

void  TestStatTask (void *pdata)
{
    INT8U   i;
    INT16S  key;
    char    s[81];


    pdata = pdata;                                         /* Prevent compiler warning                 */


    OS_ENTER_CRITICAL();
    PC_VectSet(0x08, OSTickISR);                           /* Install uC/OS-II's clock tick ISR        */
    PC_SetTickRate(OS_TICKS_PER_SEC);                      /* Reprogram tick rate                      */
    OS_EXIT_CRITICAL();

    PC_DispStr(0, 22, "Determining  CPU's capacity ...", DISP_FGND_WHITE);
    OSStatInit();                                          /* Initialize uC/OS-II's statistics         */
    PC_DispClrRow(22, DISP_FGND_WHITE + DISP_BGND_BLACK);

    TestInitModules();                                     /* Initialize all building blocks used ...  */
                                                           /* ... including their tasks.               */

                                                           /* Create application tasks                 */
    OSTaskCreateExt(TestClkTask, 
                   (void *)0, 
                   &TestClkTaskStk[TASK_STK_SIZE], 
                   TEST_CLK_TASK_PRIO,
                   TEST_CLK_TASK_PRIO,  
                   &TestClkTaskStk[0],  
                   TASK_STK_SIZE,  
                   (void *)0,  
                   OS_TASK_OPT_SAVE_FP);
    OSTaskCreateExt(TestRxTask, 
                   (void *)0, 
                   &TestRxTaskStk[TASK_STK_SIZE], 
                   TEST_RX_TASK_PRIO,
                   TEST_RX_TASK_PRIO,  
                   &TestRxTaskStk[0],  
                   TASK_STK_SIZE,  
                   (void *)0,  
                   OS_TASK_OPT_SAVE_FP);
    OSTaskCreateExt(TestTxTask, 
                   (void *)0, 
                   &TestTxTaskStk[TASK_STK_SIZE], 
                   TEST_TX_TASK_PRIO,
                   TEST_TX_TASK_PRIO,  
                   &TestTxTaskStk[0],  
                   TASK_STK_SIZE,  
                   (void *)0,  
                   OS_TASK_OPT_SAVE_FP);
    OSTaskCreateExt(TestTmrTask,         
                   (void *)0,  
                   &TestTmrTaskStk[TASK_STK_SIZE],  
                   TEST_TMR_TASK_PRIO,
                   TEST_TMR_TASK_PRIO,            
                   &TestTmrTaskStk[0],  
                   TASK_STK_SIZE,          
                   (void *)0,  
                   OS_TASK_OPT_SAVE_FP);
    OSTaskCreateExt(TestDIOTask,      
                   (void *)0,  
                   &TestDIOTaskStk[TASK_STK_SIZE],  
                   TEST_DIO_TASK_PRIO,
                   TEST_DIO_TASK_PRIO,        
                   &TestDIOTaskStk[0], 
                   TASK_STK_SIZE,        
                   (void *)0, 
                   OS_TASK_OPT_SAVE_FP);
    OSTaskCreateExt(TestAIOTask,  
                   (void *)0,  
                   &TestAIOTaskStk[TASK_STK_SIZE],  
                   TEST_AIO_TASK_PRIO,
                   TEST_AIO_TASK_PRIO,         
                   &TestAIOTaskStk[0], 
                   TASK_STK_SIZE,     
                   (void *)0, 
                   OS_TASK_OPT_SAVE_FP);
                   
    TestDispLit();                                         /* Bring up text on display                  */
    
    sprintf(s, "V%1d.%02d", OSVersion() / 100, OSVersion() % 100);
    PC_DispStr(13, 23, s, DISP_FGND_YELLOW + DISP_BGND_BLUE);
    
    for (;;) {
        sprintf(s, "%5d", OSTaskCtr);                      /* Display #tasks running                    */
        PC_DispStr(30, 23, s, DISP_FGND_BLUE + DISP_BGND_CYAN);

        sprintf(s, "%5d", OSCtxSwCtr);                     /* Display #context switches per second      */
        PC_DispStr(56, 23, s, DISP_FGND_BLUE + DISP_BGND_CYAN);

        sprintf(s, "%3d", OSCPUUsage);                     /* Display CPU usage in %                    */
        PC_DispStr(75, 23, s, DISP_FGND_BLUE + DISP_BGND_CYAN);

        if (PC_GetKey(&key) == TRUE) {                     /* See if key has been pressed              */     
            if (key == 0x1B) {                             /* Yes, see if it's the ESCAPE key          */
#if MODULE_COMM_PC
                CommRclIntVect(COMM1);                     /* Restore the old vector for COMM1         */
#endif
                PC_DOSReturn();                            /* Return to DOS                            */
            }
        }

        OSCtxSwCtr = 0;

        OSTimeDlyHMSM(0, 0, 1, 0);                         /* Wait one second                          */
    }
}
/*$PAGE*/
/*
*********************************************************************************************************
*                               Function executed when Timers Time Out
*********************************************************************************************************
*/

static  void  TestTmr0TO (void *arg)
{
    arg = arg;
    PC_DispStr( 8, 17, "Timer #0 Timed Out!", DISP_FGND_WHITE + DISP_BGND_RED);
}



static  void  TestTmr1TO (void *arg)
{
    arg = arg;
    PC_DispStr( 8, 19, "Timer #1 Timed Out!", DISP_FGND_WHITE + DISP_BGND_RED);
}

/*
*********************************************************************************************************
*                                       TEST 'Timer Manager' TASK
*********************************************************************************************************
*/

void  TestTmrTask (void *data)
{
    char    s[81];
    INT16U  time;


    data = data;                                           /* Prevent compiler warning                 */
    
                                                           /* Setup Timer #0                           */
    TmrCfgFnct(0, TestTmr0TO, (void *)0);                  /* Execute when Timer #0 times out          */
    TmrSetMST(0, 1, 3, 9);                                 /* Set timer #0 to 1 min., 3 sec. 9/10 sec. */
    TmrStart(0);  
                                                           /* Setup Timer #1                           */
    TmrCfgFnct(1, TestTmr1TO, (void *)0);                  /* Execute when Timer #1 times out          */
    TmrSetMST(1, 2, 0, 0);                                 /* Set timer #1 to 2 minutes                */
    TmrStart(1);
    
    for (;;) {
        TmrFormat(0, s);                                   /* Get formatted remaining time for Tmr#0   */
        PC_DispStr( 8, 16, s, DISP_FGND_RED + DISP_BGND_LIGHT_GRAY);
        
        TmrFormat(1, s);                                   /* Get formatted remaining time for Tmr#1   */
        PC_DispStr( 8, 18, s, DISP_FGND_RED + DISP_BGND_LIGHT_GRAY);

        OSTimeDlyHMSM(0, 0, 0, 50);                        /* Run 20 times per second                  */
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                             TEST 'Asynchronous Serial Communication' TASK
*                                       DATA TRANSMISSION TASK
*********************************************************************************************************
*/

void  TestTxTask (void *data)
{
    INT16U  ctr;
    char    s[81];
    char   *ps;
    
    
    data  = data;                                          /* Prevent compiler warning                 */
    ctr   = 0;
    for (;;) {
        sprintf(s, "%05d\n", ctr);        
        PC_DispStr(49, 16, s, DISP_FGND_YELLOW + DISP_BGND_BLUE);
        ps = s;
        while (*ps != NUL) {
            CommPutChar(COMM1, *ps, OS_TICKS_PER_SEC);
            OSTimeDly(5);                                  /* REMOVE if running under DOS 6.xx         */
            ps++;
        }
        ctr++;
    }
}

⌨️ 快捷键说明

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