dope40
Member level 4
- Joined
- Oct 3, 2011
- Messages
- 76
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Bulgaria
- Activity points
- 1,777
Problem with project (gear indicator)
Hi , i am making gear indicator, but i cant make the code work properly... i am new to MicroC so i need some help.I am using 7 segment common cathode display and two buttons ,the buttons are connected to PORTA and the 7segment is connected to PORTB. the code i am using is this...
I dont know how to make it if gear=8 the seven segment shows 8 (PORTB = 127) and is the code correct....
Hi , i am making gear indicator, but i cant make the code work properly... i am new to MicroC so i need some help.I am using 7 segment common cathode display and two buttons ,the buttons are connected to PORTA and the 7segment is connected to PORTB. the code i am using is this...
Code:
/*Header******************************************************/
unsigned short gear, memo ; // Define variables
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
PORTB = 0; // Initial state of port B
TRISB = 0; // All port B 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
gear = memo; // save the new value
PORTB = gear; // and show it on port B
}
Delay_ms(200); // 200mS delay
}
}
I dont know how to make it if gear=8 the seven segment shows 8 (PORTB = 127) and is the code correct....