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

📄 sevensegment.c

📁 uCOS-II example for MC9S12DPxxx
💻 C
📖 第 1 页 / 共 2 页
字号:
{
   INT8U digits[4];
   INT8U currDispNum;
   
   
   PTP        |=   0x0F;                                                /* Shut off all 7-Segment LED blocks by removing the ground */   
   currDispNum = ((actBlockNum) % 4);                                   /* Get the number of the current LED block to display on    */
   actBlockNum++;                                                       /* Increment the display # used for the next interrupt      */
   
                                                                        /* Calculate all the digits for each display even though    */
                                                                        /* only one of these digits will be used during this ISR    */
                                                                        
   digits[0]   =  (INT8U) (outputNum / 1000);	                        /* Calculate digit 4 (most significant) 1000's place        */
   digits[1]   =  (INT8U)((outputNum % 1000) / 100);                    /* Calculate digit 3, the 100's place                       */
   digits[2]   =  (INT8U)((outputNum % 100)  / 10);                     /* Calculate digit 2, the 10's place                        */
   digits[3]   =  (INT8U) (outputNum % 10);                             /* Calculate digit 1 (lease significant) 1's place          */
      
   SevenSegOut(digits[currDispNum]);                                    /* Put the value on the 7-Segment LED data bus              */
   PTP        &= ~(1 << currDispNum);                                   /* Enable the current LED block, by supplying the ground    */
   
#if SEVEN_SEG_OC == 0
    TFLG1 |= 0x01;                                                      /* Clear interrupt                                          */
    TC0   += nbrCnts;                                                   /* Set TC0 to present time + nbrCnts                        */
#endif

#if SEVEN_SEG_OC == 1 
    TFLG1 |= 0x02;                                                      /* Clear interrupt                                          */
    TC1   += nbrCnts;                                                   /* Set TC1 to present time + nbrCnts                        */
#endif

#if SEVEN_SEG_OC == 2
    TFLG1 |= 0x04;                                                      /* Clear interrupt                                          */
    TC2   += nbrCnts;                                                   /* Set TC2 to present time + nbrCnts                        */
#endif

#if SEVEN_SEG_OC == 3
    TFLG1 |= 0x08;                                                      /* Clear interrupt                                          */
    TC3   += nbrCnts;                                                   /* Set TC3 to present time + nbrCnts                        */
#endif

#if SEVEN_SEG_OC == 4
    TFLG1 |= 0x10;                                                      /* Clear interrupt                                          */
    TC4   += nbrCnts;                                                   /* Set TC4 to present time + nbrCnts                        */
#endif

#if SEVEN_SEG_OC == 5
    TFLG1 |= 0x20;                                                      /* Clear interrupt                                          */
    TC5   += nbrCnts;                                                   /* Set TC5 to present time + nbrCnts                        */
#endif

#if SEVEN_SEG_OC == 6
    TFLG1 |= 0x40;                                                      /* Clear interrupt                                          */
    TC6   += nbrCnts;                                                   /* Set TC6 to present time + nbrCnts                        */
#endif

#if SEVEN_SEG_OC == 7
    TFLG1 |= 0x80;                                                      /* Clear interrupt                                          */
    TC7   += nbrCnts;                                                   /* Set TC7 to present time + nbrCnts                        */   
#endif    
}


/*
*********************************************************************************************************
*                                        7-Segment Display Write
*
* Description : This function puts data on PORTB, the 7-Segment LED data bus.
*********************************************************************************************************
*/

static  void  SevenSegOut (INT8U digit)
{
    PTJ |= (1 << 1);                                                    /* Shut off the other regular LED's while displaying        */
    
    switch (digit) {
        case 0:
             PORTB = SSD_0;
             break;

        case 1:
             PORTB = SSD_1;
             break;

        case 2:
             PORTB = SSD_2;
             break;

        case 3:
             PORTB = SSD_3;
             break;

        case 4:
             PORTB = SSD_4;
             break;

        case 5:
             PORTB = SSD_5;
             break;

        case 6:
             PORTB = SSD_6;
             break;

        case 7:
             PORTB = SSD_7;
             break;

        case 8:
             PORTB = SSD_8;
             break;

        case 9:
             PORTB = SSD_9;
             break;

        case 'A':
             PORTB = SSD_A;
             break;

        case 'B':
             PORTB = SSD_B;
             break;
        
        case 'C':
             PORTB = SSD_C;
             break;
        
        case 'D':
             PORTB = SSD_D;
             break;
        
        case 'E':
             PORTB = SSD_E;
             break;
        
        case 'F':
             PORTB = SSD_F;
             break;
        
        default:
             break; 
    }
}


/*
*********************************************************************************************************
*                                        Multiple 7-Seg Output
*
* Description : This function updates a global variable used to pass the desired
*               value of the digit to be displayed on the 7-Segment LEDs to the
*               SevenSegDisp_ISR. A critical section must be used to ensure exclusive
*               access to the global variable while it is being updated. This function
*               is thread safe.
*
* Notes       : This function only allows decimal numbers between 0000 and 9999 inclusive to be
*               written to the global output variable. Any number < 0 or > 9999 can not be
*               represented on four, 7-Segment LED blocks.  Ex: [9][1][2][3], 9123.
*********************************************************************************************************
*/

void  SevenSegWrite (INT16U num) 
{
    CPU_SR  cpu_sr;
    
    
    if (num <= 9999) {                                                      /* Only display numbers between 0000 and 9999 inclusive     */        
        CPU_CRITICAL_ENTER();                                               /* Lock access to the global output variable                */
        outputNum = num;                                                    /* Update the variable with the new output value            */
        CPU_CRITICAL_EXIT();                                                /* Unlock access to the global output variable              */
    }
}


⌨️ 快捷键说明

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