void initLEDs()
{
    mPORTDClearBits(BIT_1); //yellow
    mPORTGClearBits(BIT_6); //green
    notifyOnCommandProcessed();
    notifyOffCommandProcessed();
}
void __ISR(_TIMER_4_VECTOR, ipl4) interruptForTransmitingIRSignals(void)
{
    if (mT4GetIntFlag())
    {
        if (irTransmitBufferIndex >= IR_TRANSMSIT_BUFFER_SIZE)
        {
            OC3CONbits.ON = 0;
            irTransmitBufferIndex = 0;
            T4CONbits.ON = 0;
            sendingIR = 0;
            mPORTGClearBits(BIT_6);
            //printf("S\r\n");
        }
        else
        {
            //printf("T\r\n");
            mPORTGToggleBits(BIT_6);
            //toggle OC3
            OC3CONINV = 0b1000000000000000;
            //OC3CONbits.ON = !OC3CONbits.ON;
            //mPORTBToggleBits(BIT_13);
            PR4 = irTransmitBuffer[irTransmitBufferIndex++];
            TMR4 = 0;
        }
        mT4ClearIntFlag();
    }
}
Example #3
0
void vLCDTFTWriteCommand(UINT16 Data){
    
    mPORTGClearBits(LCD_PIN_RS);
    mPORTDClearBits(LCD_PIN_CS);
    mPORTDClearBits(LCD_PIN_WR); 
    PMPMasterWrite(Data);
    mPORTDSetBits(LCD_PIN_WR);
    mPORTDSetBits(LCD_PIN_CS);  
}
Example #4
0
void InitializeSystem()
{
	SYSTEMConfigWaitStatesAndPB(CLOCK_FREQ);
	mOSCSetPBDIV(OSC_PB_DIV_4);  // Set to get 20MHz PB clock
  //mOSCSetPBDIV(OSC_PB_DIV_2);
	CheKseg0CacheOn();
	mJTAGPortEnable(0);

	// Initialize the pins to all digital output and driven to ground.
	// Exception is RE7 and RE6 which are switch inputs
	PORTSetPinsDigitalIn(IOPORT_E, BIT_6);
	PORTSetPinsDigitalIn(IOPORT_E, BIT_7);

	mPORTASetPinsDigitalOut(0xFFFF);
	mPORTBSetPinsDigitalOut(0xFFFF);
	mPORTCSetPinsDigitalOut(0xFFFF);
	mPORTDSetPinsDigitalOut(0xFFFF);
	mPORTESetPinsDigitalOut(0xFF3F);
	mPORTFSetPinsDigitalOut(0xFFFF);
	mPORTGSetPinsDigitalOut(0xFFFF);

	mPORTAClearBits(0xFFFF);
	mPORTBClearBits(0xFFFF);
	mPORTCClearBits(0xFFFF);
	mPORTDClearBits(0xFFFF);
	mPORTEClearBits(0xFF3F);
	mPORTESetBits(0x000F);		// LED latches need to be set high for off
	mPORTFClearBits(0xFFFF);
	mPORTGClearBits(0xFFFF);

	INTEnableSystemMultiVectoredInt();

  #ifdef SANITY_CHECK
  mLED_Green_On();
  #endif
	
	//LCD_Initialize();
	//WIFI_Initialize();
	//SPRINKLER_Initialize();
	//RTCC_Initialize(); 
  //SERIALUSB_Initialize();
	SDCARD_Initialize();

  TCPIP_Initialize();
}
Example #5
0
void chip_select(void)
{
	mPORTDSetPinsDigitalOut(BIT_12);        	//chip select for eeprom
	mPORTDSetBits(BIT_12);  
	mPORTGSetPinsDigitalOut(BIT_8 | BIT_6);     //master out slave in  & SCK
	mPORTGClearBits(BIT_6 | BIT_8);           /* SCK(RG6) and SDO(RG8) low */
	mPORTGSetPinsDigitalIn(BIT_7);    	        //master in slav out
	mPORTGSetBits(BIT_7);
	mPORTDSetPinsDigitalOut(BIT_8);             //write protect
	mPORTDSetBits(BIT_8);        

//config SPI2....!!!!
	SPI2CONbits.SIDL 	= 0; 	// Continue module operation in Idle mode
  	SPI2CONbits.DISSDO	= 0;	// SDOx pin is controlled by the module

	SPI2CON=0; 
	SPI2CON=0x00008360;				//enable the spi peripheral-8160
	SPI2BRG=15;            			// use Fpb/10 clock frequency will give 10MHz....40/(2*(1+1))=10Mhz
	IEC1CLR=0xE0;          			// disable all interrupts
	IFS1CLR=0xE0;        			// clear any existing event
    IPC7CLR=0x1f000000;     		// clear the priority
}
//********************************
//********************************
//********** INITIALISE **********
//********************************
//********************************
void initialise (void)
{
	BYTE data;
	
	//##### GENERAL NOTE ABOUT PIC32'S #####
	//Try and use the peripheral libraries instead of special function registers for everything (literally everything!) to avoid
	//bugs that can be caused by the pipeline and interrupts.
	

	//---------------------------------
	//----- CONFIGURE PERFORMANCE -----
	//---------------------------------
	
	//----- SETUP EVERYTHING FOR OPTIMUM PERFORMANCE -----
	SYSTEMConfigPerformance(80000000ul);		//Note this sets peripheral bus to '1' max speed (regardless of configuration bit setting)
												//Use PBCLK divider of 1:1 to calculate UART baud, timer tick etc


	//----- SET PERIPHERAL BUS DIVISOR -----
	//To minimize dynamic power the PB divisor should be chosen to run the peripherals at the lowest frequency that provides acceptable system performance
	mOSCSetPBDIV(OSC_PB_DIV_2);			//OSC_PB_DIV_1, OSC_PB_DIV_2, OSC_PB_DIV_4, OSC_PB_DIV_8, 

	//----- SETUP INTERRUPTS -----
	INTEnableSystemMultiVectoredInt();

	//-------------------------
	//----- SETUP IO PINS -----
	//-------------------------
	//(Device will powerup with all IO pins as inputs)

	//----- TURN OFF THE JTAG PORT -----
	//(JTAG is on by default)
	//mJTAGPortEnable(0);		//Must be on for Microchip Multimedia Development board

	#define	PORTA_IO	0xc2ff				//Setup the IO pin type (0 = output, 1 = input)
	mPORTAWrite(0xc033);					//Set initial ouput pin states
	mPORTASetPinsDigitalIn(PORTA_IO);		//(Sets high bits as input)
	mPORTASetPinsDigitalOut(~PORTA_IO);		//(Sets high bits as output)
	
	#define	PORTB_IO	0xfbff				//Setup the IO pin type (0 = output, 1 = input)
	mPORTBWrite(0x6d13);					//Set initial ouput pin states
	mPORTBSetPinsDigitalIn(PORTB_IO);		//(Sets high bits as input)
	mPORTBSetPinsDigitalOut(~PORTB_IO);		//(Sets high bits as output)

	mPORTBSetPinsDigitalIn(BIT_0 | BIT_1 | BIT_3 | BIT_4 | BIT_15);			//Joystick inputs

	#define	PORTC_IO	0xf01e				//Setup the IO pin type (0 = output, 1 = input)
	mPORTCWrite(0x3018);					//Set initial ouput pin states
	mPORTCSetPinsDigitalIn(PORTC_IO);		//(Sets high bits as input)
	mPORTCSetPinsDigitalOut(~PORTC_IO);		//(Sets high bits as output)

	#define	PORTD_IO	0x7bfe				//Setup the IO pin type (0 = output, 1 = input)
	mPORTDWrite(0xbdaf);					//Set initial ouput pin states
	mPORTDSetPinsDigitalIn(PORTD_IO);		//(Sets high bits as input)
	mPORTDSetPinsDigitalOut(~PORTD_IO);		//(Sets high bits as output)

	mPORTDSetPinsDigitalOut(BIT_2 | BIT_1);		//LED's 2 and 3
	mPORTDSetPinsDigitalIn(BIT_9);

	#define	PORTE_IO	0x03ff				//Setup the IO pin type (0 = output, 1 = input)
	mPORTEWrite(0x02a2);					//Set initial ouput pin states
	mPORTESetPinsDigitalIn(PORTE_IO);		//(Sets high bits as input)
	mPORTESetPinsDigitalOut(~PORTE_IO);		//(Sets high bits as output)

	#define	PORTF_IO	0x111f				//Setup the IO pin type (0 = output, 1 = input)
	mPORTFWrite(0x0039);					//Set initial ouput pin states
	mPORTFSetPinsDigitalIn(PORTF_IO);		//(Sets high bits as input)
	mPORTFSetPinsDigitalOut(~PORTF_IO);		//(Sets high bits as output)

	#define	PORTG_IO	0xd3cf				//Setup the IO pin type (0 = output, 1 = input)
	mPORTGWrite(0xf203);					//Set initial ouput pin states
	mPORTGSetPinsDigitalIn(PORTG_IO);		//(Sets high bits as input)
	mPORTGSetPinsDigitalOut(~PORTG_IO);		//(Sets high bits as output)



	//Read pins using:
	// mPORTAReadBits(BIT_0);
	//Write pins using:
	// mPORTAClearBits(BIT_0);
	// mPORTASetBits(BIT_0);
	// mPORTAToggleBits(BIT_0);



	//----- INPUT CHANGE NOTIFICATION CONFIGURATION -----
	//EnableCN0();
	ConfigCNPullups(CN2_PULLUP_ENABLE | CN3_PULLUP_ENABLE | CN5_PULLUP_ENABLE | CN6_PULLUP_ENABLE | CN12_PULLUP_ENABLE);		//Joystick pins



	//----- SETUP THE A TO D PINS -----
	ENABLE_ALL_DIG;


	//---------------------
	//----- SETUP USB -----
	//---------------------
	//The USB specifications require that USB peripheral devices must never source current onto the Vbus pin.  Additionally, USB peripherals should not source
	//current on D+ or D- when the host/hub is not actively powering the Vbus line.  When designing a self powered (as opposed to bus powered) USB peripheral
	//device, the firmware should make sure not to turn on the USB module and D+ or D- pull up resistor unless Vbus is actively powered.  Therefore, the
	//firmware needs some means to detect when Vbus is being powered by the host. A 5V tolerant I/O pin can be connected to Vbus (through a resistor), and
	//can be used to detect when Vbus is high (host actively powering), or low (host is shut down or otherwise not supplying power).  The USB firmware
	//can then periodically poll this I/O pin to know when it is okay to turn on the USB module/D+/D- pull up resistor.  When designing a purely bus powered
	//peripheral device, it is not possible to source current on D+ or D- when the host is not actively providing power on Vbus. Therefore, implementing this
	//bus sense feature is optional.  This firmware can be made to use this bus sense feature by making sure "USE_USB_BUS_SENSE_IO" has been defined in the
	//HardwareProfile.h file.    
    //	#if defined(USE_USB_BUS_SENSE_IO)
    //	tris_usb_bus_sense = INPUT_PIN; // See HardwareProfile.h
    //	#endif
    
	//If the host PC sends a GetStatus (device) request, the firmware must respond	and let the host know if the USB peripheral device is currently bus powered
	//or self powered.  See chapter 9 in the official USB specifications for details regarding this request.  If the peripheral device is capable of being both
	//self and bus powered, it should not return a hard coded value for this request.  Instead, firmware should check if it is currently self or bus powered, and
	//respond accordingly.  If the hardware has been configured like demonstrated on the PICDEM FS USB Demo Board, an I/O pin can be polled to determine the
	//currently selected power source.  On the PICDEM FS USB Demo Board, "RA2" is used for	this purpose.  If using this feature, make sure "USE_SELF_POWER_SENSE_IO"
	//has been defined in HardwareProfile.h, and that an appropriate I/O pin has been mapped to it in HardwareProfile.h.
    //	#if defined(USE_SELF_POWER_SENSE_IO)
    //	tris_self_power = INPUT_PIN;	// See HardwareProfile.h
    //	#endif
    
    
    //Enable the USB port now - we will check to see if Vbus is  powered at the end of init and disable it if not.
    //USBDeviceInit();	//usb_device.c.  Initializes USB module SFRs and firmware variables to known states.

	

	//------------------------
	//----- SETUP TIMERS -----
	//------------------------
	//(INCLUDE THE USAGE OF ALL TIMERS HERE EVEN IF NOT SETUP HERE SO THIS IS THE ONE POINT OF
	//REFERENCE TO KNOW WHICH TIMERS ARE IN USE AND FOR WHAT).

	//----- SETUP TIMER 1 -----
	//Used for: Available
	//OpenTimer1((T1_ON | T1_IDLE_CON | T1_GATE_OFF | T1_PS_1_4 | T1_SOURCE_INT), 20000);

	//----- SETUP TIMER 2 -----
	//Used for: 
	//OpenTimer2((T2_ON | T2_IDLE_CON | T2_GATE_OFF | T2_PS_1_1 | T2_SOURCE_INT), 0xffff);		//0xffff = 305Hz

	//----- SETUP TIMER 3 -----
	//Used for: 
	//OpenTimer3((T3_ON | T3_IDLE_CON | T3_GATE_OFF | T3_PS_1_1 | T3_SOURCE_INT), PIEZO_TIMER_PERIOD);

	//----- SETUP TIMER 4 -----
	//Used for: 
	//OpenTimer4((T4_ON | T4_IDLE_CON | T4_GATE_OFF | T4_PS_1_1 | T4_SOURCE_INT), 20000);

	//----- SETUP TIMER 5 -----
	//Used for: Heartbeat
	OpenTimer5((T5_ON | T5_IDLE_CON | T5_GATE_OFF | T5_PS_1_1 | T5_SOURCE_INT), 40000);		//1mS with 80MHz osc and PB_DIV_2
	ConfigIntTimer5(T5_INT_ON | T5_INT_PRIOR_7);											//1=lowest priority to 7=highest priority.  ISR function must specify same value



	//---------------------------------
	//----- SETUP EVAL BOARD CPLD -----
	//---------------------------------
	//Graphics bus width = 16
	mPORTGSetPinsDigitalOut(BIT_14);
	mPORTGSetBits(BIT_14);

	//SPI source select = SPI3 (not used)
	mPORTGSetPinsDigitalOut(BIT_12);
	mPORTGClearBits(BIT_12);
	
	//SPI peripheral destination select = Expansion Slot (not used)
	mPORTASetPinsDigitalOut(BIT_7 | BIT_6);
	mPORTASetBits(BIT_7);
	mPORTAClearBits(BIT_6);


	//--------------------------------------
    //----- PARALLEL MASTER PORT SETUP -----
	//--------------------------------------
    PMMODE = 0;
    PMAEN = 0;
    PMCON = 0;
    PMMODE = 0x0610;
    PMCONbits.PTRDEN = 1;                   //Enable RD line
    PMCONbits.PTWREN = 1;                   //Enable WR line
    PMCONbits.PMPEN = 1;                    //Enable PMP


	//------------------------------
	//----- INITIALISE DISPLAY -----
	//------------------------------
	display_initialise();


	display_test();

	//LOAD OUR GLOBAL HTML STYLES FILE READY FOR DISPLAY HTML PAGES
	BYTE dummy_styles_count;
	DWORD file_size;
	if (display_html_setup_read_file(global_css, 0, &file_size))
	{
		dummy_styles_count = 0;
		display_html_read_styles(&file_size, &dummy_styles_count, 1);			//1 = this is global styles file
	}

}
Example #7
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);
}