That's strange why you can't properly post code. I don't know why that is. Allow me:
Code:
bit button_up = 0;
bit toggle = 0;
void main(void)
{
TRISB = 0X00; //trisb input
TRISC = 0X00;//trisc output
TRISD = 0XFF;//trisd output
for (;;)
{
if (RD0 == 1) //if its not pressed then
button_up == 1;//button up is assigned 1
else
{
if (button_up == 1)
{
button_up = 0;
toggle = !toggle;
RB0 = toggle;//GREEN ON LIGHT 1
RC2 = toggle;//RED ON LIGHT 2
}
}
}
}
You implemented the switch/flag concept well - good job on that!
Now you just have to flesh out the light changing routine. As of now, it only toggles between two states. The "toggle" method you currently have probably is not be best way to go about it, since there are several (more than two) distinct states.
There are many possible ways for you to approach this. I would again recommend the FSM (Finite State Machine, not Flying Spaghetti Monster) I linked in post #3. You would have several possible "states", each with its own distinct value. Then a variable will contain the current "state" value, and you can determine the light configuration based on the value of the "state" variable.
A very generalized example might be as follows:
Code:
#define STATE_L1_G_L2_R 0 /* Light 1 GREEN, Light 2 RED */
#define STATE_L1_Y_L2_R 1 /* Light 1 YELLOW, Light 2 RED */
#define STATE_L1_R_L2_R 2 /* Light 1 RED, Light 2 RED */
#define STATE_L1_R_L2_G 3 /* Light 1 RED, Light 2 GREEN */
#define STATE_L1_R_L2_Y 4 /* Light 1 RED, Light 2 YELLOW */
#define STATE_L1_R_L2_R 5 /* Light 1 RED, Light 2 RED */
#define MAX_STATES 6
// ...
int state = STATE_L1_G_L2_R;
// if button press...
state++;
if(state == MAX_STATES)
state = STATE_L1_G_L2_R;
switch(state)
{
case STATE_L1_G_L2_R:
// set PORTB and PORTC values as needed
break;
case STATE_L1_Y_L2_R:
// set PORTB and PORTC values as needed
break;
// etc...
I gave a bit more code than I normally would, because I feel that in this instance, seeing a bit of the code would be a lot easier than trying to explain it in words. Don't rush off and try to copy/implement what I have without first making sure you fully understand the concept I've tried to illustrate.
You'd also have to take the second button into account - you'd use similar code as with the first button, but go the other way.
If this seems too complicated for you, let us know. There are easier, though more messy, solutions that exist - I'm just offering one I think is better overall.
If you need any clarifications on any of these points, please do not hesitate to ask.