// UART 2 interrupt handler
// it is set at priority level 2
void __ISR(_UART2_VECTOR, ipl2) IntUart2Handler(void)
{
	// Is this an RX interrupt?
	if(INTGetFlag(INT_SOURCE_UART_RX(UART2)))
	{
		// Clear the RX interrupt Flag
	    INTClearFlag(INT_SOURCE_UART_RX(UART2));

	// Code to be executed on RX interrupt:

		// Echo what we just received.
		PutCharacter(UARTGetDataByte(UART2));
		// Toggle LED to indicate UART activity
		mPORTAToggleBits(BIT_7);

	}

	// We don't care about TX interrupt
	if ( INTGetFlag(INT_SOURCE_UART_TX(UART2)) )
	{
		// Clear the TX interrupt Flag
		INTClearFlag(INT_SOURCE_UART_TX(UART2));

	// Code to be executed on TX interrupt:

		
	}
}
void __ISR(_UART2_VECTOR, ipl2) IntUart2Handler(void)
{
	// Is this an RX interrupt?
	if(INTGetFlag(INT_SOURCE_UART_RX(UART2)))
	{

		// Clear the RX interrupt Flag
	    INTClearFlag(INT_SOURCE_UART_RX(UART2));

		// Code to be executed on RX interrupt:
		COMMAND = UARTGetDataByte(UART2);
		
		// Echo what we just received.
		PutCharacter(COMMAND);
	}

	// We don't care about TX interrupt
	if ( INTGetFlag(INT_SOURCE_UART_TX(UART2)) )
	{
		// Clear the TX interrupt Flag
		INTClearFlag(INT_SOURCE_UART_TX(UART2));

		// Code to be executed on TX interrupt:
			//none
	}
}
// UART 2 interrupt handler
// it is set at priority level 2
void __ISR(_UART2_VECTOR, ipl2) IntUart2Handler(void)
{
	// Is this an RX interrupt?
	if(INTGetFlag(INT_SOURCE_UART_RX(UART2)))
	{
		unsigned char databyte;

		// Clear the RX interrupt Flag
	    INTClearFlag(INT_SOURCE_UART_RX(UART2));

		// Code to be executed on RX interrupt:
		databyte = UARTGetDataByte(UART2);
		databyte++;
		
		// Echo what we just received.
		PutCharacter(databyte);
	}

	// We don't care about TX interrupt
	if ( INTGetFlag(INT_SOURCE_UART_TX(UART2)) )
	{
		// Clear the TX interrupt Flag
		INTClearFlag(INT_SOURCE_UART_TX(UART2));

		// Code to be executed on TX interrupt:

		
	}
}
Exemplo n.º 4
0
/**********************************************************
 * Application tasks routine. This function implements the
 * application state machine.
 ***********************************************************/
