Пример #1
0
void  LED_Toggle (CPU_INT08U led)
{
    switch (led) {
        case 0:
             mPORTAToggleBits((IOPORT_BIT_0 | IOPORT_BIT_1 | IOPORT_BIT_2 | IOPORT_BIT_3 |
                               IOPORT_BIT_4 | IOPORT_BIT_5 | IOPORT_BIT_6 | IOPORT_BIT_7));
             break;
        case 1:
             mPORTAToggleBits(IOPORT_BIT_0);
             break;
        case 2:
             mPORTAToggleBits(IOPORT_BIT_1);
             break;
        case 3:
             mPORTAToggleBits(IOPORT_BIT_2);
             break;
        case 4:
             mPORTAToggleBits(IOPORT_BIT_3);
             break;
        case 5:
             mPORTAToggleBits(IOPORT_BIT_4);
             break;
        case 6:
             mPORTAToggleBits(IOPORT_BIT_5);
             break;
        case 7:
             mPORTAToggleBits(IOPORT_BIT_6);
             break;
        case 8:
             mPORTAToggleBits(IOPORT_BIT_7);
             break;
        default:
             break;
    }
}
Пример #2
0
int main(void)
{
	int i;

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// 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(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);


	// Explorer16 LEDs are on lower 8-bits of PORTA and to use all LEDs, JTAG port must be disabled.
	mJTAGPortEnable(DEBUG_JTAGPORT_OFF);

	// Make all lower 8-bits of PORTA as output. Turn them off before changing
	// direction so that we don't have unexpected flashes
	mPORTAClearBits(BIT_7 | BIT_6 | BIT_5 | BIT_5 | BIT_4 | \
							 BIT_3 | BIT_2 | BIT_1 | BIT_0 );

	mPORTASetPinsDigitalOut( BIT_7 | BIT_6 | BIT_5 | BIT_5 | BIT_4 | \
							 BIT_3 | BIT_2 | BIT_1 | BIT_0 );

	// Now blink all LEDs ON/OFF forever.
	while(1)
	{
		mPORTAToggleBits(BIT_7 | BIT_6 | BIT_5 | BIT_5 | BIT_4 | \
							 BIT_3 | BIT_2 | BIT_1 | BIT_0 );

		// Insert some delay
		i = 1024*1024*10;
		while(i--);
	}
}
/**
 * The first protothread function. A protothread function must always
 * return an integer, but must NEVER explicitly return - returning is
 * performed inside the protothread statements.
 *
 * The protothread function is driven by the main loop further down in
 * the code.
 */
