106
Everything else in this demo is done inside Timer_A3 interrupt subroutine (ISR). There are two parts
inside the ISR. The first as shown below is responsible for counting time.
ms++;
if(ms > 999)
{
ms = 0;
value++;
if(value > 9999)
{
value = 0;
}
}
The other portion is tasked with the LED segment scanning and data display part. At every millisecond,
a new segment is turned on, keeping others off. At the end of the ISR, interrupt flags are cleared.
switch(seg)
{
case 1:
{
n = (value / 1000);
P2OUT = num[n];
P1OUT = 0xE0;
break;
}
case 2:
{
n = ((value / 100) % 10);
P2OUT = num[n];
P1OUT = 0xD0;
break;
}
case 3:
{
n = ((value / 10) % 10);
P2OUT = num[n];
P1OUT = 0xB0;
break;
}
case 4:
{
n = (value % 10);
P2OUT = num[n];
P1OUT = 0x70;
break;
}
}
seg++;
if(seg > 4)
{
seg = 1;