mmc01
Joined: 16 Jun 2010 Posts: 31
|
How to fix 7 Segment multiplex blink ? |
Posted: Sat Jun 07, 2014 9:52 am |
|
|
I connect 7 Segment Anode 2 Digits to 16F887 by multiplex. The 7 Segment always blink. I reduce delay in code but it blink yet. How to fix it ?
Code: | #include <16F887.h>
#fuses HS
#fuses NOLVP
#fuses NOWDT
#fuses NOPROTECT
#use delay(clock = 4000000)
#define LED_DSP(x) OUTPUT_C(x)
char dt1,dt2; // delay time
int i=0;
// LED Number Cathode
/*char const LED_NUM[10] = {0x3F,0x06, 0x5B, 0x4F, //0,1,2,3
0x66, 0x6D, 0x7D, //4,5,6
0x07, 0x7F, 0x6F, //7,8,9
};
*/
//LED Number Anode
char const LED_NUM[10] = {0x40,0x79, 0x24, 0x30, //0,1,2,3
0x19, 0x12, 0x02, //4,5,6
0x78, 0x00, 0x10, //7,8,9
};
//-------------------------------------------------------Dispaly Digit1
void dsp_digit1(char n) {
output_b(0x05);
LED_DSP(n);
delay_ms(2-dt1-dt2); // delay
}
//-------------------------------------------------------Dispaly Digit2
void dsp_digit2(char n) {
output_b(0x03);
LED_DSP(n);
delay_ms(dt1); // delay
}
void main (void)
{
while(1)
{
i++;
dsp_digit1(LED_NUM[i/10]);
delay_ms(50);
dsp_digit2(LED_NUM);
delay_ms(50);
if(i>99){
i = 0;
}
}
} |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Sat Jun 07, 2014 12:14 pm |
|
|
What if anything is putting a value into dt1, and dt2?.
The line:
delay_ms(2-dt1-dt2); // delay
Will overflow, if these are anything other than '0' or '1'. They'll wake up probably containing 255. integers are unsigned by default, so the value would wrap and could give silly long delays.
Get rid of both these delays. You already have fixed digit delays in the outer loop. |
|