📄 lcd_twi.c
字号:
* This function clears the line, diplays a string, and shift
* step by step.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* The number of shifts corresponds to the length of the line.
*----------------------------------------------------------------------------
* REQUIREMENTS:
* Define ENABLE_SPLASH_SCREEN in config.h to use this function
*****************************************************************************/
void lcd_scrolling_line(Uchar uc_line, Uchar * pt_string, Uchar uc_direction)
{
Uchar uc_len;
Uchar uc_index;
lcd_clear_line(uc_line);
uc_len = strlen(pt_string);
strcpy(uc_buffer_scroll, pt_string);
/*display the string*/
lcd_wr_str(uc_line, pt_string);
/*fill the buffer after the shift*/
for(uc_index = uc_len; uc_index < ROW_LENGTH; uc_index++)
{
uc_buffer_scroll[uc_index] = 0x20;
}
uc_buffer_scroll[ROW_LENGTH] = 0x00;
/*start the scrolling*/
if(uc_direction == LCD_SCROLL_INC)
{
for(uc_index=0;uc_index< ROW_LENGTH;uc_index++)
{
tempo(TIMER_20_MS);
lcd_scrolling_inc(uc_line);
}
}
else if(uc_direction == LCD_SCROLL_DEC)
{
for(uc_index=0;uc_index< ROW_LENGTH;uc_index++)
{
tempo(TIMER_20_MS);
lcd_scrolling_dec(uc_line);
}
}
}
/*F**************************************************************************
* NAME: lcd_scrolling_inc
*----------------------------------------------------------------------------
* PARAMS:
* uc_line:
* return: none
*----------------------------------------------------------------------------
* PURPOSE:
* This function shifts all the line of a character on the right.
* The last character replaces the first one.
* This function doesn't use the shift controller command.
* The controller manages the dispaly as 2 lines of 40 characters.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* The buffer uc_buffer_scroll[] must contain the string
* to display. The lcd_scrolling_line() function fills the buffer.
*----------------------------------------------------------------------------
* REQUIREMENTS:
* Define ENABLE_SPLASH_SCREEN in config.h to use this function
*****************************************************************************/
void lcd_scrolling_inc(Uchar uc_line)
{
Uchar uc_index;
Uchar uc_temp;
uc_temp = uc_buffer_scroll[ROW_LENGTH - 1];
for(uc_index = (ROW_LENGTH - 1); uc_index >= 1; uc_index--)
{
uc_buffer_scroll[uc_index] = uc_buffer_scroll[uc_index-1];
}
uc_buffer_scroll[0] = uc_temp;
lcd_wr_str(uc_line, uc_buffer_scroll);
}
/*F**************************************************************************
* NAME: lcd_scrolling_dec
*----------------------------------------------------------------------------
* PARAMS:
* uc_line: line number
* return: none
*----------------------------------------------------------------------------
* PURPOSE:
* This function shifts all the line of a character on the left.
* The first character replaces the last one.
* This function doesn't use the shift controller command.
* The controller manages the dispaly as 2 lines of 40 characters.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* The buffer uc_buffer_scroll[] must contain the string
* to display. The lcd_scrolling_line() function fills the buffer.
*----------------------------------------------------------------------------
* REQUIREMENTS:
* Define ENABLE_SPLASH_SCREEN in config.h to use this function
*****************************************************************************/
void lcd_scrolling_dec(Uchar uc_line)
{
Uchar uc_index;
Uchar uc_temp;
uc_temp = uc_buffer_scroll[0];
for(uc_index = 0; uc_index < (ROW_LENGTH - 1); uc_index++)
{
uc_buffer_scroll[uc_index] = uc_buffer_scroll[uc_index+1];
}
uc_buffer_scroll[ROW_LENGTH -1] = uc_temp;
lcd_wr_str(uc_line, uc_buffer_scroll);
}
#endif
#ifdef ENABLE_OLD_LCD_FUNC // Use printf in stdio.h, and modules/custom_io instead of specific funstion
// if you need more performance than printf, write function that manipulate/create strings
// and *NEXT* send this string to output (screen) function.
/*F**************************************************************************
* NAME: lcd_hex_to_ASCII
*----------------------------------------------------------------------------
* PARAMS:
* uc_data: data to convert
* return: result in ASCII
*----------------------------------------------------------------------------
* PURPOSE:
* This function converts a value (0-F) in ASCII byte
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
* Define ENABLE_OLD_LCD_FUNC in config.h to use this function.
*****************************************************************************/
Uchar lcd_hex_to_ASCII(Uchar uc_data)
{
if((uc_data >= 0 ) && (uc_data <= 0x09)) return( uc_data + 0x30);
else if((uc_data >= 0x0A) && (uc_data <= 0x0F)) return( uc_data + 0x37);
return 0;
}
/*F**************************************************************************
* NAME: lcd_wr_byte_hex
*----------------------------------------------------------------------------
* PARAMS:
* uc_line: Line number on the display (1, 2, 3 or 4)
* uc_data: data to write (1 byte => 2 ASCII) 00-FF
* return: none
*----------------------------------------------------------------------------
* PURPOSE:
* Send a byte on the display in hexa (2 characters).
* no line clear
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
* Define ENABLE_OLD_LCD_FUNC in config.h to use this function.
*****************************************************************************/
void lcd_wr_byte_hex(Uchar uc_line, Uchar uc_byte, Uchar uc_offset)
{
Uchar uc_data_msb;
Uchar uc_data_lsb;
Uchar uc_temp;
Uchar uc_address;
uc_temp = ((0xF0) & uc_byte) >> 4;
uc_data_msb = lcd_hex_to_ASCII(uc_temp);
uc_temp = (0x0F) & uc_byte;
uc_data_lsb = lcd_hex_to_ASCII(uc_temp);
lcd_cmd_wr(LCD_E_0|LCD_RW_0|LCD_RS_0|LCD_DISP_ON|LCD_CURS_OFF|LCD_BLINK_OFF);
lcd_cmd_wr(LCD_E_0|LCD_RW_0|LCD_RS_0|LCD_CURS_MOV|LCD_RIGHT_SHIFT);
/* DDRAM init */
uc_address = lcd_ddram_addr[uc_line];
lcd_set_ddram(uc_address + uc_offset);
lcd_putchar(uc_data_msb);
lcd_putchar(uc_data_lsb);
}
/*F**************************************************************************
* NAME: lcd_wr_byte_dec
*----------------------------------------------------------------------------
* PARAMS:
* uc_line: Line number on the display (1, 2, 3 or 4)
* uc_data: data to write (1 byte => 3 ASCII) 0-255
* return: none
*----------------------------------------------------------------------------
* PURPOSE:
* Send a byte on the display in hexa (2 characters).
* no line cleared
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
* Define ENABLE_OLD_LCD_FUNC in config.h to use this function.
*****************************************************************************/
void lcd_wr_byte_dec(Uchar uc_line, Uchar uc_byte, Uchar uc_offset)
{
Uchar uc_index2;
Uchar uc_index;
Uchar uc_address;
uc_index = 0;
uc_index2 = 0;
lcd_cmd_wr(LCD_E_0|LCD_RW_0|LCD_RS_0|LCD_DISP_ON|LCD_CURS_OFF|LCD_BLINK_OFF);
lcd_cmd_wr(LCD_E_0|LCD_RW_0|LCD_RS_0|LCD_CURS_MOV|LCD_RIGHT_SHIFT);
/*DDRAM init*/
uc_address = lcd_ddram_addr[uc_line];
lcd_set_ddram(uc_address + uc_offset);
if(uc_byte <= 0x09)
{ /*1 character*/
lcd_putchar(' ');
lcd_putchar(' ');
lcd_putchar(lcd_hex_to_ASCII(uc_byte));
}
else if((uc_byte >= 0x0A) && (uc_byte <= 0x63))
{
while(uc_byte > 0x9)
{
uc_byte -= 0x0A;
uc_index++;
}
/*2 characters*/
lcd_putchar(' ');
lcd_putchar(lcd_hex_to_ASCII(uc_index));
lcd_putchar(lcd_hex_to_ASCII(uc_byte));
}
else if((uc_byte >= 0x64) && (uc_byte <= 0xFF))
{
while(uc_byte > 0x9)
{
uc_byte -= 0x0A;
uc_index++;
}
while(uc_index > 0x9)
{
uc_index -= 0x0A;
uc_index2++;
}
/*3 characters*/
lcd_putchar(lcd_hex_to_ASCII(uc_index2));
lcd_putchar(lcd_hex_to_ASCII(uc_index));
lcd_putchar(lcd_hex_to_ASCII(uc_byte));
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -