/*Header******************************************************/
unsigned short gear, memo ; // Define variables
#define SEGA 0x01
#define SEGB 0x02
#define SEGC 0x04
#define SEGD 0x08
#define SEGE 0x10
#define SEGF 0x20
#define SEGG 0x40
#define NUM0 SEGA+SEGB+SEGC+SEGD+SEGE+SEGF
#define NUM1 SEGB+SEGC
#define NUM2 SEGA+SEGB+SEGG+SEGE+SEGD
#define NUM3 SEGA+SEGB+SEGG+SEGC+SEGD
#define NUM4 SEGF+SEGG+SEGB+SEGC
#define NUM5 SEGA+SEGF+SEGG+SEGC+SEGD
#define NUM6 SEGA+SEGF+SEGE+SEGD+SEGC+SEGG
#define NUM7 SEGA+SEGB+SEGC
#define NUM8 SEGA+SEGB+SEGC+SEGD+SEGE+SEGF+SEGG
#define NUM9 SEGG+SEGF+SEGA+SEGB+SEGC+SEGD
const unsigned char numbitmap[]={NUM0, NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7,NUM8, NUM9};
void initMain() {
ANSEL = 0; // All I/O pins are configured as digital
ANSELH = 0;
PORTA = 255; // Port A initial state
TRISA = 255; // All port A pins are configured as inputs
PORTD = 0; // Initial state of port B
TRISD = 0; // All port D pins are configured as outputs
}
void main() {
initMain();
gear = 0; // Initial value of variable gear
memo = 0; // Reset variable memo
while (1) { // Endless loop
if (Button(&PORTA, 0,1,1)) // If the button connected to RA0 is pressed
gear++ ; // increment variable gear
if (Button(&PORTA, 1,1,1)) // If the pressed button is connected to RA1
gear-- ; // decrement value gear
if (memo != gear) { // If gear and memo are not equal
memo = gear; // save the new value
PORTD = numbitmap[gear]; // and show it on port D
Delay_ms(200); // 200mS delay
}
}