#include "Display_Utils.h"
unsigned short shifter, portd_index;
unsigned int digit, number;
unsigned short portd_array[4];
void interrupt() {
LATA = 0; // Turn off all 7seg displays
LATD = portd_array[portd_index]; // bring appropriate value to PORTD
LATA = shifter; // turn on appropriate 7seg. display
// move shifter to next digit
shifter <<= 1;
if (shifter > 8u)
shifter = 1;
// increment portd_index
portd_index++ ;
if (portd_index > 3u)
portd_index = 0; // turn on 1st, turn off 2nd 7seg.
TMR0L = 0; // reset TIMER0 value
TMR0IF_bit = 0; // Clear TMR0IF
}
void main() {
ANSELA = 0; // Configure PORTA pins as digital
ANSELD = 0; // Configure PORTD pins as digital
TRISA = 0; // Configure PORTA as output
TRISC = 0xFF;
LATA = 0; // Clear PORTA
TRISD = 0; // Configure PORTD as output
LATD = 0; // Clear PORTD
T0CON = 0xC4; // Set TMR0 in 8bit mode, assign prescaler to TMR0
TMR0L = 0; // clear TMROL
digit = 0;
portd_index = 0;
shifter = 1;
number = 1234; // Initial number value
GIE_bit = 1;
TMR0IE_bit = 1;
do {
digit =PORTC ; // extract thousands digit
portd_array[3] = digit; // and store it to PORTD array
/*digit = (number / 100u) % 10u; // extract hundreds digit
portd_array[2] = mask(digit); // and store it to PORTD array
digit = (number / 10u) % 10u; // extract tens digit
portd_array[1] = mask(digit); // and store it to PORTD array
digit = number % 10u; // extract ones digit
portd_array[0] = mask(digit); // and store it to PORTD array
*/
Delay_ms(1000); // one second delay
number++ ; // increment number
if (number > 9999u)
number = 0;
} while(1); // endless loop
}