void main()
{
   char s[40];
	int encoder_state;
   word count;

   // Initialize the controller
	brdInit();

   // Configure digital outputs to simulate quadrature encoder output
	setDigOut(LED1, 1);
   setDigOut(LED2, 1);

	// Configure quadrature encoder input
   setDecoder(QUAD_I, QUAD_Q, -1, 0);

   // Configure digital inputs for switches
   setDigIn(SW1);
   setDigIn(SW2);
   setDigIn(SW3);

   // initialize outputs to low
   encoder_state = 0;
	simulate_encoder(encoder_state);

   // reset quadrature decoder counter
   resetCounter(QUAD_I);

	DispStr(2, 1, "<<< Simulating a Quadrature Encoder with button presses >>>");
   DispStr(1, 3, "Press Button SW1 to decrement counter");
   DispStr(1, 4, "Press Button SW2 to increment counter");
   DispStr(1, 5, "Press Button SW3 to reset counter");

	while (1)
	{
   	costate
      {
       	// Display the counter value
         getCounter(QUAD_I, &count);
         sprintf(s, "Quadrature Decoder Count = %6u", count);
         DispStr(1, 7, s);
      }

      costate
      {
      	// decrement counter
			waitfor(!digIn(SW1)); 			// wait for switch 1 to be pressed
			waitfor(DelayMs(50));			// debounce
			if (!digIn(SW1)) {
	         --encoder_state;
	         if (encoder_state < 0)
	         {
	            encoder_state = 3;
	         }
	         simulate_encoder(encoder_state);
				waitfor(DelayMs(150));         // repeat when switch held down
         }
      }

      costate
      {
      	// increment counter
			waitfor(!digIn(SW2)); 			// wait for switch 2 to be pressed
			waitfor(DelayMs(50));			// debounce
			if (!digIn(SW2)) {
	         ++encoder_state;
	         if (encoder_state > 3)
	         {
	            encoder_state = 0;
	         }
	         simulate_encoder(encoder_state);
				waitfor(DelayMs(150));         // repeat when switch held down
         }
      }

      costate
      {
      	// reset counter
			waitfor(!digIn(SW3)); 			// wait for switch 3 to be pressed
			waitfor(DelayMs(50));			// debounce
         if (!digIn(SW3)) {
	         resetCounter(QUAD_I);      // reset quadrature decoder counter
	         waitfor(digIn(SW3));       // wait for switch 3 to be released
         }
      }
	}
}
void main ()
{
	auto unsigned int rawdata;
	auto int channel, keypress;
	auto int key;
	auto float voltage;
   auto char s[256];

   // The brdInit function is only used to configure the I/O
   // on the prototyping board and is not required for the A/D
   // library which will configure everything required to access
   // the A/D circuit.
	brdInit();

   // Step 5 for MUX control
   // Make sure is low when the line is enabled.
   WrPortI(PDDR,  &PDDRShadow,  (PDDRShadow  & ~0x20));

   // Set Function for I/O opeartion
   WrPortI(PDFR,  &PDFRShadow,  (PDFRShadow  & ~0x20));

   // Make PD5 an output
   WrPortI(PDDDR, &PDDDRShadow, (PDDDRShadow | 0x20));

   // Set PD5 for active high/low operation
   WrPortI(PDDCR, &PDDCRShadow, 0x00);

   // Set Port D to be CLK'd by PCLK/2
   WrPortI(PDCR,  &PDCRShadow,  0x00);
   // End of step

   // Initialize the A/D ramp circuit and low-level driver.
   anaInRampInit();

   // Initialize the core module to read external A/D circuit.
   anaInExternalInit(3, 2, 1);


   // Copy calibration data from ch0 to ch1, since we are simulating the
   // 2nd channel....must be done after executing anaInExternalInit.
   _adcCalib[1][0] = _adcCalib[0][0];
   _adcCalib[1][1] = _adcCalib[0][1];

   mux_conversion_done[0] = FALSE;
   mux_conversion_done[1] = FALSE;
	while (1)
	{
      blankScreen(0, 20);
		DispStr(1, 2,  "External A/D input voltage for channels 0 and 1");
		DispStr(1, 3,  "-----------------------------------------------");
      DispStr(1, 6,  "Press Q or q to exit program.");

    	while(1)
      {
   		// Notes:
      	// 1. The mux_conversion_done flag is predefined and will be set
   		// by the ADC low-level driver.
      	// 2. If the mux_conversion_done flag isn't used, and if you read
      	// the external A/D channel faster than the A/D conversion rate,
      	// then the data will be from the previous A/D conversion until a
      	// new A/D conversion is completed.
      	if(mux_conversion_done[0] && mux_conversion_done[1])
         {
            mux_conversion_done[0] = FALSE;
            mux_conversion_done[1] = FALSE;
            for(channel=0; channel < MAX_ADCHANNELS; channel++)
            {
            	voltage = anaInVolts(channel);
            	if(channel >= MAX_ADCHANNELS)
            		channel = 0;
            	if(voltage != ADOVERFLOW)
         			sprintf(s, "Voltage = %.3f               ", voltage);
            	else
               	sprintf(s, "Voltage = Exceeded Range!!!  ");
            	DispStr(1, channel + 4, s);
         	}
         }
         if(kbhit())
			{
				key = getchar();
				if (key == 'Q' || key == 'q')
				{
            	anaInDisable();
      			exit(0);
     			}
			}
      }
   }
}
Exemple #3
0
void main()
{
	auto int device0, status;
	auto char tmpbuf[24];
	auto int done, command;
   auto rn_search newdev;
   auto DacCal DacCalTable1;
   auto float voltout;
   auto int channel, selectChannel;
   auto int key;

	brdInit();		// Required for controllers
   rn_init(RN_PORTS, 1);      //initialize controller RN ports

   //search for device match
	newdev.flags = MATCHFLAG;
	newdev.productid = MATCHPID;
   if ((device0 = rn_find(&newdev)) == -1)
   {
   	printf("\n no device found\n");
      exit(0);
   }

	for(;;)
	{
   	blankScreen(0, 28);

		DispStr(2, 2, "DAC Board   CH0&1   CH2-7 ");
		DispStr(2, 3, "--------------------------");

		DispStr(2, 4, "Config = 0  2.5v    10v");
		DispStr(2, 5, "Config = 1  5.0v    10v");
		DispStr(2, 6, "Config = 2  10v     10v");
		DispStr(2, 7, "Config = 3  5v      20v");
		DispStr(2, 8, "Config = 4  10v     20v");
		DispStr(2, 9, "Config = 5  20v     20v");
		DispStr(2, 10, "Please enter the DAC configuration 0 - 5....");
		do
		{
			command = getchar();
		} while (!((command >= '0') && (command <= '5')));
		printf("Config  = %d", command-=0x30);
      rn_anaOutConfig(device0, command, 1, 0);
      for(channel=0; channel < 8; channel++)
      {
      	rn_anaOutRdCalib(device0, channel, &DacCalTable1, 0);
      }


     	done = FALSE;
      selectChannel = TRUE;
		while (!done)
		{
         if(selectChannel)
         {
         	DispStr(2, 12, "DAC0 - DAC7 Voltage Out Program");
				DispStr(2, 13, "-------------------------------");
				DispStr(2, 14, "Please enter an output channel (0 - 7) = ");
				do
				{
		  			channel = getchar();
				} while (!((channel >= '0') && (channel <= '7')));
				printf("%d", channel-=0x30);
            selectChannel = FALSE;
        	}

         // display DAC voltage message
			DispStr(2, 16, "Type a desired voltage (in Volts) =  ");

			// get user voltage value for the DAC thats being monitored
			voltout = atof(gets(tmpbuf));

 			// send voltage value to DAC for it to output the voltage
     		rn_anaOutVolts(device0, channel,  voltout, &DacCalTable1, 0);

 			// display user options
			DispStr(2, 19, "User Options:");
			DispStr(2, 20, "-------------");
			DispStr(2, 21, "1. Write voltage value to DAC channel (internal register)");
         DispStr(2, 22, "2. Strobe DAC chip, all DAC channels will be updated");
         DispStr(2, 23, "3. Change to another DAC channel");
			DispStr(2, 24, "4. Change overall DAC output configuration");
			DispStr(2, 25, "5. Exit Program");

         DispStr(2, 28, "Note: Must strobe DAC for outputs to be updated!");
         while(1)
			{
				// wait for a key to be pressed
				while(!kbhit());
				key = getchar();
            if(key == '1')
				{
   				// empty the keyboard buffer and clear user options
   				while(kbhit()) getchar();
               blankScreen(16, 28);
   				break;
   			}

            if(key == '2')
				{
   				// empty the keyboard buffer and clear user options
   				while(kbhit()) getchar();
               rn_anaOutStrobe(device0, 0);
               DispStr(2, 27, "DAC outputs have been updated");
               msDelay(1000);
               DispStr(2, 27, "                                ");
   			}

            if(key == '3')
				{
   				// empty the keyboard buffer and clear user options
   				while(kbhit()) getchar();
               blankScreen(12, 28);
               selectChannel = TRUE;
   				break;
   			}

				if(key == '4')
				{
					// exit while loop and clear previous calibration infor
					done = TRUE;
  					blankScreen(15, 28);
					// empty keyboard buffer
					while(kbhit()) getchar();
					break;
				}
				if (key == '5')		// check if it's the q or Q key
				{
					// exit sample program
     				exit(0);
   			}
			}
		}
	}
}
void main ()
{
    auto long value1, value2;
    auto unsigned int rawdata;
    auto int channel, gaincode;
    auto int key, i;
    auto float voltage, volts1, volts2, cal_voltage;
    auto char buffer[64];

    // Initialize the controller
    brdInit();

    // Configure channel pair 0 & 1 for Single-Ended bipolar mode of operation.
    // (Max voltage range is �V)
    anaInConfig(0, SE1_MODE);

    // Configure channel pair 2 & 3 for Single-Ended bipolar mode of operation
    // (Max voltage range is �V)
    anaInConfig(1, SE1_MODE);

    // Configure channel pair 4 & 5 for Single-Ended bipolar mode of operation
    // (Max voltage range is �V)
    anaInConfig(2, SE1_MODE);

    // Configure channel pair 6 & 7 for Single-Ended bipolar mode of operation
    // (Max voltage range is �V)
    anaInConfig(3, SE1_MODE);

    while(1)
    {
        DispStr(1, 1,"!!!Caution this will overwrite the calibration constants set at the factory.");
        DispStr(1, 2,"Do you want to continue(Y/N)?");

        while(!kbhit());
        key = getchar();
        if(key == 'Y' || key == 'y')
        {
            break;
        }
        else if(key == 'N' || key == 'n')
        {
            exit(0);
        }

    }
    while(kbhit()) getchar();

    while (1)
    {
        printf("\n\nPlease enter an ADC channel, 0 thru 7....");
        do
        {
            channel = getchar();
        } while (!( (channel >= '0') && (channel <= '7')) );
        channel = channel - 0x30;
        printf("%d", channel);
        while(kbhit()) getchar();


        printrange();
        printf("\nChoose gain code .... ");
        do
        {
            gaincode = getchar();
        } while (!( (gaincode >= '0') && (gaincode <= '5')) );
        gaincode = gaincode - 0x30;
        printf("%d", gaincode);
        while(kbhit()) getchar();

        cal_voltage = vmax[gaincode]*.8;
        printf("\nAdjust Power connected to AIN%d to approx. %.2f\n", channel, cal_voltage);
        printf("and then enter actual voltage = ");
        gets(buffer);

        volts1 = atof(buffer);
        value1 = 0;
        for(i=0; i<10; i++)
            value1 += anaIn(channel, gaincode);
        value1 = value1/10;
        printf("Hi:  channel=%d raw=%d\n", channel, value1);


        printf("\nSwap power supply connections and then PRESS any key\n");
        while(!kbhit());
        while(kbhit()) getchar();

        volts2 = -volts1;
        value2 = 0;
        for(i=0; i<10; i++)
            value2 += anaIn(channel, gaincode);
        value2 = value2/10;
        printf("Lo:  channel=%d raw=%d\n", channel, value2);

        anaInCalib(channel, SE1_MODE, gaincode,
                   (int) value1, volts1, (int) value2, volts2);

        printf("\nVary voltage within the range selected.... \n");
        do
        {
            voltage = anaInVolts(channel, gaincode);
            printf("Ch %2d Volt=%.4f \n", channel, voltage);
            printf("Press ENTER key to read values again or 'Q' to calibrate another channel\n\n");
            while(!kbhit());
            key = getchar();
            while(kbhit()) getchar();
        } while(key != 'q' && key != 'Q');
    }
}
Exemple #5
0
void main ()
{
	auto long average;
	auto unsigned int rawdata;
	auto int channel, gaincode;
	auto int key, i;
	auto float voltage, cal_voltage;
	auto char buffer[64];

	
	brdInit();	
	while(1)
	{
		DispStr(1, 1,"!!!Caution this will overwrite the calibration constants set at the factory.");
		DispStr(1, 2,"Do you want to continue(Y/N)?");  

		while(!kbhit());
		key = getchar();
		if(key == 'Y' || key == 'y')
		{		
			break;
		}
		else if(key == 'N' || key == 'n')
		{
			exit(0);
		}		
	}
	
	while (1)
	{
		printrange();
		printf("\nChoose gain code .... ");
		do
		{
			gaincode = getchar();
		} while (!( (gaincode >= '0') && (gaincode <= '7')) );
		gaincode = gaincode - 0x30;
		printf("%d", gaincode);
		while(kbhit()) getchar();
		
		cal_voltage = .1*vmax[gaincode];
		printf("\nAdjust to approx. %.4f and then enter actual voltage = ", cal_voltage);
		gets(buffer);
		for (channel=STARTCHAN; channel<=ENDCHAN; channel++)
		{
			ln[channel].volts1 = atof(buffer);
			average = 0;
			for(i=0; i<10; i++)
				average += anaIn(channel, SE_MODE, gaincode);
			ln[channel].value1 = (int)average/10;
			printf("lo:  channel=%d raw=%d\n", channel, ln[channel].value1);
		}
		while(kbhit()) getchar();
	
		cal_voltage = .9*vmax[gaincode];
		printf("\nAdjust to approx. %.4f and then enter actual voltage = ", cal_voltage);
		gets(buffer);
		for (channel=STARTCHAN; channel<=ENDCHAN; channel++)
		{
			ln[channel].volts2 = atof(buffer);
			average = 0;
			for(i=0; i<10; i++)
				average += anaIn(channel, SE_MODE, gaincode);
			ln[channel].value2 = (int)average/10;
			printf("hi:  channel=%d raw=%d\n", channel, ln[channel].value2);
		}
		while(kbhit()) getchar();
			
		for (channel=STARTCHAN; channel<=ENDCHAN; channel++)
		{
 			anaInCalib(channel, SE_MODE, gaincode, ln[channel].value1, ln[channel].volts1,
 			                                       ln[channel].value2, ln[channel].volts2);
		}
		
		printf("\nstore constants to flash\n");
		for (channel=STARTCHAN; channel<=ENDCHAN; channel++)
		{
			anaInEEWr(channel, SE_MODE, gaincode);				//store all channels
		}
		
		printf("\nread back constants\n");
		anaInEERd(ALL_CHANNELS, SE_MODE, gaincode);				//read all channels
		
		printf("\nVary voltage within the range selected\n");
		
		do 
		{
			for (channel=STARTCHAN; channel<=ENDCHAN; channel++)
			{
				voltage = anaInVolts(channel, gaincode);
				printf("Ch %2d Volt=%.5f \n", channel, voltage);
			}
			printf("Press ENTER key to read values again or 'Q' to calibrate another gain\n\n");
			while(!kbhit());
			key = getchar();
			while(kbhit()) getchar();
			
		}while(key != 'q' && key != 'Q');
	}            
}
Exemple #6
0
void main()
{

	auto char s[128];
	auto char display[128];
	auto char channels[8];
	auto int output_status, channel;
	auto int output_level;
	auto unsigned int outputChannel;

	brdInit();				//initialize board for this demo

	// Display user instructions and channel headings
	DispStr(8, 2, "<<< Proto-board LED's   >>>");
	DispStr(8, 4, "DS1\tDS2");
	DispStr(8, 5, "-----\t-----");

	DispStr(8, 10, "From PC keyboard:");
	DispStr(8, 21, "< Press 'Q' To Quit >");

	for(channel = DS1; channel <=DS2 ; channel++)
	{
		channels[channel] = 1;		// Indicate output is OFF
		digOut(channel, 1);
	}

	// Loop until user presses the upper/lower case "Q" key
	for(;;)
	{
		// Update high current outputs
		display[0] = '\0';								//initialize for strcat function
		for(channel = DS1; channel <= DS2; channel++)	//output to DS1 and DS2 only
		{
			output_level = channels[channel];		//output logic level to channel
			digOut(channel, output_level);
			sprintf(s, "%s\t", output_level?"OFF":"ON");		//format logic level for display
			strcat(display,s);							//add to display string
		}
		DispStr(8, 6, display);							//update output status

		// Wait for user to make output channel selection or exit program
		sprintf(display, "Select 1=DS1 or 2=DS2 to toggle LED's");
		DispStr(8, 12, display);
     	do
		{
			channel = getchar();
			if (channel == 'Q' || channel == 'q')		// check if it's the q or Q key
			{
      		exit(0);
     		}
     		channel = channel - 0x30;		// convert ascii to integer
		} while (!((channel >= DS1) && (channel <= DS2)));

		// Display the channel that the user has selected
		sprintf(display, "Selected DS%d to toggle               ", channel);
		DispStr(8, 12, display);

		// Wait for user to select logic level or exit program
		sprintf(display, "Select 1=OFF or 0=ON");
		DispStr(8, 13, display);
		do
		{
			output_level = getchar();
			if (output_level == 'Q' || output_level == 'q')		// check if it's the q or Q key
			{
      		exit(0);
     		}
     		output_level = output_level - 0x30;
		} while (!((output_level >= 0) && (output_level <= 1)));
		sprintf(display, "Selected %s         ", output_level?"OFF":"ON");
     	DispStr(8, 13, display);
     	channels[channel] = output_level;

  		// Clear channel and logic level selection prompts
  		DispStr(8, 12, "                                                  ");
  		DispStr(8, 13, "                                                  ");
   }
}
Exemple #7
0
void main()
{
   auto int c, num_bytes, done;
   auto char *ptr;
	auto int parallel_counter, loop_counter;
	auto char buffer[256];
	auto char s[256];
   

	brdInit();		//required for BL2100 series boards
		
	c = 0;			//initialize variables
	parallel_counter = 0;
	loop_counter	  = 0;
	done				  = FALSE;

	sprintf(s, "Character counter = %d", 0);	//initialize for proper STDIO effects
   DispStr(2, 2, s);

   // display exit message
   DispStr(2, 5, "Press the ESC key in Hyperterminal to exit the program");
   
	serCopen(BAUD_RATE);	//set baud rates for the serial ports to be used
   serBopen(BAUD_RATE);
   
	serCwrFlush();		//clear Rx and Tx data buffers 
	serCrdFlush();

	serBwrFlush();		
	serBrdFlush();
   
   serMode(0);			//required for BL2100 series bds...must be done after serXopen function(s)
 
   while (!done) {
               
   	loophead();			//required for single-user cofunctions
   	
   	costate				//single-user serial cofunctions 
   	{
   		// Wait for char from hyperterminal
	      wfd c = cof_serBgetc(); // yields until successfully getting a character

			//do clean exit from costatement
	      if(c == ESC)
   	   {
   	   	//flag used to exit out of this WHILE loop and other costatements
				done = TRUE;
				
				//abort this costatement
				abort;		
   	   }

	      // send character to serial port C
   	   wfd cof_serBputc(c);    // yields until c successfully put

   	   // wait for char from serial port C
   	   wfd c = cof_serCgetc(); // yields until successfully getting a character

   	   //send character back to hyperterminal
   	   wfd cof_serCputc(c);    // yields until c successfully put

   	   waitfor(serCwrUsed() == 0);
   	   
   	   //demonstrates that the above cofunctions only yields to other costates
   	   //and not to the code within the same costatement section.
   	   sprintf(s, "Character counter = %d", ++loop_counter);
   	   DispStr(2, 2, s);
      }
      costate
      {
      	// Abort this costatement if the done flag has been set
      	if(done)
   	   {
				abort;	//do clean exit of costatement
   	   }
			//execute code while waiting for characters from hyperterminal
			sprintf(s, "Parallel code execution counter = %d\r", parallel_counter++);
			DispStr(2, 3, s);
      }
   }
   
   // send program exit message
   serBputs("\n\n\rProgram Done...exiting");
   
   // wait for memory data buffer, serial holding register, and shift
   // register all to become empty
   while (serBwrFree() != BOUTBUFSIZE);
   while((RdPortI(SBSR)&0x08) || (RdPortI(SBSR)&0x04));

	// read data and send to hyperterminal
   num_bytes = serCread(buffer, sizeof(buffer), 5);
   buffer[num_bytes] = '\0';
	serCwrite(buffer, strlen(buffer));
	
   // wait for memory data buffer, serial holding register, and shift
   // register all to become empty
   while (serCwrFree() != COUTBUFSIZE);
   while((RdPortI(SCSR)&0x08) || (RdPortI(SCSR)&0x04));
 
   //close the serial ports
   serCclose();
   serBclose();
}
main()
{
   auto int device0;
   auto rn_search newdev;
   auto char s[128];
   auto int counter, i, option;

   // Array locations 0 - 5 used to indicate what state relays
   // 0 - 5 are in, here's the possible states.
   // -----------------------------------------
   //  0 = Relay OFF...no action to be taken
   //  1 = Request for relay to be activated
   //  2 = Relay actvated...no action to be taken.
   //  3 = Request for relay to be deactivated.
	//
   // The user will select a menu option which set the memory
   // locations 0 - 5 with the desired relay state. The main
   // program will detect when a change occurs in the memory
   // array, which will then update the relay(s) with the new
   // Relay state.

   auto char CurrentRelayState[6];
   auto char NewRelayState[6];
   auto int relay_control_update;
   auto int relay;

	brdInit();                 //initialize controller
   rn_init(RN_PORTS, 1);      //initialize controller RN ports

   //search for device match
	newdev.flags = MATCHFLAG;
	newdev.productid = MATCHPID;
   if ((device0 = rn_find(&newdev)) == -1)
   {
   	printf("\n no device found\n");
      exit(0);
   }

  	//Display user instructions and channel headings
  	DispStr(2, 1, "<<< Relay Control Menu >>>");
   DispStr(2, 2, "--------------------------");
   DispStr(2, 3, "1.Sequence Relays 0, 2, and 4 ON, set all others OFF.");
   DispStr(2, 4, "2.Sequence Relays 0, 1, 3, and 5 ON, set all others OFF.");
   DispStr(2, 5, "3.Sequence All Relays ON.");
   DispStr(2, 6, "4.Sequence All Relays OFF.");

   counter = 0;
   relay_control_update = FALSE;
   memset(CurrentRelayState, 0x00, 6);
   memset(NewRelayState, 0x00, 6);

   for(;;)
   {

   	costate
      {
      	sprintf(s,"Application program is running, counter = %d", counter++);
      	DispStr(2, 10, s);

      }
   	costate
   	{
         if(kbhit())
         {
            option = getchar();
           	set_relay_state(option, &CurrentRelayState[0], &relay_control_update);
         }
         waitfor(DelayMs(10));
      }
      costate
      {
      	if(relay_control_update)
         {
         	for(relay=0; relay < 6; relay++)
            {
            	if(NewRelayState[relay] == 1)
               {
               	// Activate given relay, then wait for 50ms
                  rn_Relay(device0, relay, 1, 0);
                  NewRelayState[relay] = RELAY_IS_ON;
                  CurrentRelayState[relay] = RELAY_IS_ON;
                  // Wait for relay to stabilize
                  waitfor(DelayMs(50));
               }
               else if(NewRelayState[relay] == 3)
               {
               	// Deactivate relay, then wait for 5ms
                  rn_Relay(device0, relay, 0, 0);
                  NewRelayState[relay] = RELAY_IS_OFF;
                  CurrentRelayState[relay] = RELAY_IS_OFF;
                  // Wait for relay power OFF completely
                  waitfor(DelayMs(50));
               }
        		}
            relay_control_update = FALSE;
         }
         else
         {
         	if(memcmp(CurrentRelayState,NewRelayState, 6) != 0)
   			{
          		memcpy(NewRelayState, CurrentRelayState, 6);
          		relay_control_update = TRUE;
         	}
         }
      }
   }
}
Exemple #9
0
main()
{
	auto int key, i;
   auto int triac_cntrl0, triac_cntrl1;
	auto int increment, decrement;
   auto int triac;
   auto char s[256];

   // The brdInit function is only used to configure the I/O
   // on the prototyping board and is not required for the triac
   // library which will configure everything required for triac
   // control.
   brdInit();

   triac_TimePropInit(1, 3);
   triac_TimePropCntrlPin(0, PFDR, 2, 0);
   triac_TimePropCntrlPin(1, PFDR, 3, 0);
   triac_cntrl0 = 0;
   triac_cntrl1 = 0;
   triac = 0;

   DispStr(1, 1,  "Triac Status");
   DispStr(1, 2,  "------------");
   sprintf(s,"Triac 0 ON/OFF ratio = %d/10", triac_cntrl0);
   DispStr(1, 3, s);

   sprintf(s,"Triac 1 ON/OFF ratio = %d/5", triac_cntrl1);
   DispStr(1, 4, s);
   sprintf(s,"Triac selected = %d", triac);
   DispStr(1, 5, s);

   DispStr(1, 7,  "Triac control Menu");
	DispStr(1, 8,  "------------------");
   DispStr(1, 9,  "1. Select triac 0 for control");
   DispStr(1, 10, "2. Select triac 1 for control");
	DispStr(1, 11, "3. Increment number of ON cycles");
	DispStr(1, 12, "4. Decrement number of ON cycles");
   DispStr(1, 13, "Select Option 1 - 4 > ");

	while (1)
	{
      costate
      {
      	switch(triac)
         {
         	case 0:
      			triac_TimePropCntrl(0, triac_cntrl0, 10);
               break;

            case 1:
               triac_TimePropCntrl(1, triac_cntrl1, 5);
               break;
         }
      }
		costate
		{
         if(kbhit())
			{
				key = getchar();
            while(kbhit()) getchar();
            msDelay(500);
            if( key >= '0' && key <='4')
				{
            	sprintf(s, "Select Option 1 - 4 > %c  ", key);
            	DispStr(1, 13, s);
				}
            switch(key)
            {
            	case '1':
               	triac = 0;
                  break;

               case '2':
               	triac = 1;
               	break;

               case '3':
               	switch(triac)
               	{
                		case 0:
                        if(triac_cntrl0 < 10)
                        	triac_cntrl0++;
                     	break;

                  	case 1:
                     	if(triac_cntrl1 < 5)
                  			triac_cntrl1++;
                     	break;
               	}
                  break;

               case '4':
             		switch(triac)
               	{
                		case 0:
                   		if (triac_cntrl0 > 0 )
                        	triac_cntrl0--;
                     	break;
                  	case 1:
                  		if (triac_cntrl1 > 0 )
                        	triac_cntrl1--;
                    	 	break;
               	}
                  break;


     			}
            sprintf(s,"Triac 0 ON/OFF ratio = %d/10   ", triac_cntrl0);
   			DispStr(1, 3, s);
         	sprintf(s,"Triac 1 ON/OFF ratio = %d/5    ", triac_cntrl1);
   			DispStr(1, 4, s);
         	sprintf(s,"Triac selected = %d", triac);
   			DispStr(1, 5, s);
			}
   	}
	}
}
Exemple #10
0
nodebug void InitDisplay()
{

	DispStr(0, 1, "                             uC/OS-II Task Deletion                               ");
	DispStr(0, 2, "                            ------------------------                              ");

	DispStr(0,  4, " Task Status:                                                                    ");
	DispStr(0,  5, " ------------                                                                    ");
   DispStr(0,  6, " t00 t01 t02 t03 t04 t05 t06 t07 t08 t09 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 ");
   DispStr(0,  7, "                                                                                 ");

   DispStr(0,  9, " t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 ");
   DispStr(0, 10, "                                                                                 ");

   DispStr(0, 12, " t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57 t58 t59 ");
   DispStr(0, 13, "                                                                                 ");

	DispStr(0, 15, "  r = running/ready                                                              ");
	DispStr(0, 16, "  d = deleted                                                                    ");
   DispStr(0, 18, " System Statistics:                                                              ");
   DispStr(0, 19, " ------------------                                                              ");
}
Exemple #11
0
/*输出说明:
*	k 关键字
*	v 标识符
*	n 常数
*	+-/*= 自身
*识别成功则将其储存在out中
*忽略空格
*/
bool lex(FILE * in, char * out)
{
	char newchar;
	SqString word;
	int oindex = 0;

	printf("类型\t单词符号\n");

	newchar = getc(in);

	while (newchar != EOF)																/*读入字符,分析类型*/
	{
		if (newchar >= 'a' && newchar <= 'z')											/*检测关键词or标识符*/
		{
			int i = 0;
			do{
				if (i < WordMax)
				{
					word.data[i] = newchar;
					i++;
				}
				newchar = getc(in);
			} while ((newchar >= 'a' && newchar <= 'z') || (newchar >= '0' && newchar <= '9'));
			word.length = i;
			if (is_Keyword(word.data))
			{
				printf("关键词\t");
				DispStr(word);
				out[oindex] = 'k';
				oindex++;
				continue;
			}
			else
			{
				printf("标识符\t");
				DispStr(word);
				out[oindex] = 'v';
				oindex++;
				continue;
			}
		}

		else if (newchar == ' ' || newchar == '\n' || newchar == '\t')					/*检测空格*/
		{
			newchar = getc(in);
			continue;
		}

		else if (newchar >= '0' && newchar <= '9')
		{
			int i = 0;
			do{																			/*检测常数*/
				if (i < WordMax)
				{
					word.data[i] = newchar;
					i++;
				}
				newchar = getc(in);
			} while (newchar >= '0' && newchar <= '9');
			word.length = i;
			printf("常数\t");
			DispStr(word); 
			out[oindex] = 'n';
			oindex++;
			continue;
		}

		else if (newchar == '(' || newchar == ')')	/*检测界符*/
		{
			out[oindex] = newchar;
			oindex++;
			printf("界符\t%c\n", newchar);
			newchar = getc(in);
			continue;
		}

		else if (newchar == '+' || newchar == '-' || newchar == '*' || newchar == '/' || newchar == '=')		/*检测运算符*/
		{
			out[oindex] = newchar;
			oindex++;
			printf("运算符\t%c\n", newchar);
			newchar = getc(in);
			continue;
		}

		else																				/*无效字符*/
		{
			printf("无效字符\t%c\n输入说明:\n\t只能输入关键词 标识符 常数 +-*/=\n", newchar);
			return false;
		}
	}
	out[oindex] = '#';
	return true;
}
Exemple #12
0
void main ()
{
	auto int device0, status;
	auto char buffer[64];
   auto rn_search newdev;
   auto rn_AinData aindata;
   auto float voltage, cal_voltage;
	auto int rawdata;
   auto int gaincode;
   auto int data1, data2;
   auto int channel;
   auto int key;


	brdInit();
   rn_init(RN_PORTS, 1);      //initialize controller RN ports

   //search for device match
	newdev.flags = MATCHFLAG;
	newdev.productid = MATCHPID;
   if ((device0 = rn_find(&newdev)) == -1)
   {
   	printf("\n no device found\n");
      exit(0);
   }

   while(1)
	{
		DispStr(1, 1,"!!!Caution this will overwrite the calibration constants set at the factory.");
		DispStr(1, 2,"Do you want to continue(Y/N)?");

		while(!kbhit());
		key = getchar();
		if(key == 'Y' || key == 'y')
		{
			break;
		}
		else if(key == 'N' || key == 'n')
		{
			exit(0);
		}

	}
	printf("\n");
	while(kbhit()) getchar();

   while (1)
	{
		// display the voltage that was read on the A/D channels
   	printrange();
		printf("\nChoose Voltage Configuration for the ADC Board 0 - 7.... ");
		do
		{
			gaincode = getchar();
		} while (!( (gaincode >= '0') && (gaincode <= '7')) );
		gaincode = gaincode - 0x30;
		printf("%d", gaincode);
		while(kbhit()) getchar();

	   // enable on all channels for conversions
		for(channel = 0; channel < 8; channel++)
		{
			status = rn_anaInConfig(device0, channel, RNSINGLE, gaincode, 0);
	   }

     	cal_voltage = .1*vmax[gaincode];
		printf("\nAdjust to approx. %.4f and then enter actual voltage = ", cal_voltage);
		gets(buffer);
		for (channel=0; channel < 8; channel++)
		{
			ln[channel].volts1 = atof(buffer);
			status = rn_anaIn(device0, channel, &data1, NUMSAMPLES, 0);
			ln[channel].value1 = data1;
			if (ln[channel].value1 == ADOVERFLOW)
				printf("lo:  channel=%d overflow\n", channel);
			else
				printf("lo:  channel=%d raw=%d\n", channel, ln[channel].value1);
		}

   	cal_voltage = .9*vmax[gaincode];
		printf("\nAdjust to approx. %.4f and then enter actual voltage = ", cal_voltage);
		gets(buffer);
		for (channel=0; channel < 8; channel++)
		{
			ln[channel].volts2 = atof(buffer);
			status = rn_anaIn(device0, channel, &data2, NUMSAMPLES, 0);
			ln[channel].value2 = data2;
			if (ln[channel].value2 == ADOVERFLOW)
				printf("hi:  channel=%d overflow\n", channel);
			else
				printf("hi:  channel=%d raw=%d\n", channel, ln[channel].value2);
		}

		printf("\nstore all constants to flash\n");
		for (channel=0; channel < 8; channel++)
		{
 			rn_anaInCalib(channel, RNSINGLE, gaincode, ln[channel].value1,
         	ln[channel].volts1,ln[channel].value2, ln[channel].volts2, &aindata);
	   	printf("gain=%8.5f offset=%d\n", aindata.gain, aindata.offset);
			status = rn_anaInWrCalib(device0, channel, RNSINGLE, gaincode, aindata, 0);
		}

		printf("\nread back constants\n");
		for (channel=0; channel < 8; channel++)
		{
			status = rn_anaInRdCalib(device0, channel, RNSINGLE, gaincode, &aindata, 0);
   		printf("read back gain=%8.5f offset=%d\n", aindata.gain, aindata.offset);
		}

      //After writing constants to flash, you must hard reset to close
      // off flash writes.  Wait 1 second to make sure device reinitializes
      // and clear the reset register.
      rn_reset(device0, 0);
      rn_msDelay(1000);

      //Check and clear reset status
      if(!((status = rn_rst_status(device0, buffer)) & 0x01))
     	{
      	printf("Error! ADC board didn't reset");
         exit(1);
      }
     	status =  rn_enable_wdt(device0, 1);  //enable device hardware watchdog

	   // Must enable on all channels for conversions again after reset
		for(channel = 0; channel < 8; channel++)
		{
			status = rn_anaInConfig(device0, channel, RNSINGLE, gaincode, 0);
	   }
  		printf("\nVary power supply for the voltage range selected.... \n\n");
		do
		{
      	for(channel = 0; channel < 8; channel++)
         {
         	status = rn_anaInVolts(device0, channel, &voltage, NUMSAMPLES, 0);
				printf("Ch %2d Volt=%.5f \n", channel, voltage);
         }
			printf("Press ENTER key to read value again or 'Q' to select another gain option\n\n");
			while(!kbhit());
			key = getchar();
			while(kbhit()) getchar();

		}while(key != 'q' && key != 'Q');
	}
}
Exemple #13
0
void main()
{
	auto int i;
   auto float temperature;
   auto char s[256];
   auto int key;
   auto int calib;
   auto int temp_units;

	// Initialize the I/O on the RabbitFLEX SBC40 board
	brdInit();

   while(1)
	{
		DispStr(1, 1,"!!!Caution this will overwrite the offset constant set at the factory.");
		DispStr(1, 2,"Do you want to continue(Y/N)?");
      while(!kbhit());
		key = getchar();
		if(key == 'Y' || key == 'y')
		{
      	calib = TRUE;
			break;
		}
		else if(key == 'N' || key == 'n')
		{
         calib = FALSE;
			break;
		}
	}
	while(kbhit()) getchar();
   if(calib)
   {
   	printf("\n\n");
      printf(" Select unit type you will be entering\n");
      printf(" -------------------------------------\n");
      printf(" 0 = Celsius\n");
      printf(" 1 = Fahrenheit\n");
      printf(" 2 = Kelvin\n");
		printf(" Select (0-2) =  ");
		do
		{
			temp_units = getchar();
		} while (!( (temp_units >= '0') && (temp_units <= '2')) );
		temp_units = temp_units - 0x30;
		printf("%d\n\n", temp_units);

		while(kbhit()) getchar();
		printf(" Enter the value from your temperature reference = ");
		gets(s);
		while(kbhit()) getchar();
		temperature = atof(s);

      // Create temperature offset constant and then write to flash.
      thermOffset(temp_units, temperature);
   }
   printf(" Thermistor adjustment completed...\n");
   printf(" Now display temperature continually...\n\n\n");
   while(1)
   {
     	sprintf(s, " Celsius=%.1f Fahrenheit=%.1f Kelvin=%.1f  \r",
      		  thermReading(0), thermReading(1), thermReading(2));
      printf("%s", s);
	}
}
Exemple #14
0
///////////////////////////////////////////////////////////////
//							File List
///////////////////////////////////////////////////////////////
int SelectPMFile (char * file_name)  //*SelectPMFile*
// -1 no file , 1 complate ,0 cancel
{
	int key;
	char str[50]; //字符数组长度下标从0开始,共50个元素
	FONTCHARACTER find_path[50];   //获得路径
	FONTCHARACTER find_name[50];   //获得名字
	int find_h;
	int size = 0;
	int top = 0;
	int buttom = 0;
	int index,r,y;
	char *files;
	FILE_INFO file_info;
//	CharToFont("\\\\fls0\\JDF\\*.pm",find_path); //*pm*
	sprintf(str,"%s\\*.pm",szPMDir); //*pm*
	PMCharToFont(str,find_path);
	if(Bfile_FindFirst (find_path,&find_h,find_name,&file_info)==0)  //函数搜索目录中文件的名称符合指定的文件名
	{
		int i=0,ret;
		BOOL bFindFirst=TRUE; //定义一个布尔型变量初始化为真(true),对于bool类型,值只要不是0就是为真,即true;当值为0时为假,即false;
		size ++;  //使用size之后再加一(先计算再操作)
		while(Bfile_FindNext(find_h,find_name,&file_info)==0) //Bfile_FindNext 函数使用搜索处理定位匹配一个给定名称的文件名称。
		size++;
		Bfile_FindClose(find_h);  //Bfile_FindClose 关闭搜索指定处理函数
		files = (char*)malloc(size*13);
		index = 0;
		for(;;)
		{
			if(bFindFirst)  //if 值为真
				ret=Bfile_FindFirst (find_path,&find_h,find_name,&file_info);
			else 
				ret=Bfile_FindNext(find_h,find_name,&file_info);
			if(ret!=0)  //if 
				break;
			strncpy((files+13*i),PMFontToChar(find_name,str),13);
			if(strcmp((files+13*i),setup_data.pmroute_name)==0) //文件选中后,现在记忆位置
			index=i; 
			i++;
			bFindFirst=FALSE;  //令值为假 即=0
		}
		Bfile_FindClose(find_h);  //Bfile_FindClose 关闭搜索指定处理函数
		r = 1;
		top = 0;
		buttom = 4;
		while(1)   
		{
			if (r)
			{
				Bdisp_AllClr_VRAM();
				//PopUpWin(6);
				DispStr(20,8,"线元参数文件: ");
				if (buttom-top>3)buttom = top + 3;
				if(top>index)
				{
					top = index;
					buttom = index + 3;
				}
				if (index>buttom)
				{
					buttom = index;
					top = buttom - 3;
				}
				if(buttom>size - 1)buttom = size - 1;
				if(top<0) top = 0;
				for (i=top;i<=buttom;++i)
				{
					//sprintf(str,"%13.13s",(files+13*i));
					//y=2+(i-top)*13;   //顶部文件位置
					//SetMyFont(&stHz12x12,&stAsc6x12);
					//DispStr(18,y,str); //str[]是字符串
					//if(index==i)
					//Bdisp_AreaReverseVRAM(15,y,20+13*6,y+11);
				    PrintfXY(20,22+(i-top)*8,index==i,"%13.13s",(files+13*i));
				}
				PrintXY(100,22,top>0?"\xE6\x92":" ",0);
				PrintXY(100,46,buttom<size-1?"\xE6\x93":" ",0);
				r = 0;
			}
			GetKey(&key);
			if (key==KEY_CTRL_UP) 	{if(--index<0) index = size - 1;r = 1;}
			if (key==KEY_CTRL_DOWN)	{if(++index>size - 1) index = 0;r = 1;}
			if (key==KEY_CTRL_EXE)
			{
				strcpy(file_name,(files+13*index));
				free (files);
				return 1;
			}
			if (key==KEY_CTRL_EXIT)
			{
				free (files);
				return 0;
			}
		}
	}
	else
		return -1;
	
}
Exemple #15
0
void main()
{

	auto char s[128];
	auto char display[128];
	auto char channels[16];
	auto int output_status, channel;
	auto int output_level;
	auto unsigned int outputChannel;

   brdInit();

	// Display user instructions and channel headings
	DispStr(8, 1, " <<< Sinking output channels  = OUT1-OUT7   >>>");
	DispStr(8, 2, " <<< Sourcing output channel  = OUT8-OUT9   >>>");
	DispStr(8, 4, "OUT0\tOUT1\tOUT2\tOUT3\tOUT4\tOUT5\tOUT6\tOUT7");
	DispStr(8, 5, "-----\t-----\t-----\t-----\t-----\t-----\t-----\t-----");

	DispStr(8, 9, "OUT8\tOUT9");
	DispStr(8, 10, "-----\t-----");

	DispStr(8, 14, "Connect the Demo Bd. LED's to the outputs that you want to demo.");
	DispStr(8, 15, "(See instructions in sample program for complete details)");
	DispStr(8, 21, "<-PRESS 'Q' TO QUIT->");

	// Set the channel array to reflect the output channel default value
	outputChannel = OUTCONFIG;
	for(channel = 0; channel <=9 ; channel++)
	{
		// Set outputs to be OFF, for both sinking
		// and sourcing type outputs.
		channels[channel] = outputChannel & 0x0001;
		outputChannel = outputChannel >> 1;
	}

	// Loop until user presses the upper/lower case "Q" key
	for(;;)
	{
		// Update high current outputs
		display[0] = '\0';								//initialize for strcat function
		for(channel = 0; channel <= 7; channel++)	//output to channels 0 - 7
		{
			output_level = channels[channel];		//output logic level to channel
			digOut(channel, output_level);
			sprintf(s, "%d\t", output_level);		//format logic level for display
			strcat(display,s);							//add to display string
		}
		DispStr(8, 6, display);							//update output status


		display[0] = '\0';
		for(channel = 8; channel <= 9; channel++)	//output to channels 8 - 9
		{
			output_level = channels[channel];			//output logic level to channel
			digOut(channel, output_level);
			sprintf(s, "%d\t", output_level);
			strcat(display,s);
		}
		DispStr(8, 11, display);

		// Wait for user to make output channel selection or exit program
		sprintf(display, "Select output channel 0 - 9 (Input Hex 0-F) = ");
		DispStr(8, 17, display);
     	do
		{
			channel = getchar();
			if (channel == 'Q' || channel == 'q')		// check if it's the q or Q key
			{
      		exit(0);
     		}
		}while(!isxdigit(channel));

		// Convert the ascii hex value to a interger
		if( channel >= '0' && channel <='9')
		{
			channel = channel - 0x30;
		}

		// Display the channel that ths user has selected
		sprintf(display, "Select output channel 0 - 9  = %d", channel);
		DispStr(8, 17, display);


		// Wait for user to select logic level or exit program
		sprintf(display, "Select logic level = ");
		DispStr(8, 18, display);
		do
		{
			output_level = getchar();
			if (output_level == 'Q' || output_level == 'q')		// check if it's the q or Q key
			{
      		exit(0);
     		}
     		output_level = output_level - 0x30;

		} while(!((output_level >= 0) && (output_level <= 1)));

		sprintf(display, "Select logic level = %d", output_level);
     	DispStr(8, 18, display);
     	channels[channel] = output_level;

  		// Clear channel and logic level selection prompts
  		DispStr(8, 17, "                                                  ");
  		DispStr(8, 18, "                                                  ");
   }
}