This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Multiplexed 7 segment display scanning

I am using 6 7-segment displays which are multiplexed using a 3:8 multiplexer. I am displaying ADC readings on the display. I am unable to find a point wherein the display would not flicker but show continuous reading (ADC: ADS1230, uC: 89V51RD2, Communication via SPI)
Here's my current code for displaying results.

code const unsigned char ActualDigit[10] = {
    0xC0, 0xF9, 0xA4,
    0xB0, 0x99, 0x92,
    0x82, 0xF8, 0x80,
    0x98
};

code const unsigned char DigitSelect[6] = {
    0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0
};

void segdelay()
{
    int i;
    for(i=0; i<=200; i++);
}


void turnOffAll()
{
        char i;
        for(i=0;i<6;i++)
        {
                P2 &= ~((1<<5) | (1<<6) | (1<<7));
                P2 |= DigitSelect[i];
                P0 = 0xFF;
        }
}

void showData(int adcresult)
{
        int digits[6];
        char count = 0,i;
        while(adcresult)
        {
                digits[count++] = adcresult % 10;
                adcresult/=10;
        }
        for(i=0;i<count;i++)
        {
                P2 &= ~((1<<5) | (1<<6) | (1<<7));
                P2 |= DigitSelect[i];
                P0 = ActualDigit[digits[i]];
                segdelay();
                turnOffAll();
        }
}

Parents
  • Does this code seem good?

    void timer_init()
    {
            TMOD = 0x01;            // mode1 of Timer0
            TH0 = 0xE0;             // initial values loaded to timer
            TL0 = 0xBF;
            IEN0 = 0x82;            // enable interrupt
            TR0 = 1;
    }
    
    void holdResult(int adcresult)
    {
            char count = 0;
            while(adcresult)
            {
                    digits[count++] = (char)(adcresult % 10);
                    adcresult/=10;
            }
            totalDigits = count - 1;
    }
    
    void showDigit()
    {
            if(currentDigit > totalDigits)
                    currentDigit = 0;
            //P2 &= ~((1<<5) | (1<<6) | (1<<7));
            P2 = DigitSelect[currentDigit];
            P0 = ActualDigit[digits[currentDigit++]];
    }
    
    void timer(void) interrupt 1            //interrupt no. 1 for Timer 0
    {
            showDigit();
            TH0=0xE0;               // initial values loaded to timer
            TL0=0xBF;
    }
    
    void main()
    {
        P0 = 0xFF;
                    P2 &= ~((1<<5) | (1<<6) | (1<<7));
                    init_master();
                    timer_init();
                    while(1)
                    {
                            adc_result = receiveADC();
                            holdResult(adc_result);
                    }
    }
    

Reply
  • Does this code seem good?

    void timer_init()
    {
            TMOD = 0x01;            // mode1 of Timer0
            TH0 = 0xE0;             // initial values loaded to timer
            TL0 = 0xBF;
            IEN0 = 0x82;            // enable interrupt
            TR0 = 1;
    }
    
    void holdResult(int adcresult)
    {
            char count = 0;
            while(adcresult)
            {
                    digits[count++] = (char)(adcresult % 10);
                    adcresult/=10;
            }
            totalDigits = count - 1;
    }
    
    void showDigit()
    {
            if(currentDigit > totalDigits)
                    currentDigit = 0;
            //P2 &= ~((1<<5) | (1<<6) | (1<<7));
            P2 = DigitSelect[currentDigit];
            P0 = ActualDigit[digits[currentDigit++]];
    }
    
    void timer(void) interrupt 1            //interrupt no. 1 for Timer 0
    {
            showDigit();
            TH0=0xE0;               // initial values loaded to timer
            TL0=0xBF;
    }
    
    void main()
    {
        P0 = 0xFF;
                    P2 &= ~((1<<5) | (1<<6) | (1<<7));
                    init_master();
                    timer_init();
                    while(1)
                    {
                            adc_result = receiveADC();
                            holdResult(adc_result);
                    }
    }
    

Children