static PT_THREAD (protothread1(struct pt *pt))
{
    // mark beginning of thread
    PT_BEGIN(pt);

    /* We loop forever here. */
    while(1) {

        //stop until thread 2 signals
        PT_SEM_WAIT(pt, &control_t1);
        // put a 2 microsec pulse on the debug pin with amplitude 3
        PT_DEBUG_VALUE(3, 2) ;
        
        // toggle a port pin
        mPORTAToggleBits(BIT_0);

         // tell thread 2 to go
        PT_SEM_SIGNAL(pt, &control_t2);
        
        // Allow thread 3 to control blinking
        // thru command interface
        PT_YIELD_UNTIL(pt, cntl_blink) ;

        // This is a locally written macro using  timer5 to count millisec
        // to program a yield time
        PT_YIELD_TIME_msec(wait_t1) ;
        
        // NEVER exit while
    } // END WHILE(1)

  // mark end the thread
  PT_END(pt);
} // thread 1
// 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:

		
	}
}
Пример #5
0
int main(int argc, char** argv) {

    mPORTAClearBits(BIT_6);           //Clear bits to ensure the LED is off.
    mPORTASetPinsDigitalOut(BIT_6);   //Set port as output
  
     while(1)
     {
        //PORTAbits.RA2 = ~PORTAbits.RA2;
        mPORTAToggleBits(BIT_6);
         delay_millis(100);
     }
     
    return (EXIT_SUCCESS);
}
// === Thread 2 ======================================================
//
static PT_THREAD (protothread2(struct pt *pt))
{
    PT_BEGIN(pt);

      while(1) {
            
            //stop until thread 1 signals
            PT_SEM_WAIT(pt, &control_t2);

            // put a 5 microsec pulse on the debug pin with amplitude 6
            PT_DEBUG_VALUE(6, 5) ;

            // toggle a port
            mPORTAToggleBits(BIT_1);

            // tell thread 1 to go
            PT_SEM_SIGNAL(pt, &control_t1);
            
            // NEVER exit while
      } // END WHILE(1)
  PT_END(pt);
} // thread 2
Пример #7
0
int
main() 
{
	SYSTEMConfigPerformance(FCY);

	/* JTAG off */
	DDPCONbits.JTAGEN = 0;

	/* RA0 = 0 */
	mPORTAClearBits(BIT_0);

	/* RA0 O/P */
	mPORTASetPinsDigitalOut(BIT_0);

	while(1) {
		/*  F = 10 Hz */
		delay_ms(50);

		/* RA0 = ! RA0 */
		mPORTAToggleBits(BIT_0);
	}
	return 0;
}
Пример #8
0
int main(int argc, char** argv) {

    uchar status = 0;
    
    mPORTAClearBits(BIT_6);           //Clear bits to ensure the LED is off.
    //mPORTASetPinsDigitalOut(BIT_6);   //Set port as output
  
    // lets set the digital IO bits for the ethernet module
    mPORTASetPinsDigitalOut(BIT_7|BIT_6);
    mPORTGSetPinsDigitalOut(BIT_8 | BIT_9 | BIT_14 | BIT_0);
    mPORTBSetPinsDigitalOut(0x0000FFFF);
    mPORTESetPinsDigitalOut(0x000000FF);
    
    // set the control bits high
    mPORTASetBits(BIT_7);
    mPORTGSetBits(BIT_8 | BIT_9 | BIT_14);
    mPORTGClearBits(BIT_0);
    //mPORTGClearBits(BIT_0);
    //mPORTGClearBits(0x0000FFFF);
    //mPORTEClearBits(0x0000FFFF);
    //mPORTAClearBits(0x0000FFFF);
    //mPORTBClearBits(0x0000FFFF);
    
    //while(1){}

    // lets init the W5100
    struct W5100Context_t context;
    context.Mode = MR_RST;
    context.InterruptMask = 0xFF;
    context.RetryTimeValue = 0x0FA0; // 400 ms
    context.RetryCount = 1;
    
    context.GateAdd[0] = 10;
    context.GateAdd[1] = 1;
    context.GateAdd[2] = 1;
    context.GateAdd[3] = 3;
    
    context.SHardAdd[0] = 0;
    context.SHardAdd[1] = 1;
    context.SHardAdd[2] = 2;
    context.SHardAdd[3] = 3;
    context.SHardAdd[4] = 4;
    context.SHardAdd[5] = 5;
    
    context.Subnet[0] = 255;
    context.Subnet[1] = 255;
    context.Subnet[2] = 255;
    context.Subnet[3] = 0;
    
    context.SourceIP[0] = 10;
    context.SourceIP[1] = 1;
    context.SourceIP[2] = 1;
    context.SourceIP[3] = 2;
    
    context.sockets[0].Mem = MEM_2K;
    context.sockets[1].Mem = MEM_2K;
    context.sockets[2].Mem = MEM_2K;
    context.sockets[3].Mem = MEM_2K;
    
    ShortDelay_ms(100);
    
    W5100Init( &context );
  
    W5100ReadData(SHAR0, &status, 1);
    W5100ReadData(SHAR1, &status, 1);
    W5100ReadData(SHAR2, &status, 1);
    W5100ReadData(SHAR3, &status, 1);
    W5100ReadData(SHAR4, &status, 1);
    W5100ReadData(SHAR5, &status, 1);
    
    EstablishServer(&context);
    
    // lets try a random write
    //W5100WriteData(0x001A, 0x07, 1);
    //mPORTEWrite(0x07);
    
    
  
    
     while(1)
     {
     
        status = W5100PollStatus(&context, 0);
        if( status == SOCK_ESTABLISH)
            mPORTGSetBits(BIT_0);
        else
            mPORTGClearBits(BIT_0);
        
        if( status == SOCK_CLOSE_WAIT)
            EstablishServer(&context);
        
        
         //PORTAbits.RA2 = ~PORTAbits.RA2;
        mPORTAToggleBits(BIT_6);
        ShortDelay(US_TO_CT_TICKS*1000000);
        //delay_millis(1000);
   
     }
     
    return (EXIT_SUCCESS);
}