thanks a lot for your suggestion.
first code you quoted
WriteBCD = tents;
WriteBCD = WriteBCD | ((tents >> 1) & 0b01000000); // Surely this is zero?
WriteBCD = WriteBCD & 0b01000111; // Mask only bits 6,3,2,1,0
line two--- I just saw the mistake, it should be same as the unit
line three --- mask only bit 6, 2, 1, 0 that right
for the code 2nd you quoted
line 2 --- during the next loop when condition is false, it flow through this code, so the WriteBCD is cleared before the decision ask.
now here is the new thang, with your code.
8, 9 to 88, 89
18, 19 to 98, 99
starting 20s to 70s, when the units are 8 or 9 it overflow give the result,
-8 and -9 on 28 29 38 39 48 49 58 59 68 69 78 and 79
- means overflow(1010 to 1111)
but at 80s, 80-87 to 00-07 then 88, 89 were right
and at 90s, 90-97 to 10-17 and 98, 99 were right.
void BCDout(char value)
{
char tens = value/10;
char unit = value - (tens*10);
char WriteBCD = 0;
x = ~x;
if(x == 0xFF) //tens
{
WriteBCD = tens & 0b00000111;
if(unit & 0b00001000)
{
WriteBCD += 0b01000000;
}
PORTA = (PORTA & 0x10111000) | WriteBCD;
RB1 = x;
}
else
{
WriteBCD = unit & 0b00000111;
if(unit & 0b00001000)
{
WriteBCD += 0b01000000;
}
PORTA = (PORTA & 0x10111000) | WriteBCD;
RB1 = x;
}
}
I realize I spell tens wrongly so corrected!