unsigned short mask(unsigned short num) {
switch (num) {
case 0 : return 0x3F;
case 1 : return 0x06;
case 2 : return 0x5B;
case 3 : return 0x4F;
case 4 : return 0x66;
case 5 : return 0x6D;
case 6 : return 0x7D;
case 7 : return 0x07;
case 8 : return 0x7F;
case 9 : return 0x6F;
} //case end
}
unsigned int digit; // To Hold Decimal Value
unsigned short number; // To Hold Equivalent Seven Segment Value
void main() {
CMCON |= 7; // Disable Comparators
TRISB = 0x00; // Set PORTB direction to be output
PORTB = 0x00; // Turn OFF LEDs on PORTB
TRISA0_bit = 1; // PA.0 Input for Increment
TRISA1_bit = 1; // PA.1 Input for Decrement
digit = 0; // Initial Value of Counter
number = mask(digit) ;
PORTB = number;
do {
if (Button(&PORTA, 0, 1, 0)) { // Detect logical one to zero
Delay_ms(300);
digit ++; // Increase Counter
number = mask(digit) ;
PORTB = number;
}
if (Button(&PORTA, 1, 1, 0)) { // Detect logical one to zero
Delay_ms(300) ;
digit = digit-1; // Decrease Counter
number = mask(digit) ;
PORTB = number; // Update flag
}
} while(1); // endless loop
}