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

📄 test.c

📁 常用外围接口的程序设计
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*                                    Embedded Systems Building Blocks
*                                 Complete and Ready-to-Use Modules in C
*
*                            (c) Copyright 1999, Jean J. Labrosse, Weston, FL
*                                           All Rights Reserved
*
* Filename   : TEST.C
* Programmer : Jean J. Labrosse
*********************************************************************************************************
*/

#include "includes.h"

/*
*********************************************************************************************************
*                                             CONSTANTS
*********************************************************************************************************
*/

#define          TASK_STK_SIZE            512    /* Size of each task's stacks (# of 16-bit words)     */

/*
*********************************************************************************************************
*                                             VARIABLES
*********************************************************************************************************
*/

OS_STK           TestStatTaskStk[TASK_STK_SIZE];

OS_STK           TestAIOTaskStk[TASK_STK_SIZE];
OS_STK           TestClkTaskStk[TASK_STK_SIZE];
OS_STK           TestDIOTaskStk[TASK_STK_SIZE];
OS_STK           TestRxTaskStk[TASK_STK_SIZE];
OS_STK           TestTxTaskStk[TASK_STK_SIZE];
OS_STK           TestTmrTaskStk[TASK_STK_SIZE];


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

static void       TestDispLit(void);
static void       TestDispMap(void);

       void       TestStatTask(void *data);
static void       TestInitModules(void);

       void       TestAIOTask(void *data);
       
       void       TestClkTask(void *data);
       
       void       TestDIOTask(void *data);
       
       void       TestRxTask(void *data);
       void       TestTxTask(void *data);
       
       void       TestTmrTask(void *data);
static void       TestTmr0TO(void *arg);
static void       TestTmr1TO(void *arg);

/*$PAGE*/
/*
*********************************************************************************************************
*                                                  MAIN
*
* Description: This is the main program entry point.  If you type the following command (i.e. without
*              arguments) from the DOS command line, the Embedded Systems Building Blocks test code will 
*              execute.
*
*                  TEST
*                   
*              If you specify 'any' argument to TEST on the command line, TEST will display the PC's
*              display character map.  In other words, you could type:
*
*                  TEST display
*
* Arguments  : argc        is the 'standard' C command line argument count
*              argv        is an array containing the arguments passed on the command line
*
* Returns    : nothing
*********************************************************************************************************
*/

void  main (int argc, char *argv[])
{
    if (argc > 1) {
        if (strcmp(argv[1], "display") == 0 || strcmp(argv[1], "DISPLAY") == 0) {
            TestDispMap();                                 /* Display the PC's character map           */
        }
        exit(0);                                           /* Return back to DOS                       */
    }
    
    PC_DispClrScr(DISP_FGND_WHITE + DISP_BGND_BLACK);      /* Clear the screen                         */
    OSInit();                                              /* Initialize uC/OS-II                      */
    OSFPInit();                                            /* Initialize floating-point support        */
    PC_DOSSaveReturn();                                    /* Save environment to return to DOS        */   
    PC_VectSet(uCOS, OSCtxSw);                             /* Install uC/OS-II's context switch vector */
    OSTaskCreateExt(TestStatTask, 
                   (void *)0, 
                   &TestStatTaskStk[TASK_STK_SIZE], 
                   STAT_TASK_PRIO,
                   STAT_TASK_PRIO, 
                   &TestStatTaskStk[0], 
                   TASK_STK_SIZE, 
                   (void *)0, 
                   OS_TASK_OPT_SAVE_FP);
    OSStart();                                             /* Start multitasking                       */
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                      TEST 'Analog I/Os' TASK
*********************************************************************************************************
*/

void  TestAIOTask (void *data)
{
    char    s[81];
    FP32    value;
    INT16S  temp;
    INT8U   err;
    

    data = data;                                           /* Prevent compiler warning                 */
    
    AICfgConv(0, 0.01220740, -4095.875, 10);               /* Configure AI channel #0                  */
    AICfgCal(0,  1.00,           0.00);
    
    for (;;) {
        err  = AIGet(0, &value);                           /* Read AI channel #0                       */
        temp = (INT16S)value;                              /* No need for decimal places               */
        sprintf(s, "%5d", temp);                           
        PC_DispStr(49, 11, s, DISP_FGND_YELLOW + DISP_BGND_BLUE);

        OSTimeDlyHMSM(0, 0, 0, 10);                        /* Run 100 times per second                 */
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                           TEST 'Clk' TASK
*********************************************************************************************************
*/

void  TestClkTask (void *data)
{
    char    s[81];
    INT16U  time;
    TS      ts;


    data  = data;                                          /* Prevent compiler warning                 */

    ClkSetDateTime(12, 31, 1999, 23, 58, 0);               /* Set the clock/calendar                   */

    for (;;) {
        PC_ElapsedStart();
        ClkFormatDate(2, s);                               /* Get formatted date from clock/calendar   */
        time = PC_ElapsedStop();
        PC_DispStr( 8, 11, "                   ", DISP_FGND_WHITE);
        PC_DispStr( 8, 11, s, DISP_FGND_BLUE + DISP_BGND_CYAN);
        sprintf(s, "%3d uS", time);
        PC_DispStr( 8, 14, s, DISP_FGND_RED + DISP_BGND_LIGHT_GRAY);

        PC_ElapsedStart();
        ClkFormatTime(1, s);                               /* Get formatted time from clock/calendar   */
        time = PC_ElapsedStop();
        PC_DispStr( 8, 12, s, DISP_FGND_BLUE + DISP_BGND_CYAN);
        sprintf(s, "%3d uS", time);
        PC_DispStr(22, 14, s, DISP_FGND_RED + DISP_BGND_LIGHT_GRAY);

        ts = ClkGetTS();                                   /* Get current   time stamp                 */
        ClkFormatTS(2, ts, s);                             /* Get formatted time stamp                 */
        PC_DispStr( 8, 13, s, DISP_FGND_BLUE + DISP_BGND_CYAN);

        OSTimeDlyHMSM(0, 0, 0, 100);
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                      TEST 'Discrete I/Os' TASK
*********************************************************************************************************
*/

void  TestDIOTask (void *data)
{
    BOOLEAN state;


    data = data;                                           /* Prevent compiler warning                 */
    
    DOSetSyncCtrMax(100);
    
    DOCfgBlink(0, DO_BLINK_EN,  5, 10);                    /* Discrete Out #0, Blink 50% duty          */
    DOCfgMode(0,  DO_MODE_BLINK_ASYNC, FALSE);
    
    DOCfgBlink(1, DO_BLINK_EN, 10, 20);                    /* Discrete Out #1, Blink 50% duty          */
    DOCfgMode(1,  DO_MODE_BLINK_ASYNC, FALSE);
    
    DOCfgBlink(2, DO_BLINK_EN, 25,  0);                    /* Discrete Out #2, Blink 25% duty          */
    DOCfgMode(2,  DO_MODE_BLINK_SYNC, FALSE);

    for (;;) {
        state = DOGet(0);
        if (state == TRUE) {
            PC_DispStr(49,  6, "TRUE ", DISP_FGND_YELLOW + DISP_BGND_BLUE);
        } else {
            PC_DispStr(49,  6, "FALSE", DISP_FGND_YELLOW + DISP_BGND_BLUE);
        }
        state = DOGet(1);
        if (state == TRUE) {
            PC_DispStr(49,  7, "HIGH", DISP_FGND_YELLOW + DISP_BGND_BLUE);
        } else {
            PC_DispStr(49,  7, "LOW ", DISP_FGND_YELLOW + DISP_BGND_BLUE);
        }
        state = DOGet(2);
        if (state == TRUE) {
            PC_DispStr(49,  8, "ON ", DISP_FGND_YELLOW + DISP_BGND_BLUE);
        } else {
            PC_DispStr(49,  8, "OFF", DISP_FGND_YELLOW + DISP_BGND_BLUE);
        }
        OSTimeDlyHMSM(0, 0, 0, 100);                       /* Run 10 times per second                  */
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                           DISPLAY LAYOUT
*********************************************************************************************************
*/

static  void  TestDispLit (void)
{
                     /*           1111111111222222222233333333334444444444555555555566666666667777777777 */
                     /* 01234567890123456789012345678901234567890123456789012345678901234567890123456789 */
    PC_DispStr( 0,  0, "                        EMBEDDED SYSTEMS BUILDING BLOCKS                        ", DISP_FGND_WHITE + DISP_BGND_RED + DISP_BLINK);
    PC_DispStr( 0,  1, "                     Complete and Ready-to-Use Modules in C                     ", DISP_FGND_WHITE);
    PC_DispStr( 0,  2, "                                Jean J. Labrosse                                ", DISP_FGND_WHITE);
    PC_DispStr( 0,  3, "                                  SAMPLE  CODE                                  ", DISP_FGND_WHITE);
    PC_DispStr( 0,  4, "                                                                                ", DISP_FGND_WHITE);
    PC_DispStr( 0,  5, "Chapter 3, Keyboards                    Chapter  8, Discrete I/Os               ", DISP_FGND_WHITE);
    PC_DispStr( 0,  6, "Chapter 4, Multiplexed LED Displays       DO #0:        50% Duty Cycle (Async)  ", DISP_FGND_WHITE);
    PC_DispStr( 0,  7, "Chapter 5, Character LCD Modules          DO #1:        50% Duty Cycle (Async)  ", DISP_FGND_WHITE);
    PC_DispStr( 0,  8, "  -No Sample Code-                        DO #2:        25% Duty Cycle (Sync)   ", DISP_FGND_WHITE);
    PC_DispStr( 0,  9, "                                                                                ", DISP_FGND_WHITE);
    PC_DispStr( 0, 10, "Chapter 6, Time-Of-Day Clock            Chapter 10, Analog I/Os                 ", DISP_FGND_WHITE);
    PC_DispStr( 0, 11, "  Date:                                   AI #0:                                ", DISP_FGND_WHITE);
    PC_DispStr( 0, 12, "  Time:                                                                         ", DISP_FGND_WHITE);
    PC_DispStr( 0, 13, "  TS  :                                                                         ", DISP_FGND_WHITE);
    PC_DispStr( 0, 14, "  Date:         Time:                                                           ", DISP_FGND_WHITE);
    PC_DispStr( 0, 15, "Chapter 7, Timer Manager                Chapter 11, Async. Serial Comm.         ", DISP_FGND_WHITE);
    PC_DispStr( 0, 16, "  Tmr0:                                   Tx   :                                ", DISP_FGND_WHITE);
    PC_DispStr( 0, 17, "                                          Rx   :                                ", DISP_FGND_WHITE);
    PC_DispStr( 0, 18, "  Tmr1:                                                                         ", DISP_FGND_WHITE);
    PC_DispStr( 0, 19, "                                                                                ", DISP_FGND_WHITE);
    PC_DispStr( 0, 20, "                                                                                ", DISP_FGND_WHITE);
    PC_DispStr( 0, 21, "                                                                                ", DISP_FGND_WHITE);
    PC_DispStr( 0, 22, "                                                                                ", DISP_FGND_WHITE);
    PC_DispStr( 0, 23, "MicroC/OS-II Vx.yy    #Tasks: xxxxx   #Task switch/sec: xxxxx   CPU Usage: xxx %", DISP_FGND_YELLOW + DISP_BGND_BLUE);
    PC_DispStr( 0, 24, "                            <-PRESS 'ESC' TO QUIT->                             ", DISP_FGND_WHITE);
                     /*           1111111111222222222233333333334444444444555555555566666666667777777777 */
                     /* 01234567890123456789012345678901234567890123456789012345678901234567890123456789 */
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                       DISPLAY CHARACTER MAP
*
* Description: This function displays the full character mode display map.  The left hand side of the
*              table corresponds to the ASCII characters (i.e. 0x00 to 0x7F) while the right hand side
*              table corresponds to 'special' characters from 0x80 to 0xFF.
*
* Arguments  : none
*
* Returns    : nothing
*********************************************************************************************************
*/

static  void  TestDispMap (void)
{
    INT8U  x;
    INT8U  y;
    INT16S key;
    
    
    PC_DispClrScr(DISP_FGND_WHITE);
    PC_DispStr( 0,  0, "                        EMBEDDED SYSTEMS BUILDING BLOCKS                        ", DISP_FGND_WHITE + DISP_BGND_RED + DISP_BLINK);
    PC_DispStr( 0,  1, "                     Complete and Ready-to-Use Modules in C                     ", DISP_FGND_WHITE);
    PC_DispStr( 0,  2, "                                Jean J. Labrosse                                ", DISP_FGND_WHITE);
    PC_DispStr( 0,  3, "                                 PC DISPLAY MAP                                 ", DISP_FGND_WHITE);
    PC_DispStr( 0,  4, "                                                                                ", DISP_FGND_WHITE);
    PC_DispStr( 0,  5, "     ------ ASCII  Characters ------            ----- Special  Characters ----- ", DISP_FGND_WHITE);
    PC_DispStr( 0,  6, "     0 1 2 3 4 5 6 7 8 9 A B C D E F            0 1 2 3 4 5 6 7 8 9 A B C D E F ", DISP_FGND_WHITE);
    PC_DispStr( 0,  7, "                                                                                ", DISP_FGND_WHITE);
    PC_DispStr( 0,  8, "0x00                                       0x80                                 ", DISP_FGND_WHITE);
    PC_DispStr( 0,  9, "                                                                                ", DISP_FGND_WHITE);
    PC_DispStr( 0, 10, "0x10                                       0x90                                 ", DISP_FGND_WHITE);
    PC_DispStr( 0, 11, "                                                                                ", DISP_FGND_WHITE);
    PC_DispStr( 0, 12, "0x20                                       0xA0                                 ", DISP_FGND_WHITE);
    PC_DispStr( 0, 13, "                                                                                ", DISP_FGND_WHITE);
    PC_DispStr( 0, 14, "0x30                                       0xB0                                 ", DISP_FGND_WHITE);
    PC_DispStr( 0, 15, "                                                                                ", DISP_FGND_WHITE);
    PC_DispStr( 0, 16, "0x40                                       0xC0                                 ", DISP_FGND_WHITE);

⌨️ 快捷键说明

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