void APP_Tasks ( void )
{
    /* check the application state*/
    switch ( appData.state )
    {
        case USART_ENABLE:
           
            /* Enable the UART module*/
            PLIB_USART_Enable(USART_ID_2);

            appData.stringPointer = txPowerValuesBuff_1;
;

            appData.state =  USART_TRANSMIT_FIRST_STRING;

            break;

        case USART_TRANSMIT_FIRST_STRING:
            if(true == WriteString())
            {
                appData.state = USART_TRANSMIT_SECOND_STRING;
                appData.stringPointer = string2;
            }

            break;

        case USART_TRANSMIT_SECOND_STRING:
            if(true == WriteString())
            {
                appData.state = USART_RECEIVE_DONE;
            }
            break;

        case USART_RECEIVE_DONE:
              if (appData.InterruptFlag)
              {
                  if(true == PutCharacter(appData.data))
                  {
                    BSP_LEDOn(BSP_LED_3);
                    appData.InterruptFlag = false;        
                  }
              }
            break;

        default:
            SYS_DEBUG (SYS_ERROR_FATAL,"ERROR! Invalid state\r\n");
            while (1);

    }

} 
Exemplo n.º 5
0
//////////////////////////////////
// DN Communications Interrupts //
//////////////////////////////////
void __ISR(_UART2_RX_VECTOR, ipl7) _InterruptHandler_RS485_RX(void)
{
   /* Clear the interrupt flag */
   PLIB_INT_SourceFlagClear(INT_ID_0, INT_SOURCE_USART_2_RECEIVE);

   /* Make sure receive buffer has data availible */
   if (PLIB_USART_ReceiverDataIsAvailable(USART_ID_2))
   {
      char data;

      /* Get the data from the buffer */
      data = PLIB_USART_ReceiverByteReceive(USART_ID_2);

      /* Echo what we just received */
      PutCharacter(data);
   }
   usartIntTriggered = true;
}
Exemplo n.º 6
0
void CWinGlkWndTextGrid::PutCharacter(glui32 c)
{
  CWinGlkWnd::PutCharacter(c);

  if ((m_iCursorY >= 0) && (m_iCursorY < m_TextGrid.GetSize()))
  {
    CGridRow& Row = m_TextGrid[m_iCursorY];
    if ((m_iCursorX >= 0) && (m_iCursorX < Row.GetLength()))
    {
      if (c == L'\n')
      {
        m_iCursorX = 0;
        m_iCursorY++;
      }
      else
      {
        if ((c >= 32 && c <= 126) || (c >= 160 && c <= 0xFFFF))
        {
          Row.SetChar(m_iCursorX,(wchar_t)c);
          Row.SetStyle(m_iCursorX,m_iCurrentStyle);
          Row.SetLink(m_iCursorX,m_iCurrentLink);
          m_iCursorX++;
          if (m_iCursorX >= Row.GetLength())
          {
            m_iCursorX = 0;
            m_iCursorY++;
          }
        }
        else
        {
          char pszError[16];
          if (c <= 0xFF)
            sprintf(pszError,"[0x%02X]",(int)c);
          else
            sprintf(pszError,"[0x%08X]",(int)c);
          for (int i = 0; i < (int)strlen(pszError); i++)
            PutCharacter(pszError[i]);
        }
      }
    }
  }
}
Exemplo n.º 7
0
void PutString(unsigned char string[]) {
    // Declare local variables
    unsigned char ch;
    unsigned char i;
    // initialze the iterator variable
    i = 0;


    // get first character of the string (dereference the pointer)
    ch = string[i];

    // apply putCharacter to each letter in string while letter is not null character
    while (ch != 0x00) {
        // send out each character
        PutCharacter(ch);
        // increment pointer's position
        i++;
        // get next character from the array
        ch = string[i];
    }
}
Exemplo n.º 8
0
void PutString(char *stringptr) {
	// Declare local variables
	unsigned char ch;
	
	// get first character of the string (dereference the pointer)
	ch = *stringptr;
	
	// apply putCharacter to each letter in string while letter is not null character
	while (ch != 0x00) {
		// send out each character
		PutCharacter(ch);
		// increment pointer's position
		stringptr++;
		// get the next character in the string
		ch = *stringptr;
		
		
	}
	
	
}
Exemplo n.º 9
0
main()
{
    // Disable JTAG (on RA0 and RA1 )
    mJTAGPortEnable( DEBUG_JTAGPORT_OFF );

    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig(GetSystemClock(), SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

    initializeUART();
    initializeADC();
    initializeLCD();
    initializeRPG();
    
    /* Initialize SD card */
    setup_SDSPI();
    SD_setStart();
    /* Fill tempBuffer[] with int 0 to 63
     * Write it to the current block.
     * Empty tempBuffer[] to all 0.
     * Read from the current block to make sure that it returns the right value.
     */
    fillTempBuffer();
    testSDReadWrite(tempBuffer);

    curr_read_block = curr_block;
    
    ConfigTimer1(); // Enable Timer1 for second counts
    configureInterrupts();

    // T2CON = 0x8030; // TMR1 on, prescale 1:256 PB

    mPORTASetPinsDigitalOut( LED_MASK ); // LEDs = output
    mPORTDSetPinsDigitalIn( PB_MASK_D ); // PBs on D = input

    curr_state = READY;
    // enable interrupts
    INTEnableInterrupts();
    int i = 0;
    while( 1 )
    {
        if (getPrintToUARTFlag() == 1){
            LCDMenuControl();
        
            //mPORTAToggleBits( LED_MASK );
            convertAndPrintIntegerToString("i => ", i++);
            convertAndPrintIntegerToString("timeElapse => ", timeElapsed);
            convertAndPrintIntegerToString("timeElapsedLEDSample => ", timeElapsedLEDSample);
            convertAndPrintIntegerToString("timeElapsedLEDTurnedOff => ", timeElapsedLEDTurnedOff);
            convertAndPrintIntegerToString("sampleLEDNow => ", sampleLEDNow);

            convertAndPrintIntegerToString(" ADC Value => ", getChannel5Value());
            printShadowDetect();
            printLightLevel();
            drawLightDetectedBar();
            controlPowerRelay();

            switch(curr_state) {
            case READY : WriteString("State => READY     ");
                        break;
            case SLEEP : WriteString("State => SLEEP    ");
                        break;
            case HIBERNATE : WriteString("State => HIBERNATE");
                        break;
            case BUSY : WriteString("State => BUSY     ");
                        break;
            }

            WriteString("\r");
            
            setPrintToUARTFlag(0);
        }
        if (NEW_BYTE_RECEIVED == 1){
            curr_state = READY;
            NEW_BYTE_RECEIVED = 0;
            //mPORTAToggleBits( LED_MASK );
            char tempArray[] = "g";
            tempArray[0] = characterByteReceived;
            WriteString(tempArray);
            if(curr_state = HIBERNATE) {
                addByteToBuffer(characterByteReceived);
            }
            else {
                PutCharacter(characterByteReceived);
            }
        }
        if(bufferIndex == 512) {
            SDWriteBlock(currBlock);
            currBlock++;
            bufferIndex = 0;
        }
         if((curr_state == READY) && (timeElapsed >= SLEEP_TIMEOUT) && (timeElapsed < HIBERNATE_TIMEOUT)) {
             curr_state = SLEEP;
         }
         else if((curr_state == SLEEP) && (timeElapsed >= HIBERNATE_TIMEOUT)) {
             curr_state = HIBERNATE;
             timeElapsed = 0;
         }
        if (transmitDataFromSDCard == 1) {
            transmitDataFromSDCard = 0;
            forwardDataToPrinter();
        }
    } // main (while) loop

    return 0;

} // main
Exemplo n.º 10
0
int
ParseInput(register DviWidget dw)
{
	int		n, k;
	int		c;
	char		Buffer[BUFSIZ];
	int		NextPage;
	int		otherc;

	StopSeen = 0;

	/*
	 * make sure some state exists
	 */

	if (!dw->dvi.state)
	    push_env (dw);
	for (;;) {
		switch (DviGetC(dw, &c)) {
		case '\n':	
			break;
		case ' ':	/* when input is text */
		case 0:		/* occasional noise creeps in */
			break;
		case '{':	/* push down current environment */
			push_env(dw);
			break;
		case '}':
			pop_env(dw);
			break;
		/*
		 * two motion digits plus a character
		 */
		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			HorizontalMove(dw, (c-'0')*10 +
					   DviGetC(dw,&otherc)-'0');
			/* fall through */
		case 'c':	/* single ascii character */
			DviGetC(dw,&c);
		    	if (c == ' ')
			    break;
			Buffer[0] = c;
			Buffer[1] = '\0';
			(void) PutCharacter (dw, Buffer);
			break;
		case 'C':
			GetWord (dw, Buffer, BUFSIZ);
			(void) PutCharacter (dw, Buffer);
			break;
		case 't':
			Buffer[1] = '\0';
			while (DviGetC (dw, &c) != EOF
			       && c != ' ' && c != '\n') {
				Buffer[0] = c;
				HorizontalMove (dw, PutCharacter (dw, Buffer));
			}
			break;
		case 'u':
			n = GetNumber(dw);
			Buffer[1] = '\0';
			while (DviGetC (dw, &c) == ' ')
				;
			while (c != EOF && c != ' ' && c != '\n') {
				Buffer[0] = c;
				HorizontalMove (dw,
						PutCharacter (dw, Buffer) + n);
				DviGetC (dw, &c);
			}
			break;

		case 'D':	/* draw function */
			(void) GetLine(dw, Buffer, BUFSIZ);
			if (dw->dvi.display_enable)
				ParseDrawFunction(dw, Buffer);
			break;
		case 's':	/* ignore fractional sizes */
			n = GetNumber(dw);
			dw->dvi.state->font_size = n;
			break;
		case 'f':
			n = GetNumber(dw);
			dw->dvi.state->font_number = n;
			break;
		case 'H':	/* absolute horizontal motion */
			k = GetNumber(dw);
			HorizontalGoto(dw, k);
			break;
		case 'h':	/* relative horizontal motion */
			k = GetNumber(dw);
			HorizontalMove(dw, k);
			break;
		case 'w':	/* word space */
			Word (dw);
			break;
		case 'V':
			n = GetNumber(dw);
			VerticalGoto(dw, n);
			break;
		case 'v':
			n = GetNumber(dw);
			VerticalMove(dw, n);
			break;
		case 'P':	/* new spread */
			break;
		case 'p':	/* new page */
			(void) GetNumber(dw);
			NextPage = dw->dvi.current_page + 1;
			RememberPagePosition(dw, NextPage);
			FlushCharCache (dw);
			return(NextPage);
		case 'N':
			n = GetNumber(dw);
			PutNumberedCharacter (dw, n);
			break;
		case 'n':	/* end of line */
			GetNumber(dw);
			GetNumber(dw);
			Newline (dw);
			HorizontalGoto(dw, 0);
			break;
		case 'F':       /* input files */
		case '+':	/* continuation of X device control */
		case 'm':	/* color */
		case '#':	/* comment */
			GetLine(dw, NULL, 0);
			break;
		case 'x':	/* device control */
			ParseDeviceControl(dw);
			break;
		case EOF:
			dw->dvi.last_page = dw->dvi.current_page;
			FlushCharCache (dw);
			return dw->dvi.current_page;
		default:
			break;
		}
	}
}
Exemplo n.º 11
0
void _mon_putc(char c) {
    PutCharacter(UART3, c);
}
Exemplo n.º 12
0
void WriteString(UART_MODULE id, const char *string) {
    while (*string != '\0') {
        PutCharacter(id, *string);
        string++;
    }
}
Exemplo n.º 13
0
int main(void)
{
	// Declare local variables
	unsigned char switches;

	
	// Initialize the SAM4 board
	sysclk_init();
	board_init();
	
	// Initialize the IO board
	my_ioport_init();
	
	// Initialize UART3
	uart3_init();
	
	// Set LCD to Cursor Mode
	PutCharacter(0x1B);
	PutCharacter('[');
	PutCharacter('1');
	PutCharacter('c');
	
	// Set LCD to clear display and home cursor
	PutCharacter(0x1B);
	PutCharacter('[');
	PutCharacter('j');
	
		// Loop section
	
	while (true) {
		
		// Send command to move cursor back to start of first line
		PutCharacter(0x1B);
		PutCharacter('[');
		PutCharacter('0');
		PutCharacter(';');
		PutCharacter('0');
		PutCharacter('H');
		
		// Put letter Y to lcd screen
		PutCharacter('Y');
		
		// Send command to move cursor to start of second line
		PutCharacter(0x1B);
		PutCharacter('[');
		PutCharacter('1');
		PutCharacter(';');
		PutCharacter('0');
		PutCharacter('H');
		
		// send letter R
		PutCharacter('R');
        
        // wait 5 seconds
		delay_ms(5000);
		
		// move to start of first line
		PutCharacter(0x1B);
		PutCharacter('[');
		PutCharacter('0');
		PutCharacter(';');
		PutCharacter('0');
		PutCharacter('H');
		
		// send letter U
		PutCharacter('U');
		
		// move to start of second line
		PutCharacter(0x1B);
		PutCharacter('[');
		PutCharacter('1');
		PutCharacter(';');
		PutCharacter('0');
		PutCharacter('H');
		
		// send the word "here"
		PutCharacter('H');
		PutCharacter('E');
		PutCharacter('R');
		PutCharacter('E');
		
		// wait 5 seconds
		delay_ms(5000);
		
	}


	
	

} // end of main, never reached