예제 #1
0
void BSP_LEDToggle(BSP_LED led)
{
	if (led == LED_1 || led == LED_2)
	{
		PLIB_PORTS_PinToggle(PORTS_ID_0, PORT_CHANNEL_A, led);
	}
	else
	{
        PLIB_PORTS_PinToggle(PORTS_ID_0, PORT_CHANNEL_D, led);
	}
}
예제 #2
0
파일: app.c 프로젝트: kill4n/Kuro_ACM
void APP_Tasks(void) {
    /* Check the application's current state. */
    switch (appData.state) {
            /* Application's initial state. */
        case APP_STATE_INIT:
        {
            DRV_TMR0_Start();
            PLIB_PORTS_PinSet(PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_1); // Turn on LED #4 (RA1)
            appData.state = APP_STATE_IDLE;
            break;
        }

            /* TODO: implement your application state machine.*/
        case APP_STATE_EVENT:
        {
            //PLIB_PORTS_PinWrite(PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_1, 1);
            PLIB_PORTS_PinToggle(PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_1);
            appData.state = APP_STATE_IDLE;
            break;
        }

        case APP_STATE_IDLE:
        {
            break;
        }
            /* The default state should never be executed. */
        default:
        {
            /* TODO: Handle error in application's state machine. */
            break;
        }
    }
}
예제 #3
0
파일: main.c 프로젝트: ctapang/v0_70_01b
int main(void)
{
    int i;

    // Set PORTH pins to output (for the three starter-kit LEDs),
    // clear the pins to ensure LEDs are off
    PLIB_PORTS_PinModePerPortSelect(PORTS_ID_0, PORT_CHANNEL_H,PORTS_BIT_POS_0,PORTS_PIN_MODE_DIGITAL);
    PLIB_PORTS_PinModePerPortSelect(PORTS_ID_0, PORT_CHANNEL_H,PORTS_BIT_POS_1,PORTS_PIN_MODE_DIGITAL);
    PLIB_PORTS_PinModePerPortSelect(PORTS_ID_0, PORT_CHANNEL_H,PORTS_BIT_POS_2,PORTS_PIN_MODE_DIGITAL);
    PLIB_PORTS_DirectionOutputSet(PORTS_ID_0, PORT_CHANNEL_H, (PORTS_DATA_MASK)0x07);
    PLIB_PORTS_Clear(PORTS_ID_0, PORT_CHANNEL_H, (PORTS_DATA_MASK)0x07);
    //ANSELH = 0;
    //TRISH = 0;
    //LATH = 0;

    // Enable the watchdog timer, turn on the red LED to indicate the device is going into sleep
    // mode, then service the watchdog timer
    PLIB_WDT_Enable(WDT_ID_0);
    PLIB_PORTS_PinSet(PORTS_ID_0, PORT_CHANNEL_H, PORTS_BIT_POS_0);
    //LATHSET = 0x1;
    PLIB_WDT_TimerClear(WDT_ID_0);
    //WDTCONbits.WDTCLRKEY = 0x5743;

    // Put device into power saving sleep mode - the device will resume normal
    // operation when the WDT fails to be serviced and triggers a WDT timeout reset
    PLIB_POWER_DeepSleepModeEnable(POWER_ID_0);
    //OSCCONbits.SLPEN = 1;
    asm volatile("WAIT");

    // The device is now out of sleep mode, turn off the WDT so that it does
    // not reset the system after another timeout
    PLIB_WDT_Disable(WDT_ID_0);

    // Turn off the red LED
    PLIB_PORTS_PinClear(PORTS_ID_0, PORT_CHANNEL_H, PORTS_BIT_POS_0);
    //LATHCLR = 0x1;

    while (1)
    {
        // Blink green LED to indicate device is functioning normally
        PLIB_PORTS_PinToggle(PORTS_ID_0, PORT_CHANNEL_H, PORTS_BIT_POS_2);
        //LATHINV = 0x4;

        // Some delay
        i = 1000 * 1000 * 10;
        while (i--);
    }

     /* Program should not go here during normal operation */
    return EXIT_FAILURE;
}
예제 #4
0
파일: app.c 프로젝트: hjph/Prueba1
void MyISR(uintptr_t context, uint32_t alarmCount)
{
    static unsigned int contador = 10;
    
    contador--;
    if(!contador)
    {
        contador = 10;
        PLIB_PORTS_PinToggle(PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_0);
    }
    //if(!escribir)
        //escribir =1;
   
}
예제 #5
0
파일: main.c 프로젝트: ctapang/v0_70_01b
int main(void)
{
    int i;

    /* Disable JTAG to free up PORTA pins */
    DDPCONbits.JTAGEN = 0;

    /* Set the lower 8 bits of PORTA as output (for Explorer-16 LEDs),
       clear the bits to ensure there is no mismatch when they are toggled */
    PLIB_PORTS_DirectionOutputSet(PORTS_ID_0, PORT_CHANNEL_A, (PORTS_DATA_MASK)0x00FF);
    PLIB_PORTS_Clear(PORTS_ID_0, PORT_CHANNEL_A, (PORTS_DATA_MASK)0x00FF);

    // Enable the watchdog timer, turn on the left-most LED to indicate the device will be in sleep
    // mode, then service the watchdog timer
    PLIB_WDT_Enable(WDT_ID_0);
    PLIB_PORTS_PinSet(PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_7); 
    PLIB_WDT_TimerClear(WDT_ID_0); 

    // Put device into power saving sleep mode - the device will resume normal
    // operation when the WDT fails to be serviced and triggers a WDT timeout
    // reset
    PLIB_POWER_DeepSleepModeEnable(POWER_ID_0);

    // The device is now out of sleep mode, turn off the WDT so that it does
    // not reset the system after another timeout
    PLIB_WDT_Disable(WDT_ID_0);

    // Turn off the left-most LED 
    PLIB_PORTS_PinClear(PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_7);

    while (1)
    {
        // Toggle first (right-most) LED to indicate device is out of sleep mode
        PLIB_PORTS_PinToggle(PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_0);

        // Some delay
        i = 1000 * 200;
        while(i--);
    }
}
예제 #6
0
파일: app.c 프로젝트: jmchuber/Rover_TEST
void APP_Tasks ( void )
{
    /* Check the application's current state. */
    switch ( appData.state )
    {
        /* Application's initial state. */
        case APP_STATE_INIT:
        {
            appData.state = APP_STATE_RECEIVE;
            break;
        }

        /* TODO: implement your application state machine.*/
        case APP_STATE_RECEIVE:
        {
            if(!DRV_USART_ReceiverBufferIsEmpty(tempUART_0))
            {
                appData.data = DRV_USART_ReadByte(tempUART_0);
                appData.state = APP_STATE_SEND;
                PLIB_PORTS_PinToggle(PORTS_ID_0, PORT_CHANNEL_C, PORTS_BIT_POS_1);
            }
        }
        case APP_STATE_SEND:
        {
            if( !(DRV_USART_TRANSFER_STATUS_TRANSMIT_FULL & DRV_USART_TransferStatus(tempUART_0)) )
            {
                DRV_USART_WriteByte(tempUART_0,'a');
                appData.state = APP_STATE_RECEIVE;
            }
        }
        
        /* The default state should never be executed. */
        default:
        {
            /* TODO: Handle error in application's state machine. */
            break;
        }
    }
}
예제 #7
0
void SYS_PORTS_PinToggle ( PORTS_MODULE_ID index,
                           PORTS_CHANNEL channel,
                           PORTS_BIT_POS bitPos )
{
    PLIB_PORTS_PinToggle ( index, channel, bitPos );
}
예제 #8
0
파일: app.c 프로젝트: govorox/pic-can-mon
void APP_Tasks ( void )
{
    /* Check the application's current state. */
    switch ( appData.state )
    {
        /* Application's initial state. */
        case APP_STATE_INIT:
        {
            SYS_CONSOLE_Flush( SYS_CONSOLE_INDEX_0 );
            
            //ssize_t nr;
            //char myBuffer[] = "\r\npic-CAN-mon";
            //nr = SYS_CONSOLE_Write( SYS_CONSOLE_INDEX_0, STDOUT_FILENO, myBuffer, strlen(myBuffer) );
            //if (nr != strlen(myBuffer))
            //{
            //    // Handle error
            //}
            SYS_PRINT("\r\npicCANmon");
            appData.state = APP_STATE_IDLE;
            break;
        }
        
        case APP_STATE_IDLE:
        {
            PLIB_PORTS_PinToggle(PORTS_ID_0, PORT_CHANNEL_G,
                                 PORTS_BIT_POS_14);
           /* 
            CAN_CHANNEL_EVENT channelEvent;
            channelEvent = PLIB_CAN_ChannelEventGet(CAN_ID_1, CAN_CHANNEL1);
            if((channelEvent & (CAN_RX_CHANNEL_NOT_EMPTY | CAN_RX_CHANNEL_FULL)) != 0) {
                SYS_MESSAGE("\r\nCAN RX\r\n");
                PLIB_PORTS_PinToggle(PORTS_ID_0, PORT_CHANNEL_G,
                                 PORTS_BIT_POS_12);
            }
            */
            
            CAN232_Tasks();
            
            ssize_t nr = 0;
            do {
                nr = SYS_CONSOLE_ReadX( SYS_CONSOLE_INDEX_0, STDIN_FILENO,
                                       &cmdBuffer[cmdTail], 0 );
                if (nr > 0)
                {
                    cmdTail += nr;
                    if (cmdTail >= sizeof(cmdBuffer))
                        cmdTail = 0;
                    //cmdBuffer[cmdTail] = 0;

                    appData.state = APP_STATE_INPUT;

                    PLIB_PORTS_PinToggle(PORTS_ID_0, PORT_CHANNEL_G,
                                         PORTS_BIT_POS_15);
                }
            } while (nr > 0);
            
            break;
        }
        
        case APP_STATE_INPUT:
        {
            appData.state = APP_STATE_IDLE;
            
            if (cmdTail > 0) {
                PLIB_PORTS_PinToggle(PORTS_ID_0, PORT_CHANNEL_G,
                                 PORTS_BIT_POS_13);
                
                char ch = cmdBuffer[cmdTail-1];
                if (ch < ' ') {
                    if (ch == '\r' || ch == '\n') {
                        cmdBuffer[cmdTail] = 0;
                        appData.state = APP_STATE_COMMAND;
                    }
                    cmdTail = 0;
                }
                else 
                {
                    // echo back
                    if (echoInput)
                        SYS_CONSOLE_Write( SYS_CONSOLE_INDEX_0, STDOUT_FILENO,
                                           &cmdBuffer[cmdTail-1], 1);
                }
                
            }
            break;
        }
        
        case APP_STATE_COMMAND: {
            
            //SYS_PRINT("\r\nCMD:%s", cmdBuffer);
            CAN232_Command(cmdBuffer);          
            
            cmdBuffer[0] = 0;   // Reset command buffer
            cmdTail = 0;
            
            appData.state = APP_STATE_IDLE;
            break;
        }

        /* TODO: implement your application state machine.*/

        /* The default state should never be executed. */
        default:
        {
            /* TODO: Handle error in application's state machine. */
            break;
        }
    }
}
void BSP_LEDToggle(BSP_LED_CHANNEL led_channel, BSP_LED_PORT led_port)
{
    PLIB_PORTS_PinToggle( PORTS_ID_0, led_channel, led_port);
}
예제 #10
0
파일: bsp.c 프로젝트: ctapang/v0_70_01b
/*
*********************************************************************************************************
*                                              LED TOGGLE
*
* Description : This function is used to alternate the state of an LED
*
*********************************************************************************************************
*/
void  LED_Toggle (void)
{
    PLIB_PORTS_PinToggle(PORTS_ID_0,PORT_CHANNEL_H,PORTS_BIT_POS_0);
}
예제 #11
0
void BSP_LEDToggle(BSP_LED led)
{
    PLIB_PORTS_PinToggle(PORTS_ID_0, PORT_CHANNEL_H, led );
}