Esempio n. 1
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;
            }
        }
    }
}
Esempio n. 2
0
///////////////////////////////////////////////////////////
// DS1 led on protoboard is controlled by port G bit 6
// DS2 led on protoboard is controlled by port G bit 7
// turns oon when port bit is set to 0
///////////////////////////////////////////////////////////
void ledon(int led)
{
	BitWrPortI(PGDR, &PGDRShadow, 0, led);
}
Esempio n. 3
0
////////
// output function to control protoboard LED's
////////
void pbLedOut(int channel, int onoff)
{
	// works for port F bits 6 and 7 only
	BitWrPortI(PFDR, &PFDRShadow, onoff, channel);
}
Esempio n. 4
0
/////
// write state to led DS1 or DS2
/////
void pbWrLed(int led, int onoff)
{
	BitWrPortI(PDDR, &PDDRShadow, onoff, led);
}
Esempio n. 5
0
pinginled(int onoff)
{
	BitWrPortI(PBDR, &PBDRShadow, !onoff, DS3);
}
pinginled(int onoff)
{
	BitWrPortI(PBDR, &PBDRShadow, onoff, LED_PING_IN_BIT);
}
Esempio n. 7
0
///////////////////////////////////////////////////////////
// DS1 led on protoboard is controlled by port D bit 6
// DS2 led on protoboard is controlled by port D bit 7
// turns oon when port bit is set to 0
///////////////////////////////////////////////////////////
void pbledon(int led)
{
	BitWrPortI(PFDR, &PFDRShadow, 0, led);
}
Esempio n. 8
0
//////////////////////////////////////////////////////////
// Function to disable 485 transmissions, put in
// receive mode
//////////////////////////////////////////////////////////
nodebug
void ser485Rx()
{
	BitWrPortI(PDDR, &PDDRShadow, 0, 4);	// set port D bit 4 low
}
LcdCommandWr(char hex) {
int cmdbits[8];

  BitWrPortI(PBDR, &PBDRShadow, 0, RSADDR);  // Set LCD command mode
  BitWrPortI(PBDR, &PBDRShadow, 0, RWADDR);  // Set LCD write mode

  // we need to split the 8 bits in half and transmit upper 4 bits,
  // then the lower 4 bits.
  ByteSplit(hex, cmdbits);

  BitWrPortI(PADR, &PADRShadow, cmdbits[3], 4);  // Set port A bit 4
  BitWrPortI(PADR, &PADRShadow, cmdbits[2], 5);  // Set port A bit 5
  BitWrPortI(PADR, &PADRShadow, cmdbits[1], 6);  // Set port A bit 6
  BitWrPortI(PADR, &PADRShadow, cmdbits[0], 7);  // Set port A bit 7

  MsDelay(1);
  BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR);  // Start sending data upper 4 bit
  MsDelay(1);                                // Wait 1 ms for LCD to read
  BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR);  // Finish transmission upper 4 bit
  MsDelay(1);

  BitWrPortI(PADR, &PADRShadow, cmdbits[7], 4);  // Set port A bit 4
  BitWrPortI(PADR, &PADRShadow, cmdbits[6], 5);  // Set port A bit 5
  BitWrPortI(PADR, &PADRShadow, cmdbits[5], 6);  // Set port A bit 6
  BitWrPortI(PADR, &PADRShadow, cmdbits[4], 7);  // Set port A bit 7

  MsDelay(1);
  BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR);  // Start sending data lower 4 bit
  MsDelay(1);                                // Wait 1 ms for LCD to read
  BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR);  // Finish transmission lower 4 bit
  MsDelay(1);
}
Esempio n. 10
0
main()
{
	auto int i, ch;
	auto char buffer[64];	//buffer used for serial data
	auto int sw1, sw2, led1, led2;

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

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

   BitWrPortI(PEDR, &PEDRShadow, 0, 5);	//set low to enable rs232 device

	led1=led2=1;						//initialize led to off value
	sw1=sw2=0;							//initialize switch to false value

	// Initialize serial port E, set baud rate to 19200
 	serEopen(19200);
	serEwrFlush();
 	serErdFlush();

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

	// 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 E and C
   //---------------------------------------------------------------------
   for(;;)
   {
		costate
		{
			if (pbRdSwitch(S1))				//wait for switch S1 press
				abort;
			waitfor(DelayMs(50));
			if (pbRdSwitch(S1))				//wait for switch release
			{
				sw1=!sw1;
				abort;
			}
		}

		costate
		{
			if (pbRdSwitch(S2))				//wait for switch S2 press
				abort;
			waitfor(DelayMs(50));
			if (pbRdSwitch(S2))				//wait for switch release
			{
				sw2=!sw2;
				abort;
			}
		}

		costate
		{	// toggle DS1 upon valid S1 press/release
			if (sw1)
			{
				pbWrLed(DS1, ON);   		//turn on DS1 led
				sw1=!sw1;

   			// Transmit an ascii string from serial port C to serial port E
				memcpy(buffer, string2, strlen(string2));
   			serCputs(buffer);
				memset(buffer, 0x00, sizeof(buffer));

   			// Get the data string that was transmitted by port C
		    	i = 0;
		     	while((ch = serEgetc()) != '\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);

		  		// Clear buffer
				memset(buffer, 0x00, sizeof(buffer));
				pbWrLed(DS1, OFF);		//turn off DS1
			}
		}

		costate
		{	// toggle DS2 upon valid S2 press/release
			if (sw2)
			{
				pbWrLed(DS2, ON);		//turn on DS2 led
				sw2=!sw2;

		   	// Transmit an ascii string from serial port E to serial port C
				memcpy(buffer, string1, strlen(string1));
     			serEputs(buffer);
		     	memset(buffer, 0x00, sizeof(buffer));

				// Get the data string that was transmitted by serial port E
     			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 E
		   	printf("%s", buffer);
				pbWrLed(DS2, OFF);		//turn off DS2
			} //endif
		} //endcostate
	} //endfor
}
Lcd4bitInit() {

  BitWrPortI(PBDR, &PBDRShadow, 0, RSADDR);    // Set command mode
  BitWrPortI(PBDR, &PBDRShadow, 0, RWADDR);    // Set LCD write mode

  BitWrPortI(PADR, &PADRShadow, 1, 4);         // Set port A-4
  BitWrPortI(PADR, &PADRShadow, 1, 5);         // Set port A-5
  BitWrPortI(PADR, &PADRShadow, 0, 6);         // Set port A-6
  BitWrPortI(PADR, &PADRShadow, 0, 7);         // Set port A-7

  MsDelay(1);
  BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR);    // Start sending data upper 4 bit
  MsDelay(1);                                  // Wait 1 ms for LCD to read
  BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR);    // Finish transmission upper 4 bit
  MsDelay(5);

  BitWrPortI(PADR, &PADRShadow, 1, 4);         // Set port A-4
  BitWrPortI(PADR, &PADRShadow, 1, 5);         // Set port A-5
  BitWrPortI(PADR, &PADRShadow, 0, 6);         // Set port A-6
  BitWrPortI(PADR, &PADRShadow, 0, 7);         // Set port A-7

  MsDelay(1);
  BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR);    // Start sending data upper 4 bit
  MsDelay(1);                                  // Wait 1 ms for LCD to read
  BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR);    // Finish transmission upper 4 bit
  MsDelay(1);

  BitWrPortI(PADR, &PADRShadow, 1, 4);         // Set port A-4
  BitWrPortI(PADR, &PADRShadow, 1, 5);         // Set port A-5
  BitWrPortI(PADR, &PADRShadow, 0, 6);         // Set port A-6
  BitWrPortI(PADR, &PADRShadow, 0, 7);         // Set port A-7

  MsDelay(1);
  BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR);    // Start sending data upper 4 bit
  MsDelay(1);                                  // Wait 1 ms for LCD to read
  BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR);    // Finish transmission upper 4 bit
  MsDelay(1);

  BitWrPortI(PADR, &PADRShadow, 0, 4);         // Set port A-4
  BitWrPortI(PADR, &PADRShadow, 1, 5);         // Set port A-5
  BitWrPortI(PADR, &PADRShadow, 0, 6);         // Set port A-6
  BitWrPortI(PADR, &PADRShadow, 0, 7);         // Set port A-7

  MsDelay(1);
  BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR);    // Start sending data upper 4 bit
  MsDelay(1);                                  // Wait 1 ms for LCD to read
  BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR);    // Finish transmission upper 4 bit
  MsDelay(1);
}
void LcdPutChar(char displayChar) {
  char * lcdChar;
  int databits[8];
  lcdChar = AsciiCharLookup(displayChar);
  if(lcdChar==NULL) return;

  BitWrPortI(PBDR, &PBDRShadow, 1, RSADDR);  // Set LCD data mode
  BitWrPortI(PBDR, &PBDRShadow, 0, RWADDR);  // Set LCD write mode

  // we need to split the 8 bits in half and transmit upper 4 bits,
  // then the lower 4 bits.
  ByteSplit(*lcdChar, databits);

  BitWrPortI(PADR, &PADRShadow, databits[3], 4);  // Set port A bit 4
  BitWrPortI(PADR, &PADRShadow, databits[2], 5);  // Set port A bit 5
  BitWrPortI(PADR, &PADRShadow, databits[1], 6);  // Set port A bit 6
  BitWrPortI(PADR, &PADRShadow, databits[0], 7);  // Set port A bit 7

  MsDelay(1);
  BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR);  // Start sending data upper 4 bit
  MsDelay(1);                                // Wait 1 ms for LCD to read
  BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR);  // Finish transmission upper 4 bit
  MsDelay(1);

  BitWrPortI(PADR, &PADRShadow, databits[7], 4);  // Set port A bit 4
  BitWrPortI(PADR, &PADRShadow, databits[6], 5);  // Set port A bit 5
  BitWrPortI(PADR, &PADRShadow, databits[5], 6);  // Set port A bit 6
  BitWrPortI(PADR, &PADRShadow, databits[4], 7);  // Set port A bit 7

  MsDelay(1);
  BitWrPortI(PBDR, &PBDRShadow, 1, ENADDR);  // Start sending data lower 4 bit
  MsDelay(1);                                // Wait 1 ms for LCD to read
  BitWrPortI(PBDR, &PBDRShadow, 0, ENADDR);  // Finish transmission lower 4 bit
  MsDelay(1);
}
Esempio n. 13
0
/////////////////////////////////////////////////////////////////////
//	Retrieve analog calibration data and rewrite to the flash
/////////////////////////////////////////////////////////////////////
void main()
{
	auto unsigned long fileptr, tempPtr, xmemPtr, index;
	auto unsigned long len;
	auto int i;
	auto char serialNumber[64];

	//------------------------------------------------------------------------
	//		Initialize the Controller
	//------------------------------------------------------------------------
	brdInit();

   BitWrPortI(PEDR, &PEDRShadow, 0, 5);	//set low to enable rs232 device

	seropen(BAUDRATE);	//set baud rates for the serial ports to be used
	serwrFlush();		//clear Rx and Tx data buffers
	serrdFlush();

	//------------------------------------------------------------------------
	//		Allocate and Clear XMEM
	//------------------------------------------------------------------------

	// Allocate XMEM memory for the file that will be read in from the PC
	xmemPtr = xalloc(FILEBUFSIZE);

	// Clear the buffer in XMEM
	for(index =0; index < FILEBUFSIZE; index++)
	{
		root2xmem(xmemPtr + index, "\x00", 1);
	}

	//------------------------------------------------------------------------
	//		Download the Data File from the PC
	//------------------------------------------------------------------------
	sprintf(string, "\r\nWaiting...Please Send Data file\n\r");
	serwrite(string, strlen(string));

	// Get the calibration data file from the PC and put it into XMEM
	if(!(len = getfile(xmemPtr)))
	{
		caldata_error(string, "\r\n\nEncounter an error while reading calibration file");
		exit(1);
	}
	fileptr = xmemPtr;
	sprintf(string, "\r\n\nDownload Complete\n\n\r");
	serwrite(string, strlen(string));

	//------------------------------------------------------------------------
	//	 Parse data file and write to calibrations to flash
	//------------------------------------------------------------------------
	sprintf(string, "\r\nParsing data file\n\r");
	serwrite(string, strlen(string));

	tempPtr = find_tag(fileptr, len);

	sprintf(string, "\r\n\nExiting....Calibration data successfully written\n\n\r");
	serwrite(string, strlen(string));
	while (serwrFree() != OUTBUFSIZE);
   while((RdPortI(SXSR)&0x08) || (RdPortI(SXSR)&0x04));
	serclose();
}
Esempio n. 14
0
///////////////////////////////////////////////////////////
// DS1 led on protoboard is controlled by port G bit 6
// DS2 led on protoboard is controlled by port G bit 7
// turns off when port bit is set to 1
///////////////////////////////////////////////////////////
void ledoff(int led)
{
	BitWrPortI(PGDR, &PGDRShadow, 1, led);	
}
Esempio n. 15
0
///////////////////////////////////////////////////////////
// DS1 led on protoboard is controlled by port D bit 6
// DS2 led on protoboard is controlled by port D bit 7
// turns off when port bit is set to 1
///////////////////////////////////////////////////////////
void pbledoff(int led)
{
	BitWrPortI(PFDR, &PFDRShadow, 1, led);
}
Esempio n. 16
0
////////
// output function
////////
void digOut(int channel, int onoff)
{
	// works for port G bits 6 and 7 only
	BitWrPortI(PGDR, &PGDRShadow, onoff, channel+5);
}
Esempio n. 17
0
if_led(int onoff)
{
	BitWrPortI(PBDR, &PBDRShadow, onoff, DS2);
}
Esempio n. 18
0
pingoutled(int onoff)
{
	BitWrPortI(PBDR, &PBDRShadow, !onoff, DS2);
}
Esempio n. 19
0
xcvr_led(int onoff)
{
	BitWrPortI(PBDR, &PBDRShadow, onoff, DS3);
}
Esempio n. 20
0
//////////////////////////////////////////////////////////
// Function to enable 485 transmissions
//////////////////////////////////////////////////////////
nodebug
void ser485Tx()
{
    BitWrPortI(PDDR, &PDDRShadow, 1, 4);	// set port D bit 4 high
}
Esempio n. 21
0
pingoutled(int onoff)
{
   BitWrPortI(PBDR, &PBDRShadow, onoff, LED_PING_OUT_BIT);
}