Example #1
0
/*******************************************************************************
* Purpose: Initializes the GPS Module.
* Passed: No arguments passed.
* Locals: int index - GPS Buffer Index
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void gps_init() {
    int index; // GPS Buffer Index

    /* 1. Turn GPS OFF before turning it on */
    GPS_PWR = OFF;
    clearScreen();
    BNSPrintf(LCD, "\tTurning\nGPS on...");
    DisplayDelay(DISPLAY_DELAY1);

    /* 2. Turn GPS ON */
    GPS_PWR = ON; // transistion from low to high
    timerDelay(2*ONE_SECOND);
    while(timerA1_started); // wait 2 seconds

    /* 3. Turn GPS_RESET ON for 250 ms */
    //clearScreen();
    //BNSPrintf(LCD, "\tGPS\nRESET");
    //DisplayDelay(DISPLAY_DELAY);
    GPS_RESET = ON; // transistion from low to high
    timerDelay(TWO_FIFTY_MS);
    while(timerA1_started); // wait 250 ms to transistion this signal

    /* 4. Pull GPS_PWRCTRL LOW for 2 seconds */
    //clearScreen();
    //BNSPrintf(LCD,"\tGPSPWRCTRL\nLOW");
    GPS_PWRCTRL = OFF; // GPS PWRCNTRL LOW
    timerDelay(2*ONE_SECOND);
    while(timerA1_started); // wait 2 seconds
    //BNSPrintf(LCD, "\tGPSPWRCTRL\nHIGH");
    //DisplayDelay(DISPLAY_DELAY);

    /* 5. Transition GPS_PWRCTRL */
    GPS_PWRCTRL = ON;

    /* 6. Wait until GPS_PWRCHK turns ON */
    //clearScreen();
    //BNSPrintf(LCD, "\tChecking\nPWRCHK");
    //DisplayDelay(DISPLAY_DELAY);
    while(!GPS_PWRCHK); // GPS PWRCHK

    /* 7. Release GPS_PWRCTRL */
    //clearScreen();
    //BNSPrintf(LCD, "\tPWRCTRL\nLOW");
    //DisplayDelay(DISPLAY_DELAY);
    GPS_PWRCTRL = OFF; // Drive PWRCNTRL back to low

    /* 8. We're done! */
    clearScreen();
    BNSPrintf(LCD, "\tGPS on!");
    DisplayDelay(DISPLAY_DELAY);

    /* Clear the longitude and latitude buffers */
    for (index = 0; index < 13; ++index) {
        lonGet[index] = latGet[index] = CLEAR_INDEX;
    }
}
/*****************************************************************************
Name:        	WaitForNotBusy
Parameters:  	controller must be 1 or 2
Returns:        none
Description:    This function waits for a controller to clear its busy bit
*****************************************************************************/
void WaitForNotBusy(char controller)
{
	while (Busy(controller)) 
	{
		  DisplayDelay(10); 
	};
}
/*****************************************************************************
Name:           LCD_read
Parameters:     value - the value to write
				data_or_ctrl - To write value as DATA or CONTROL
								1 = DATA
								0 = CONTROL
Returns:        none
Description:    Writes data to display. Sends command to display.  
*****************************************************************************/
unsigned char LCD_read(unsigned char data_or_ctrl, unsigned char controller)
{
	int value  = 0;				// return value
	int shifted = 0;			// To correct for hardware wiring error,
								// data must be shifted right once
	LCD_Port_Read();
		
	EN_PIN = LOW;          		// Prepare cycle
	RW_PIN = READ;
    DI_PIN = data_or_ctrl;     	// DI SELECT (HIGH=DATA, LOW=CTRL)

	if (controller == 1)	
	{
		CS1_PIN = SELECTED;			// controller
		CS2_PIN = UNSELECTED;			// controller
	}
	else if (controller == 2)
	{
		CS1_PIN = UNSELECTED;		// 
		CS2_PIN = SELECTED;			// controller
	}
	else if (controller == 3)		// Both!
	{
		CS1_PIN = SELECTED;			//
		CS2_PIN = SELECTED;			// 
	}

	DisplayDelay(0);				// We only need a very little delay
    EN_PIN = HIGH;          		// EN enable chip (HIGH)
	DisplayDelay(0);				// We only need a very little delay

	/* read Data */
	/* Correct hardware wiring of data pins */
	value = LCD_Remap_Read_Data();
    EN_PIN  = LOW;         			// Latch data by dropping EN
	
	return value;
}
/*****************************************************************************
Name:          	InitDisplay
Parameters:     none
Returns:        none
Description:    Intializes the LCD display. 
*****************************************************************************/
void LCD_display_init( void )
{
	// initial port directions
	LCD_Port_Drive();
		
	CS1_PIN		= SELECTED;			// Preset Values
	CS2_PIN		= SELECTED;
	EN_PIN 		= HIGH;
	RW_PIN		= WRITE;
	DI_PIN 		= HIGH;
	BACKLIGHT_PIN = LOW;
	
	CS1_PIN_DDR |= DRIVE;			// Data Direction Control lines.
	CS2_PIN_DDR |= DRIVE;
	EN_PIN_DDR	|= DRIVE;
	RW_PIN_DDR	|= DRIVE;
	DI_PIN_DDR	|= DRIVE;
	RESET_PIN_DDR |= DRIVE;
	prc2=1;							// unprotect as Port 9 is used	
	BACKLIGHT_PIN_DDR = OUTPUT;
	
	// RESET LCD
	EN_PIN 		= LOW;
	RESET_PIN	= ASSERT;
	DisplayDelay(4);	
	RESET_PIN	= UNASSERTED;
	DisplayDelay(4);	
	WaitForNotBusy(1);

	// INITIALIZE REGISTERS:
	GotoAddress( 0,0 );				// x=0; y=0;
	LCD_write(CTRL,SET_DISPLAY_START+0x00, BOTH );
	WaitForNotBusy(1);
	LCD_write(CTRL,DISPLAY_ON    ,BOTH);
	
	BACKLIGHT_PIN = LOW;	
//	BACKLIGHT_PIN = HIGH;	
}
Example #5
0
void InitDisplay(char far StartupString1[] )
//-----------------------------------------------------------------------------------------------------
//  Purpose: This will initialize the LCD and then display the define LOGO one line ine
//				and the passed parameter StartupString1 on line 2.
//
//  Rev:    1.0     Initial Release
//  
//  Notes:          None    
//-----------------------------------------------------------------------------------------------------
{
	int i;

	// initial port directions
	prc2=1;							// unprotect as Port 9 is used
	PORT_DDR = PORT_DDR_VALUE; 

	EN_PIN = HIGH;
	EN_PIN_DDR = HIGH;				// set port that controls EN as output
	RS_PIN = HIGH;
	RS_PIN_DDR = HIGH;				// set port that controls RS as output

	EN_PIN = LOW;

	LCD_write(CTRL_WR,0x33);
	DisplayDelay(20);
	LCD_write(CTRL_WR,0x32);
	DisplayDelay(20);
	LCD_write(CTRL_WR,FUNCTION_SET);	/* reset sequence */
	LCD_write(CTRL_WR,FUNCTION_SET);
	LCD_write(CTRL_WR,LCD_CURSOR_OFF);
	LCD_write(CTRL_WR,LCD_CLEAR);
	LCD_write(CTRL_WR,LCD_HOME_L1);

	DisplayString(LCD_LINE1, LOGO);
	
	BNSPrintf(LCD_FILE_NUM, "\t%8s\n%8s",LOGO, StartupString1);	
	DisplayDelay(6000);	
}
/*****************************************************************************
Name:           LCD_write_barebones
Parameters:     value - the value to write
				data_or_ctrl - To write value as DATA or CONTROL
								1 = DATA
								0 = CONTROL
Returns:        none
Description:    Does not handle smart controller switching
*****************************************************************************/
void LCD_write_barebones(unsigned char data_or_ctrl, unsigned char value, unsigned char controller)
{
	int shifted = 0;			// To correct for hardware wiring error,
								// data must be shifted right once.
	DISABLE_IRQ			// 
	
	LCD_Port_Drive();
	EN_PIN = LOW;          		// Prepare cycle
	RW_PIN = WRITE;				// Setup Read Write
    DI_PIN = data_or_ctrl;     	// Data/Instruction SELECT (HIGH=DATA, LOW=CTRL)

	if (controller == 1)	
	{
		CS1_PIN = SELECTED;			// Chip Select 1 
		CS2_PIN = UNSELECTED;			
	}
	else if (controller == 2)
	{
		CS1_PIN = UNSELECTED;			 
		CS2_PIN = SELECTED;			// Chip Select 2
	}
	else if (controller == 3)		
	{
		CS1_PIN = SELECTED;			//	Both
		CS2_PIN = SELECTED;			// 
	}
	
	/* Correct hardware wiring of data pins */
	LCD_Remap_n_Send_Data(value);

	DisplayDelay(0);					// We only need a very little delay
    EN_PIN = HIGH;          			// EN enable chip (HIGH)
	DisplayDelay(0);					// We only need a very little delay
    EN_PIN = LOW;          				// Latch data by dropping EN

	ENABLE_IRQ			// 
}
/*****************************************************************************
Name:           LCD_write
Parameters:     value - the value to write
				data_or_ctrl - To write value as DATA or CONTROL
								1 = DATA
								0 = CONTROL
Returns:        none
Description:    Writes data to display. Sends command to display.  
*****************************************************************************/
void LCD_write(unsigned char data_or_ctrl, unsigned char value, unsigned char controller)
{
	int shifted = 0;			// To correct for hardware wiring error,
								// data must be shifted right once.
	if ((data_or_ctrl == DATA) && (controller != BOTH))
	{
		// roll over to controller 2 if necessary:
		if (y_address > 63) controller = 2;
		if (y_address == 64) 
		{
		   LCD_write(CTRL, SET_X_ADDRESS+x_address, 2);
		   WaitForNotBusy(2);
		   LCD_write(CTRL, SET_Y_ADDRESS+0, 2);
		   WaitForNotBusy(2);
		}
	}

	// disable Interrupts.  We don't want data bus being 
	// 		a) written.  b) DDR changed.  c) ctrl lines
	DISABLE_IRQ		

	LCD_Port_Drive();
	EN_PIN = LOW;          		// Prepare cycle
	RW_PIN = WRITE;				// Setup Read Write
    DI_PIN = data_or_ctrl;     	// Data/Instruction SELECT (HIGH=DATA, LOW=CTRL)
	
	if (controller == 1)	
	{
		CS1_PIN = SELECTED;			// Chip Select Lines
		CS2_PIN = UNSELECTED;		
	}
	else if (controller == 2)
	{
		CS1_PIN = UNSELECTED;		
		CS2_PIN = SELECTED;			// Chip Select Lines
	}
	else if (controller == 3)		
	{
		CS1_PIN = SELECTED;			// Both
		CS2_PIN = SELECTED;			// 
	}
	
	LCD_Remap_n_Send_Data(value);

	DisplayDelay(0);					// We only need a very little delay
    EN_PIN = HIGH;          			// EN enable chip (HIGH)
	DisplayDelay(0);					// We only need a very little delay
    EN_PIN = LOW;          				// Latch data by dropping EN

	// Re-enable Interrupts
	ENABLE_IRQ			
	
	
	if(data_or_ctrl == DATA)
	{
		y_address++;
		if (y_address > 127)
		{
			x_address++;
			if (x_address > 7) x_address=0;
			controller = 1;
			y_address = 0;
			LCD_SendAddresses();
		}
	}
}