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

📄 led.c

📁 《嵌入式系统构件》源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    0x9E,                              /* 'E'                                                          */
    0x8E                               /* 'F'                                                          */
};

/*$PAGE*/
/*
*********************************************************************************************************
*                                          CLEAR THE DISPLAY
*
* Description: This function is called to clear the display.
* Arguments  : none
* Returns    : none
*********************************************************************************************************
*/

void  DispClrScr (void)
{
    INT8U i;


    for (i = 0; i < DISP_N_DIG; i++) {           /* Clear the screen by turning OFF all segments       */
        OS_ENTER_CRITICAL();
        DispSegTbl[i] = 0x00;
        OS_EXIT_CRITICAL();
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                      DISPLAY DRIVER INITIALIZATION
*
* Description : This function initializes the display driver.
* Arguments   : None.
* Returns     : None.
*********************************************************************************************************
*/

void  DispInit (void)
{
    DispInitPort();                    /* Initialize I/O ports used in display driver                  */
    DispDigMsk   = 0x80;
    DispSegTblIx = 0;
    DispClrScr();                      /* Clear the Display                                            */
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                        DISPLAY NEXT SEVEN-SEGMENT DIGIT
*
* Description: This function is called by DispMuxISR() to output the segments and select the next digit
*              to be multiplexed.  DispMuxHandler() is called by DispMuxISR() defined in LED_IA.ASM
* Arguments  : none
* Returns    : none
* Notes      : - You MUST supply the code to clear the interrupt source.  Note that with some
*                microprocessors (i.e. Motorola's MC68HC11), you must clear the interrupt source before
*                enabling interrupts.
*********************************************************************************************************
*/

void  DispMuxHandler (void)
{
                                                 /* Insert code to CLEAR INTERRUPT SOURCE here         */

    DispOutSeg(0x00);                            /* Turn OFF segments while changing digits            */
    DispOutDig(DispDigMsk);                      /* Select next digit to display                       */
    DispOutSeg(DispSegTbl[DispSegTblIx]);        /* Output digit's seven-segment pattern               */
    if (DispSegTblIx == (DISP_N_DIG - 1)) {      /* Adjust index to next seven-segment pattern         */
        DispSegTblIx =    0;                     /* Index into first segments pattern                  */
        DispDigMsk   = 0x80;                     /* 0x80 will select the first seven-segment digit     */
    } else {
        DispSegTblIx++;
        DispDigMsk >>= 1;                        /* Select next digit                                  */
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                         CLEAR STATUS SEGMENT
*
* Description: This function is called to turn OFF a single segment on the display.
* Arguments  : dig   is the position of the digit where the segment appears (0..DISP_N_DIG-1)
*              bit   is the segment bit to turn OFF (0..7)
* Returns    : none
*********************************************************************************************************
*/

void  DispStatClr (INT8U dig, INT8U bit)
{
    OS_ENTER_CRITICAL();
    DispSegTbl[dig] &= ~(1 << bit);
    OS_EXIT_CRITICAL();
}


/*
*********************************************************************************************************
*                                           SET STATUS SEGMENT
*
* Description: This function is called to turn ON a single segment on the display.
* Arguments  : dig   is the position of the digit where the segment appears (0..DISP_N_DIG-1)
*              bit   is the segment bit to turn ON (0..7)
* Returns    : none
*********************************************************************************************************
*/

void  DispStatSet (INT8U dig, INT8U bit)
{
    OS_ENTER_CRITICAL();
    DispSegTbl[dig] |= 1 << bit;
    OS_EXIT_CRITICAL();
}

/*$PAGE*/
/*
*********************************************************************************************************
*                            DISPLAY ASCII STRING ON SEVEN-SEGMENT DISPLAY
*
* Description: This function is called to display an ASCII string on the seven-segment display.
* Arguments  : dig   is the position of the first digit where the string will appear:
*                        0 for the first  seven-segment digit.
*                        1 for the second seven-segment digit.
*                        .  .   .     .     .      .      .
*                        .  .   .     .     .      .      .
*                        DISP_N_SS - 1 is the last seven-segment digit.
*              s     is the ASCII string to display
* Returns    : none
* Notes      : - Not all ASCII characters can be displayed on a seven-segment display.  Consult the
*                ASCII to seven-segment conversion table DispASCIItoSegTbl[].
*********************************************************************************************************
*/

void  DispStr (INT8U dig, char *s)
{
    INT8U stat;


    while (*s && dig < DISP_N_SS) {
        OS_ENTER_CRITICAL();
        stat              = DispSegTbl[dig] & 0x01;                  /* Save state of B0 (i.e. status) */
        DispSegTbl[dig++] = DispASCIItoSegTbl[*s++ - 0x20] | stat;
        OS_EXIT_CRITICAL();
    }
}

/*$PAGE*/
#ifndef CFG_C
/*
*********************************************************************************************************
*                                        I/O PORTS INITIALIZATION
*
* Description: This is called by DispInit() to initialize the output ports used in the LED multiplexing.
* Arguments  : none
* Returns    : none
* Notes      : 74HC573  8 bit latches are used for both the segments and digits outputs.
*********************************************************************************************************
*/

void  DispInitPort (void)
{
    outp(DISP_PORT_SEG, 0x00);              /* Turn OFF segments                                       */
    outp(DISP_PORT_DIG, 0x00);              /* Turn OFF digits                                         */
}


/*
*********************************************************************************************************
*                                        DIGIT output
*
* Description: This function outputs the digit selector.
* Arguments  : msk    is the mask used to select the current digit.
* Returns    : none
*********************************************************************************************************
*/

void  DispOutDig (INT8U msk)
{
    outp(DISP_PORT_DIG, msk);
}


/*
*********************************************************************************************************
*                                        SEGMENTS output
*
* Description: This function outputs seven-segment patterns.
* Arguments  : seg    is the seven-segment pattern to output
* Returns    : none
*********************************************************************************************************
*/

void  DispOutSeg (INT8U seg)
{
    outp(DISP_PORT_SEG, seg);
}
#endif

⌨️ 快捷键说明

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