//************************************************************************** //* 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); }
void LCD_Set_CustomChar(uint8_t location, uint8_t *ptr) { uint8_t i; if (location<8) { LCD_send_byte(0, 0x40+(location*8)); for(i=0;i<8;i++) LCD_send_byte(1, ptr[ i ]); } }
void LCD_write_char(char c) { switch (c) { case '\f': LCD_send_byte(0, 1); break; case '\n': case '\r': LCD_pos_xy(0, 0); break; default: LCD_send_byte(1, c); } }
//************************************************************************** //* LCD cursor position set //************************************************************************** //* Calling arguments: //* char x : column (starting by 0) //* char y : line (0 or 1) //************************************************************************** void LCD_pos_xy(char x, char y) { char address; if (y) address = LCD_SEC_LINE; else address = 0; address += x; LCD_send_byte(0,0x80|address); }
//************************************************************************** //* Write a character on the display //************************************************************************** //* Calling arguments: //* char c : character to be written //************************************************************************** //* Notes : //* \f clear the display //* \n and \r return the cursor to line 1 column 0 //************************************************************************** void LCD_write_char(char c) { switch (c) { case '\f' : LCD_send_byte(0,1); time_delay_ms(5); break; case '\n' : case '\r' : LCD_pos_xy(0,1); break; case RightShiftCmd : LCD_send_byte(0,c); break; default: LCD_send_byte(1,c); } }
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); }
//************************************************************************** //* Turn off the cursor blink function //************************************************************************** void LCD_cursor_blink_off(void) { lcd_mode &= 0b11111110; LCD_send_byte (0,lcd_mode); }
//************************************************************************** //* Turn on the cursor blink function //************************************************************************** void LCD_cursor_blink_on(void) { lcd_mode |= 1; LCD_send_byte (0,lcd_mode); }
//************************************************************************** //* Turn the cursor on //************************************************************************** void LCD_cursor_on(void) { lcd_mode |= 2; LCD_send_byte (0,lcd_mode); }
//************************************************************************** //* Turn the display off //************************************************************************** void LCD_display_off(void) { lcd_mode &= 0b11111011; LCD_send_byte (0,lcd_mode); }
//************************************************************************** //* Turn the display on //************************************************************************** void LCD_display_on(void) { lcd_mode |= 4; LCD_send_byte (0,lcd_mode); }
void LCD_send_data(uint8_t data){ LCD_send_byte(data, 1); LCD_wait(); }
void LCD_send_command(uint8_t command){ LCD_send_byte(command, 0); LCD_wait(); }
void LCD_cursor_off(void) { lcd_mode &= 0xFD; LCD_send_byte(0, lcd_mode); }
void LCD_display_off(void) { lcd_mode &= 0xFB; LCD_send_byte(0, lcd_mode); }