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(); } }
You could start by not turning them off all the while, and modifying P2 in a single operation
Consider having a holding register for the display digits, and cycling through that in an interrupt periodically.
I did some flicker analysis a while ago 60Hz everyone see flicker 100Hz some see flicker 1200Hz none see flicker
Did you mean 120Hz ?
yes, 120 HZ min, for a display, but as a note LED lighting (which I just did) run, typically @ 1200, thus the goof
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); } }
"Does this code seem good?"
Shouldn't the question be: do this code run good? What result did you get when you tested?
No idea, I don't have your hardware, what does your testing show?
Why don't you mask on the bits to P2 in manner that doesn't interfere with unrelated bits?
P2 = (P2 & ~((1<<5) | (1<<6) | (1<<7))) | DigitSelect[currentDigit];
P2 = (P2 & 0x1F) | DigitSelect[currentDigit];
I wonder if receiveADC() does
my GUESS is that you are loopwaiting there