Ejemplo n.º 1
0
// Check the status of switch
cofunc void CheckSwitch()
{
	static message_number;

	if (BitRdPortI(PDDR, S1))						   // wait for switch press
   {
		abort;											   // if button not down skip out
   }
	waitfor(DelayMs(50));							   // wait 50 ms
	if (BitRdPortI(PDDR, S1))						   // wait for switch press
   {
		abort;											   // if button not still down exit
   }

	BitWrPortI(PDDR, &PDDRShadow, LEDON, DS1);	// led on
   message_number = !message_number;
	SendMail(message_number); 						   // send if button was down 50 ms
	BitWrPortI(PDDR, &PDDRShadow, LEDOFF, DS1);	// led off

	while (1)
	{
		waitfor(BitRdPortI(PDDR, S1));			   // wait for button to go up
		waitfor(DelayMs(200));						   // wait additional 200 ms
		if (BitRdPortI(PDDR, S1))					   // wait for switch press
      {
			break;										   // if button still up exit loop
      }
	}
}
Ejemplo n.º 2
0
//------------------------------------------------------------------------
// Function to read the DEMO board switches
//------------------------------------------------------------------------	
nodebug
void monitor_switches(void)
{
		
		Switches_Active = FALSE;
		DemoBd_switch =0;
		
		costate
		{	
			if (BitRdPortI(PGDR, S2))		//wait for switch S2 press
				abort;
			waitfor(DelayMs(50));
			if (BitRdPortI(PGDR, S2))		//wait for switch release
			{
				Switches_Active = TRUE;
				DemoBd_switch = 1;
				abort;
			}
		}
		
		costate
		{	
			if (BitRdPortI(PGDR, S3))		//wait for switch S3 press
				abort;
			waitfor(DelayMs(50));
			if (BitRdPortI(PGDR, S3))		//wait for switch release
			{
				Switches_Active = TRUE;
				DemoBd_switch = 2;
				abort;
			}
		}
}
Ejemplo n.º 3
0
/////
// read state of switches S1 or S2
/////
int pbRdSwitch(int swstate)
{
	if (swstate == S1)
		return (BitRdPortI(PFDR, swstate));
   else
      return (BitRdPortI(PBDR, swstate));
}
Ejemplo n.º 4
0
int main()
{
	int status, led2, led3, sw2;

	// Initialize I/O pins
	brdInit();

   led2 = 0;
   led3 = 1;
   sw2 = 0;
   status = !SECURE;

   while(1) {
      costate {
         waitfor(DelayMs(200));
         if(status == SECURE) {
            // LED's on
	         BitWrPortI(PBDR, &PBDRShadow, 0, DS2_BIT);
	         BitWrPortI(PBDR, &PBDRShadow, 0, DS3_BIT);
         }
         else {
            // Flash LED's
	         led2 = !led2;
	         led3 = !led2;
	         BitWrPortI(PBDR, &PBDRShadow, led2, DS2_BIT);
	         BitWrPortI(PBDR, &PBDRShadow, led3, DS3_BIT);
         }
      }
      costate {
         // Wait for switch S2 press
			if(BitRdPortI(PBDR, S2_BIT))
				abort;
			waitfor(DelayMs(50));				// switch press detected
			if(BitRdPortI(PBDR, S2_BIT))	// wait for switch release
			{
				sw2 = !sw2;							// set valid switch
				abort;
			}
      }
      costate {
         // Periodically check the VBAT RAM
         memset(buffer, 0, 32);
         vram2root(buffer, 0, 32);

         if(memcmp(buffer, key, 32) == 0)
            status = SECURE;
         else
            status = !SECURE;

         waitfor(DelayMs(1000));
      }
      costate {
         // If the switch is pressed, reset the VBAT RAM
         if(sw2) {
            root2vram(key, 0, 32);
            sw2 = !sw2;
         }
      }
   }
}
Ejemplo n.º 5
0
main()
{
	auto int sw2, sw3, led2, led3;

	// Initialize I/O pins
	brdInit();

	led2=led3=1;			//initialize leds to off value
	DS2led(OFF);
	DS3led(OFF);
	sw2=sw3=0;				//initialize switches to false value
	printf("Ready\n");
	while (1)
	{
		costate
		{
			if (BitRdPortI(PBDR, S2_BIT))		//wait for switch S2 press
				abort;
			waitfor(DelayMs(50));					//switch press detected if got to here
			if (BitRdPortI(PBDR, S2_BIT))		//wait for switch release
			{
				sw2=!sw2;								//set valid switch
				abort;
			}
		}

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

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

		costate
		{	// toggle DS3 upon valid S3 press/release and clear switch
			if (sw3)
			{
				BitWrPortI(PBDR, &PBDRShadow, led3=led3?0:1, DS3_BIT);
				sw3=!sw3;
			}
		}

	}
}
Ejemplo n.º 6
0
void
main()
{
	auto int sw1, sw2, led1, led2;

	brdInit();				//initialize board for this demo

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

	while (1)
	{
		costate
		{
			if (BitRdPortI(PGDR, S2))		//wait for switch S2 press
				abort;
			waitfor(DelayMs(50));			//switch press detected if got to here
			if (BitRdPortI(PGDR, S2))		//wait for switch release
			{
				sw1=!sw1;						//set valid switch
				abort;
			}
		}

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

		costate
		{	// toggle DS1 led upon valid S2 press/release and clear switch
			if (sw1)
			{
				BitWrPortI(PGDR, &PGDRShadow, led1=led1?0:1, DS1);
				sw1=!sw1;
			}
		}

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

	}
}
Ejemplo n.º 7
0
void main()
{
	int vswitch;		// state of virtual switch controlled by button S1


	// set lowest 2 bits of port D as outputs, the rest as inputs
  	WrPortI(PDDDR, &PDDDRShadow, 0x03);
	// set all port D outputs to not be open drain
	WrPortI(PDDCR, &PDDCRShadow, 0x00);

   vswitch=0;				   // initialize virtual switch as off

	while (1) {					// endless loop

     // First task will flash LED #4 for 200ms once per second.
     costate {

		 BitWrPortI(PDDR, &PDDRShadow, 0xFF, 1);	// turn LED on
       waitfor(DelayMs(200));		// wait 200 milliseconds
		 BitWrPortI(PDDR, &PDDRShadow, 0x00, 1);	// turn LED off
       waitfor(DelayMs(800));		// wait 800 milliseconds
     }


     // Second task will debounce switch #1 and toggle virtual switch vswitch.
     // also check button 1 and toggle vswitch on or off
     costate {
         if (!BitRdPortI(PDDR, 2))
         	abort;				// if button not down skip out of costatement

         waitfor(DelayMs(50));		// wait 50 ms

         if(!BitRdPortI(PDDR, 2))
         	abort;				// if button not still down skip out

         vswitch = !vswitch;	// toggle virtual switch since button was down 50 ms

         // now wait for the button to be up for at least 200 ms before considering another toggle
         while (1) {
           waitfor(!BitRdPortI(PDDR, 2));		// wait for button to go up
           waitfor(DelayMs(200));				// wait additional 200 milliseconds
           if (!BitRdPortI(PDDR, 2))
           		break;				// if button still up break out of while loop
			}
      } // end of costate

		// make LED agree with vswitch
			BitWrPortI(PDDR, &PDDRShadow, vswitch, 0);

	}  // end of while loop

}  // end of main
Ejemplo n.º 8
0
void main()
{
	int vswitch;		// state of virtual switch controlled by button S1

   WrPortI(SPCR, &SPCRShadow, 0x84);	// setup parallel port A as output
   WrPortI(PADR, &PADRShadow, 0xff);		// turn off all LED's
   

   vswitch=0;				   // initialize virtual switch as off
       
	while (1) {					// endless loop
	
     // First task will flash LED DS4 for 200ms once per second.
     costate {    
       BitWrPortI(PADR, &PADRShadow, 0, 1);		// turn LED on
       waitfor(DelayMs(200));							// wait 200 milliseconds
       BitWrPortI(PADR, &PADRShadow, 1, 1);		// turn LED off
       waitfor(DelayMs(800)); 						// wait 800 milliseconds
     }

          
     // Second task will debounce switch S1 and toggle virtual switch vswitch.
     // also check button 1 and toggle vswitch on or off
     costate {
         if (BitRdPortI(PBDR, 2))
         	abort;				// if button not down skip out of costatement

         waitfor(DelayMs(50));		// wait 50 ms

         if(BitRdPortI(PBDR,2))
         	abort;				// if button not still down skip out
         
         vswitch = !vswitch;	// toggle virtual switch since button was down 50 ms
  
         // now wait for the button to be up for at least 200 ms before considering another toggle
         while (1) {
           waitfor(BitRdPortI(PBDR, 2));		// wait for button to go up
           waitfor(DelayMs(200));				// wait additional 200 milliseconds
           if (BitRdPortI(PBDR,2))
           		break;				// if button still up break out of while loop
			}
      } // end of costate
               
		// make led agree with vswitch if vswitch has changed
		if( (PADRShadow & 1) == vswitch)
			BitWrPortI(PADR, &PADRShadow, !vswitch, 0);
     
	}  // end of while loop

}  // end of main
Ejemplo n.º 9
0
void main()
{
	static const char s[] = "Hello Z-World\r\n";

	// This is necessary for initializing RS232 functionality of LP35XX boards.
#if _BOARD_TYPE_ == 0x1200 || _BOARD_TYPE_ == 0x1201
	brdInit();
#endif

	serBopen(19200);
	serBputs(s);

	// first, wait until the serial buffer is empty
	while (serBwrFree() != BOUTBUFSIZE);

	// then, wait until the Tx data register and the Tx shift register
	//  are both empty
	while (BitRdPortI(SBSR, 3) || BitRdPortI(SBSR, 2));

	// now we can close the serial port without cutting off Tx data
	serBclose();
}
Ejemplo n.º 10
0
main()
{

	//------------------------------------------------------------------------
	// Initialize the controller
	//------------------------------------------------------------------------	
	brdInit();				//initialize board for this demo

	// Start-up the keypad driver
	// Initialize the graphic driver
	dispInit();
	
	keypadDef();		// Use the default keypad ASCII return values

	glBackLight(1);	// Turn-on the backlight
	glXFontInit(&fi6x8, 6, 8, 32, 127, Font6x8);			//	Initialize 6x8 font
	glBlankScreen();
	for(;;)
	{
		glPrintf (0,  0, &fi6x8,  "Waiting for a Switch"); 
		glPrintf (0,  8, &fi6x8,  "to be pressed on the");
		glPrintf (0,  16, &fi6x8, "prototyping board...");
		
		while (BitRdPortI(PGDR, S2) && BitRdPortI(PGDR, S3));
		glBlankScreen();
		if (!BitRdPortI(PGDR, S2))
		{
			glPrintf (0,  0, &fi6x8, "Switch 2 is Active!");
			dispLedOut(5, 1);   									//Turn-on Keypad LED DS1
			BitWrPortI(PGDR, &PGDRShadow, 0, DS1);		//proto-board DS1 on

			while (!BitRdPortI(PGDR, S2));
			dispLedOut(5, 0); 	// Turn-OFF Keypad LED DS1
			BitWrPortI(PGDR, &PGDRShadow, 1, DS1);		//proto-board DS1 off
		}
		if (!BitRdPortI(PGDR, S3))
		{
			glPrintf (0,  0, &fi6x8, "Switch 3 is Active!");
			dispLedOut(6, 1); 										//Turn-on Keypad LED DS2
			BitWrPortI(PGDR, &PGDRShadow, 0, DS2);		//proto-board DS2 on

			while (!BitRdPortI(PGDR, S3));
			dispLedOut(6, 0); 	// Turn-OFF Keypad LED DS2
			BitWrPortI(PGDR, &PGDRShadow, 1, DS2);		//proto-board DS2 off
		}
		glBlankScreen();
	}
}			
void main()
{
	//temp variable useful for loops
	int i;
   //temp variables for serial communication
   int c;
   unsigned int bytesRead;

   //variables for wifi communication
   int newMode;
   int interfacePacketRecieved;
   int network;


   #GLOBAL_INIT
	{
		setMode(ROBOT_ENABLE);
      rx.state = WAIT;

      /***********************
        Initialization of Packets
      ***********************/
      // Initialize software version
      aPacket[1] = SOFTWARE_VERSION_ID >> 8;
      aPacket[2] = SOFTWARE_VERSION_ID & 0xFF;

      // Initialize UDP response packets
      gPacket[0] = 'G';
      gPacket[1] = ROBOTMODE;
      gPacket[2] = SOFTWARE_VERSION_ID >> 8;
      gPacket[3] = SOFTWARE_VERSION_ID & 0xFF;
      gPacket[4] = 0;	// user version id
      gPacket[5] = 0;
      gPacket[6] = 0;	// battery voltage
      gPacket[7] = 0;

      // Initialize J packet values to 0
      memset(jPacket, 0, J_PACKET_LENGTH);

      // Initialize X default packet (autonomous mode dummy packet) to 0
      memset(xPacketDefaultValues, 0, X_PACKET_LENGTH);
	}


   /////////////////////////////////////////////////////////////////////////
   // Configure Port D -- Leave PD4-PD7 untouched (used for other purposes)
   /////////////////////////////////////////////////////////////////////////
   WrPortI(PDCR,  &PDCRShadow,  RdPortI(PDCR)  & 0xF0);  // clear bits to pclk/2
   WrPortI(PDFR,  &PDFRShadow,  RdPortI(PDFR)  & 0xF0);  // no special functions
   WrPortI(PDDCR, &PDDCRShadow, RdPortI(PDDCR) & 0xF0);  // clear bits to drive
                                                         //  high and low
   WrPortI(PDDR,  &PDDRShadow,  RdPortI(PDDR)  | 0x0D);  // set outputs high
   WrPortI(PDDDR, &PDDDRShadow, RdPortI(PDDDR) | 0x0D);  // set inputs and
                                                         //  outputs

   //Initialize serial communication
   serialInit();

   //Initialize controls as neutral
   //memset(interface.axis, 127, sizeof(interface.axis));
   //memset(interface.btn, 0, sizeof(interface.btn));

   //Decide which router to connect to
	if (BitRdPortI(PDDR, 1) == 1) {
   	//USER settings
   	BitWrPortI(PDDR, &PDDRShadow, 1, 0);	// turn off user LED
      network = USER_ROUTER;
		printf("USER\n");
	} else {
		//COMPETITION Settings
      BitWrPortI(PDDR, &PDDRShadow, 0, 0);   // turn on user LED
      network = COMP_ROUTER;
      setMode(ROBOT_DISABLE);
      printf("COMPETITION\n");
   }
   // */

   printf("Robot Mode: %d \n", ROBOTMODE);

   // Wait for X2 handshake (to learn team #) before attempting connection
   printf("Waiting for X2...\n");
	while (x2Connection != X2_CONN_ESTABLISHED) {
      if ((c = serCgetc()) != -1) {
   		byteReceived(c);
      }
   }
   printf("X2 connection established\n");
   sendPacket('F', F_PACKET_LENGTH, fPacket);
   ConnectToNetwork(network, teamNo);

   //Main Loop
	while(1) {
		// Receive field, interface & X2 reply packets as they come
   	costate {
			//Check to see if we have new field communication
	      if (udpRecieveFieldPacket()) {

	         newMode = ProcessFieldPacket();
	         if (newMode != -1) {

            	// Set robot mode flags
	            setMode(newMode);

            	// If disable flag set: zero motor values
               if (newMode & ROBOT_DISABLE)
               	disableRobot();

               // Send X2 packet with new mode flags
               sendPacket('F', F_PACKET_LENGTH, fPacket);

					// Send back response packet with our robot mode flags
               //  and code versions
               sendFieldSocket(gPacket, G_PACKET_LENGTH);

	            //printf("Robot Mode: %d \n", ROBOTMODE);
	         }
         }

	      //Check to see if we have new field commuication, and we can use it
	      if (udpRecieveInterfacePacket()) {
	         if (interBuf[0] == 'I') {
	            udpNewData = TRUE;
	         }
         }

      	// Receive X2 serial data in bursts of up to X2_RX_BURST_LENGTH
         bytesRead = 0;
			while ((c = serCgetc()) != -1 &&
         			bytesRead <= X2_RX_BURST_LENGTH) {
				byteReceived((unsigned char)c);
            bytesRead += 1;
         }
      }
      // */

      // Time out if no UDP packets received after 500 ms
      //  TODO: Update the interface to send an enable packet. In the meantime
      //  this feature is only activated in competition mode
      costate {
      	if (network == COMP_ROUTER) {
	         waitfor( udpNewData || DelayMs(500) );
	         if (!udpNewData)
	            disableRobot();
         }
      }

      // Send X2 packets
      costate {
      	// FOR TESTING
         // udpNewData = TRUE;
      	waitfor( udpNewData );

         // Check that disable bit is not set
         if (!(ROBOTMODE & ROBOT_DISABLE)) {

	         // If in autonomous mode, send a dummy 'X' packet to keep the
            // motor refreshing, but do not send actual joystick values
            if (ROBOTMODE & ROBOT_AUTON)
            	sendPacket('X', X_PACKET_LENGTH, xPacketDefaultValues);
            // Otherwise in enable mode, send the received joystick values
            else
	         	sendPacket('X', X_PACKET_LENGTH, interBuf+1);
	         x2OkToSend = FALSE;
	         udpNewData = FALSE;

	         // Wait for reply before sending another packet
	         waitfor( x2OkToSend || DelayMs(500) );
	         if (!x2OkToSend) {   // no reply came within 500ms timeout
	            //printf("disable");
	            disableRobot();
	         }
         }
      }

		costate {
			// If auto bit is set, blink the LED fast
         if (ROBOTMODE & ROBOT_AUTON) {
				BitWrPortI(PDDR, &PDDRShadow, 0, 0);   // turn on user LED
	         waitfor (DelayMs(100));
	         BitWrPortI(PDDR, &PDDRShadow, 1, 0);   // turn off user LED
	         waitfor (DelayMs(100));

         // Otherwise if disable bit is set, blink the LED slowly
         } else if (ROBOTMODE & ROBOT_DISABLE) {
	         BitWrPortI(PDDR, &PDDRShadow, 0, 0);   // turn on user LED
	         waitfor (DelayMs(500));
	         BitWrPortI(PDDR, &PDDRShadow, 1, 0);   // turn off user LED
	         waitfor (DelayMs(500));
         }
      }
   } // while(1)

}	// main
Ejemplo n.º 12
0
main()
{
	static char buf_sw2[64], buf_sw3[64];	// buffers used for serial data
	auto int i, j, ch, rc, timer2, timer3;
	auto int sw2, sw3;

	// Configure serial ports D and E (RCM4210 only) as described
	//  in the comments above
	serDEconfig();

   // Ensure serial ports D, E read / write buffers are empty at this point
   serDrdFlush();
	serDwrFlush();
#if _BOARD_TYPE_ == RCM4210
 	serErdFlush();
   serEwrFlush();
#endif

	// Initialize switch flags to false value
	sw2 = sw3 = OFF;

	// Clear our local data buffers
	memset(buf_sw2, 0x00, sizeof(buf_sw2));
	memset(buf_sw3, 0x00, sizeof(buf_sw3));

#if _BOARD_TYPE_ == RCM4200
	printf("Please note that this sample does not actually demonstrate serial\n");
	printf(" port I/O reconfiguration on an RCM4200.\n\n");
#endif
   printf("Sample program is running:\n");
   printf("Waiting for prototyping board S2 or S3 switch click.\n\n");

   //---------------------------------------------------------------------
   // Do continuous loop echoing data via serial port D and maybe E
   //---------------------------------------------------------------------
	while(1) {
		costate {
			if (BitRdPortI(S2_PORT, S2_BIT))		//wait for switch press
				abort;
			waitfor(DelayMs(50));
			if (BitRdPortI(S2_PORT, S2_BIT)) {	//wait for switch release
				sw2 = !sw2;
				abort;
			}
		}

		costate {
			if (BitRdPortI(S3_PORT, S3_BIT))		//wait for switch press
				abort;
			waitfor(DelayMs(50));
			if (BitRdPortI(S3_PORT, S3_BIT)) {	//wait for switch release
				sw3 = !sw3;
				abort;
			}
		}

		costate {
			if (sw2) {
				sw2 = !sw2;

#if _BOARD_TYPE_ == RCM4210
            // The switch is attached to the serial port, so we need to read
            // the characters it sends
            serErdFlush();
   			// Echo an ASCII string over serial port E
				memcpy(buf_sw2, string1, strlen(string1));
   			serEputs(buf_sw2);
				memset(buf_sw2, 0x00, sizeof(buf_sw2));

   			// Get the data string that was transmitted via port E
		    	i = 0;
     			timer2 = TIME_OUT;
		     	while (timer2 > 0) {
		     		ch = serEgetc();
		     		// Preventing buffer overrun, copy only valid RCV'd characters
		     		//  to the buffer
					if (ch == -1) {
						waitfor(DelayMs(1));
						--timer2;
						// just in case we've timed out, force an end of line CR
						ch = '\r';
					}
					else if (ch == '\r') {
						timer2 = 0;	// end of line CR character, force an exit!
					} else {
						if (i < sizeof(buf_sw2) - 3) {
							buf_sw2[i++] = ch;
						}
					}
				}
				buf_sw2[i++] = ch;			 //copy '\r' to the data buffer
     			buf_sw2[i]   = '\0';      //terminate the ascii string

		     	// Display ASCII string received from serial port E echo
     			printf("%s", buf_sw2);

		  		// Clear buffer
				memset(buf_sw2, 0x00, sizeof(buf_sw2));
#elif _BOARD_TYPE_ == RCM4200
				printf("Note:  Serial port E is not available on the RCM4200.\n");
#endif
			}
		}

		costate {
			if (sw3) {
				sw3 = !sw3;

            // The switch is attached to the serial port, so we need to read
            // the characters it sends
            serDrdFlush();
		   	// Transmit an ASCII string over serial port D
				memcpy(buf_sw3, string2, strlen(string2));
     			serDputs(buf_sw3);
		     	memset(buf_sw3, 0x00, sizeof(buf_sw3));

				// Get the data string that was transmitted via serial port D
     			j = 0;
     			timer3 = TIME_OUT;
		     	while (timer3 > 0) {
		     		ch = serDgetc();
		     		// Preventing buffer overrun, copy only valid RCV'd characters
		     		//  to the buffer
					if (ch == -1) {
						waitfor(DelayMs(1));
						--timer3;
						// just in case we've timed out, force an end of line CR
						ch = '\r';
					}
					else if (ch == '\r') {
						timer3 = 0;	// end of line CR character, force an exit!
					} else {
						if (j < sizeof(buf_sw3) - 3) {
							buf_sw3[j++] = ch;
						}
					}
				}
		     	buf_sw3[j++] = ch; 		//copy '\r' to the data buffer
		     	buf_sw3[j]   = '\0';     //terminate the ascii string

	     		// Display ASCII string received from serial port D echo
		   	printf("%s", buf_sw3);

		  		// Clear buffer
				memset(buf_sw3, 0x00, sizeof(buf_sw3));
			} //endif
		} //endcostate
	} //endwhile
}
Ejemplo n.º 13
0
/*******************************************************************
   Program Main
 ******************************************************************/
