Need help with my program

Hi,

I am new to Dynamic C and particularly cooperative multitasking.

I have an RCM 3720 prototyping board and need to write a program that pulses one of the protoboard LEDs on and off at specific intervals.

My problem is that I want to start and stop the pulsing from the second pushbutton which also turns on and off a “pilot” light. That is to say when the program starts, there is no “pilot” light and no flashing. When the user presses the pushbutton, the “pilot” light comes on and the other LED begins flashing at the predetermined rate. The led continues to flash until the pushbutton is pressed again, at which time, the “pilot” light goes out.

I have included the code that I have so far.

Any input would be appreciated.

Best Regards,
Allen


#define DS1 6 //led, port F bit 6
#define DS2 7 //led, port F bit 7
#define S1 4 //switch, port F bit 4
#define S2 7 //switch, port B bit 7
#define ON 0 //Set low to turn LED on
#define OFF 1 //Set high to turn LED off
#define PERIOD 10000L //Number of milliseconds for one cycle
#define DUTYCYCLE 50L //Duty cycle of waveform

///////////////////////////////////////////////////////////
// DS1 led on protoboard is controlled by port F bit 6
// turns on when port bit is set to 0
///////////////////////////////////////////////////////////
void pbledon(int led)
{
BitWrPortI(PFDR, &PFDRShadow, ON, led);
}

///////////////////////////////////////////////////////////
// DS1 led on protoboard is controlled by port F bit 6
// turns on when port bit is set to 0
///////////////////////////////////////////////////////////
void pbledoff(int led)
{
BitWrPortI(PFDR, &PFDRShadow, OFF, led);
}

///////////////////////////////////////////////////////////
// set DS1 and to stay on and off at intervals
///////////////////////////////////////////////////////////
cofunc flashled(int led, long ontime, long offtime, int go)
{
for(;:wink:
{
pbledon(led);
waitfor(DelayMs(ontime));
pbledoff(led);
waitfor(DelayMs(offtime));
}
}

main()
{
auto int sw1, sw2, led1, led2;
long ontime; //Time in milliseconds that the LED will be on
long offtime; //Time in milliseconds that the LED will be off

brdInit(); //initialize board for this demo

led1=led2=1; //initialize leds to off value
sw1=sw2=0; //initialize switches to false value

ontime = PERIOD * DUTYCYCLE / (long)100;
//On-time in milliseconds
offtime = PERIOD - ontime;
//Off-time in milliseconds

while (1)
{
costate
{
if (BitRdPortI(PBDR, S2)) abort;
//wait for switch S2 press

     waitfor(DelayMs(50));
     			
     //switch press detected if got to here
     if (BitRdPortI(PBDR, S2))
     //wait for switch release
     {
     sw2=!sw2;  //set valid switch
     abort;
     }
  }

  costate
  {
     // toggle DS2 upon valid S2 press/release and clear switch
     if (sw2)
        {
   BitWrPortI(PFDR, &PFDRShadow, led2=led2?0:1, DS2);
   sw2=!sw2;
}
     }

  costate
  {
     wfd
     {
flashled(DS1, ontime, offtime, sw2);
// Flashes DS1 on for ontime and off for offtime
     }
  }

}
}