Beispiel #1
0
//**************************************************************************
//* LCD initialization
//**************************************************************************
//* Calling arguments:
//* char mode1 : display mode (number of lines and character size)
//* char mode2 : display mode (cursor and display state)
//**************************************************************************
void LCD_init(char mode1, char mode2)
{
	char aux;
	// Configure the pins as outputs
	LCD_ENABLE_DIR = 1;
	LCD_RS_DIR = 1;
	LCD_D4_DIR = 1;
	LCD_D5_DIR = 1;
	LCD_D6_DIR = 1;
	LCD_D7_DIR = 1;
	// Set the LCD data pins to zero
	LCD_D4 = 0;
	LCD_D5 = 0;
	LCD_D6 = 0;
	LCD_D7 = 0;
	LCD_RS = 0;
	LCD_ENABLE = 0;       // LCD enable = 0
	LCD_delay_ms(15);
	// LCD 4-bit mode initialization sequence
	// send three times 0x03 and then 0x02 to finish configuring the LCD
	for(aux=0;aux<3;++aux)
	{		
	  LCD_send_nibble(3);
	  LCD_delay_ms(5);
	}
	LCD_send_nibble(2);
	// Now send the LCD configuration data
	LCD_send_byte(0,0x20 | mode1);
	LCD_send_byte(0,0x08 | mode2);
	lcd_mode = 0x08 | mode2;
	LCD_send_byte(0,1);
	LCD_send_byte(0,6);
}
Beispiel #2
0
//**************************************************************************
//* Write a byte into the LCD
//**************************************************************************
//* Calling arguments:
//* char address : 0 for instructions, 1 for data
//* char data : command or data to be written
//**************************************************************************
void LCD_send_byte(char address, char data)
{
  unsigned int temp;
	LCD_RS = address;               // config the R/S line
	LCD_ENABLE = 0;                 // set LCD enable line to 0
	LCD_send_nibble(data >> 4);     // send the higher nibble
	LCD_send_nibble(data & 0x0f);   // send the lower nibble
	for (temp=1000; temp; temp--);
}
Beispiel #3
0
void LCD_init(char mode1, char mode2)
{
	char aux;
    //SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTB_MASK;       // enable clock to Port A and Port B
    PORTA_PCR8 = PORT_PCR_MUX(1);		// PTA8 GPIO
    PORTA_PCR9 = PORT_PCR_MUX(1);		// PTA9 GPIO
    PORTA_PCR11 = PORT_PCR_MUX(1);		// PTA11 GPIO
    PORTB_PCR4 = PORT_PCR_MUX(1);		// PTB4 GPIO
    PORTA_PCR12 = PORT_PCR_MUX(1);		// PTA12 GPIO
    PORTB_PCR12 = PORT_PCR_MUX(1);		// PTB12 GPIO
    //PORTA_PCR13 = PORT_PCR_MUX(1);		// PTA13 GPIO
    GPIOA_PDDR |= LCD_ENABLE|LCD_RS|LCD_D4|LCD_D6/*|LCD_D7*/;
    GPIOB_PDDR |= LCD_D5|LCD_D7;

	// Set the LCD data pins to zero
	LCD_ENABLE_OFF;
	LCD_RS_OFF;
	LCD_D4_OFF;
	LCD_D5_OFF;
	LCD_D6_OFF;
	LCD_D7_OFF;

	time_delay_ms(50);			//Secuencia de inicializacion
    
	// LCD 4-bit mode initialization sequence
	// send three times 0x03 and then 0x02 to finish configuring the LCD
	for(aux=0;aux<3;++aux)
	{		
	  LCD_send_nibble(3);
	  time_delay_ms(5);
	}
	LCD_send_nibble(2);
	// Now send the LCD configuration data
	LCD_send_byte(0,0x20 | mode1);
	LCD_send_byte(0,0x08 | mode2);
	lcd_mode = 0x08 | mode2;
	LCD_send_byte(0,1);
	LCD_send_byte(0,6);
}
Beispiel #4
0
//**************************************************************************
//* Write a byte into the LCD
//**************************************************************************
//* Calling arguments:
//* char address : 0 for instructions, 1 for data
//* char data : command or data to be written
//**************************************************************************
void LCD_send_byte(char address, char data)
{
	if (address == 1)
	{
		LCD_RS_ON;
	} else
	{
		LCD_RS_OFF;
	}
	LCD_ENABLE_OFF;                 // set LCD enable line to 0
	LCD_send_nibble(data >> 4);     // send the higher nibble
	LCD_send_nibble(data & 0x0f);   // send the lower nibble
	time_delay_ms(6);
}