main() {
	int i;	// define an integer j to serve as a loop counter
	//display variables
	char *strPtr, *scrollStrPtr;
	int dpos;
	short scroll;
	//program variables
	int lastSwitchVal;
	long timeStamp,st;
	char line1[17];
	char *rssServer,*rssPage;

	//display init
	scroll=1;
	dprint_init_ports();
	dprint_init();
	printf("LCD display initialized.\n");
	//print a welcome message
	dprint_clear();
	dprint_move_to(0,0);
	dprint("iDisplay");
	dprint_move_to(0,12);
	dprint("v0.1");
	dprint_move_to(1,0);
	dprint("initializing...");

	//network init
	strPtr="";
	if(init_DHCP()) {
		dprint_info();
		strPtr = "success!";
	} else {
		strPtr = "** nework initialization error!";
	}

	//program init
	timeStamp = SEC_TIMER;	//set up the timing for refreshing the data...
	lastSwitchVal = 1234;	//random, so first time it grabs RSS
	memset(headlines,0,sizeof(headlines));	//just to be safe...

	//example message
	scrollStrPtr = strPtr;
	dpos = 15;

	while(1){

		costate{
			//grab the headlines after 5 mins, or on a switch change
			if((lastSwitchVal != BitRdPortI(PBDR,2)) ||
				(SEC_TIMER > timeStamp+RSS_REFRESH_DELAY) ){
				scroll=0;
				dprint_clear();
				dprint_move_to(1,0);
				dprint("Loading data...");
				if (lastSwitchVal){
					rssServer=RSS_BBC_SERVER;
					rssPage=RSS_BBC_PAGE;
					strcpy(line1,"BBC News");
				} else {
					rssServer=RSS_CNN_SERVER;
					rssPage=RSS_CNN_PAGE;
					strcpy(line1,"CNN");
				}
				if(get_headlines(rssServer,rssPage)) strPtr = headlines;
				else {
					strPtr = "** unable to connect to Internet!";
					strcpy(line1,"Error");
				}
				scrollStrPtr = strPtr;	//be friendly and leave strPtr untouched
				lastSwitchVal = BitRdPortI(PBDR,2);
				timeStamp = SEC_TIMER;
				dprint_move_to(0,0); //print the data source
				dprint(line1);
				sprint_time(line1);	//now print the time
				dprint_move_to(0,11);
				dprint(line1);
				scroll=1;
			}
		}

		costate{
			//scroll a message across the screen
			if(scroll==1){
				dprint_move_to(1,0);
				for(i=0;i<dpos;i++) dprint_char(' ');
				if(dpos > 0) dpos--;
				if(dpos == 0) scrollStrPtr++;
				dprint(scrollStrPtr);
				if(*scrollStrPtr==0) {	//end of str
					scrollStrPtr = strPtr;
					dpos = 15;
				}
				waitfor(DelayMs(150));
			}
		}

		costate{
			//debugging
			if (BitRdPortI(PBDR, 3)==0){
				while(BitRdPortI(PBDR, 3)==0);	//debounce
				scroll=0;
				dprint_info();
			}
		}

	}	//while true

} // end program
Ejemplo n.º 14
0
void main()
{
    char outString[MAX_TX_LEN], inString[MAX_TX_LEN];
    int i, j, ch, out_string_len;

    brdInit();
    // The brdInit for this board sets pins that are not initially assigned to
    // hardware as outputs, such as the serial port Rx pins. The Rx pin for
    // serial port D is not set to an input because it is not used in this
    // sample.
    BitWrPortI(PCDDR, &PCDDRShadow, 0, 3);  // set serial port C Rx as input

    serDopen(BAUDRATE);
    serCopen(BAUDRATE);

#ifdef DIGITAL_IO_ACCESSORY
    InitIO();
#endif

    // Initialize DS1 LED (PDO) to output
    BitWrPortI(PDDDR, &PDDDRShadow, 0, 1);
    // Initialize DS1 LED (PDO) to output
    BitWrPortI(PDDDR, &PDDDRShadow, 1, 0);
    // Make sure PD0 not set to alternate function
    BitWrPortI(PDFR,  &PDFRShadow, 0, 1);
    // Make sure PD0 not set to alternate function
    BitWrPortI(PDFR,  &PDFRShadow, 0, 0);

    j = 0;

    while(1) {

        costate
        {
            // Bits for switches and LEDs correspond
            for (i = S1; i <= S4; i++)
            {
#ifdef DIGITAL_IO_ACCESSORY
                if (!BitRdPortI(PBDR, i))
#else
                if (!BitRdPortI(PDDR, i))
#endif
                {
                    // Delay so we don't output too many times
                    waitfor(DelayMs(300));

                    // Light corresponding LED
#ifdef DIGITAL_IO_ACCESSORY
                    BitWrPortI(PADR, &PADRShadow, LEDON, i);
#else
                    BitWrPortI(PDDR, &PDDRShadow, LEDON, i-1);
#endif

                    sprintf(outString, "Switch %d is on\n", i-S1+1);
                    out_string_len = strlen(outString);

                    // Make sure there's room in ouput buffer
                    waitfor(serDwrFree() > out_string_len);
                    // Write string out
                    serDwrite(outString, out_string_len);
                }
                else
                {
#ifdef DIGITAL_IO_ACCESSORY
                    BitWrPortI(PADR, &PADRShadow, LEDOFF, i);  // LED off
#else
                    BitWrPortI(PDDR, &PDDRShadow, LEDOFF, i-1);
#endif
                }
            }
        }

        // Wait for any ASCII input
        //  serCgetc() returns -1 (0xFFFF) if no chars available
        if ( (ch = serCgetc()) != -1 )
        {
            inString[j] = ch;
            j++;
            if (j >= MAX_TX_LEN)         // Make sure we don't overflow
            {   //  array bounds in case 0x0A
                j = 0;                    //  gets dropped.
            }
            else if (ch == '\n')         // Check for new line as delimiter
            {
                inString[j] = 0;          // NULL terminate
                printf("%s",inString);
                j = 0;
            }
        }
    }
}
Ejemplo n.º 15
0
/////
// read state of switches S2 or S3
/////
int pbRdSwitch(int swstate)
{
	return (BitRdPortI(PDDR, swstate));
}
Ejemplo n.º 16
0
main()
{
    auto int i, ch;
    auto char buffer[64];	//buffer used for serial data
    auto int sw1, sw2;

    static const char string1[] = {"This message has been Rcv'd from serial port C !!!\n\n\r"};
    static const char string2[] = {"This message has been Rcv'd from serial port D !!!\n\n\r"};

    sw1 = sw2 = 0;							//initialize switch to false value

    // Initialize serial port C, set baud rate to 19200
    serCopen(19200);
    serCwrFlush();
    serCrdFlush();

    // Initialize serial port D, set baud rate to 19200
    serDopen(19200);
    serDwrFlush();
    serDrdFlush();

    // Clear data buffer
    memset(buffer, 0x00, sizeof(buffer));

    printf("\nStart of Sample Program!!!\n\n\n\r");
    //---------------------------------------------------------------------
    // Do continuous loop transmitting data between serial ports C and D
    //---------------------------------------------------------------------
    while(1) {
        costate {
            if (BitRdPortI(S2_PORT, S2_BIT))		//wait for switch press
                abort;
            waitfor(DelayMs(50));
            if (BitRdPortI(S2_PORT, S2_BIT)) {	//wait for switch release
                sw1 = !sw1;
                abort;
            }
        }

        costate {
            if (BitRdPortI(S3_PORT, S3_BIT))		//wait for switch press
                abort;
            waitfor(DelayMs(50));
            if (BitRdPortI(S3_PORT, S3_BIT)) {	//wait for switch release
                sw2 = !sw2;
                abort;
            }
        }

        costate {
            // toggle led upon valid switch press/release
            if (sw1) {
                sw1 = !sw1;

                // The switch is attached the the serial port, so we need to read
                // the junk it sends
                serCrdFlush();
                // Transmit an ascii string from serial port D to serial port C
                memcpy(buffer, string2, strlen(string2));
                serDputs(buffer);
                memset(buffer, 0x00, sizeof(buffer));

                // Get the data string that was transmitted by port D
                i = 0;
                while((ch = serCgetc()) != '\r')	{
                    // Copy only valid RCV'd characters to the buffer
                    if(ch != -1) {
                        buffer[i++] = ch;
                    }
                }
                buffer[i++] = ch;			 //copy '\r' to the data buffer
                buffer[i]   = '\0';      //terminate the ascii string

                // Display ascii string received from serial port D
                printf("%s", buffer);

                // Clear buffer
                memset(buffer, 0x00, sizeof(buffer));
            }
        }

        costate {
            // toggle led upon valid switch press/release
            if (sw2) {
                sw2=!sw2;

                // The switch is attached the the serial port, so we need to read
                // the junk it sends
                serDrdFlush();
                // Transmit an ascii string from serial port C to serial port D
                memcpy(buffer, string1, strlen(string1));
                serCputs(buffer);
                memset(buffer, 0x00, sizeof(buffer));

                // Get the data string that was transmitted by serial port C
                i = 0;
                while((ch = serDgetc()) != '\r') {
                    // Copy only valid RCV'd characters to the buffer
                    if(ch != -1) {
                        buffer[i++] = ch;
                    }
                }
                buffer[i++] = ch; 		//copy '\r' to the data buffer
                buffer[i]   = '\0';     //terminate the ascii string

                // Display ascii string received from serial port C
                printf("%s", buffer);
            } //endif
        } //endcostate
    } //endwhile
}