Sonochan II 0.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
LCD_5110.c File Reference

Generic driver for LCD used in nokia 5110. More...

`#include "LCD_5110.h"`

## Data Structures
union | lcd_5110_32bits
| Structure which easily allow split 32bit value into 4 8bit variables. More...

## Macros
#define | _LCD_5110_FONT_NOKIA_5110_

## Functions
e_lcd_5110_status | LCD_5110_show_digit (uint8_t i_digit)
| Print only one digit (0~F) More...
void | LCD_5110_add_8bit_hex_to_sring (char *p_string, uint8_t i_hex_number)
| Convert input hexadecimal number to string and add it to input string variable. More...
uint8_t | LCD_5110_add_tens_to_string (char *p_string, uint8_t i_dec_number)
| From given number get tens and add tens to string. More...
void | LCD_5110_add_unit_to_string (char *p_string, uint8_t i_dec_number)
| From given number get units and add it to string. More...
void | LCD_5110_add_8bit_dec_unsigned_to_string (char *p_string, uint8_t i_dec_number)
| Convert 8bit unsigned binary number to text value. More...
void | LCD_5110_add_16bit_dec_unsigned_to_string (char *p_string, uint16_t i_dec16)
| Convert 16bit unsigned binary number to text value. More...
e_lcd_5110_status | LCD_5110_init (void)
| Initialize LCD module and call clear screen function. More...
e_lcd_5110_status | LCD_5110_clear (void)
| Clear screen and set cursor to 0,0. This function is called by "LCD_5110_init". More...
e_lcd_5110_status | LCD_5110_write (const char *p_txt_to_show)
| Write text to LCD. More...
e_lcd_5110_status | LCD_5110_write_xy (const char *p_txt_to_show, int x_position, int y_line)
| Write text to LCD at specified coordinates. More...
e_lcd_5110_status | LCD_5110_clear_line (uint8_t y_line)
| Clear selected line and set cursor to X position 0. More...
e_lcd_5110_status | LCD_5110_set_X (uint8_t X_address)
| Only set X coordinate on LCD nokia 5510. More...
e_lcd_5110_status | LCD_5110_set_line (uint8_t y_line)
| Only set active line on LCD nokia 5510. More...
e_lcd_5110_status | LCD_5110_write_to_line (uint8_t i_raw_data)
| Write argument through actual line. More...
void | LCD_5110_auto_newline (uint8_t i_auto_LF_flag)
| Allow to set/clear flag which enable/disable auto add new line. More...
void | LCD_5110_auto_clear_display (uint8_t i_auto_clear_flag)
| Allow to set/clear flag which enable/disable auto clear display. More...
void | LCD_5110_auto_clear_line (uint8_t i_auto_clear_flag)
| Allow to set/clear flag which enable/disable auto clear line. More...
e_lcd_5110_status | LCD_5110_write_hex8 (uint8_t i_hex8)
| Write given number as 8bit hexadecimal number. More...
e_lcd_5110_status | LCD_5110_write_hex16 (uint16_t i_hex16)
| Write given number as 16bit hexadecimal number. More...
e_lcd_5110_status | LCD_5110_write_hex32 (uint32_t i_hex32)
| Write given number as 32bit hexadecimal number. More...
e_lcd_5110_status | LCD_5110_write_dec8_unsigned (uint8_t i_dec8)
| Write given 8bit number as decimal value without sign. More...
e_lcd_5110_status | LCD_5110_write_dec8_signed (int8_t i_dec8)
| Write given 8bit number as decimal value with sign. More...
e_lcd_5110_status | LCD_5110_write_dec16_unsigned (uint16_t i_dec16)
| Write given 16bit number as decimal value without sign. More...
e_lcd_5110_status | LCD_5110_write_dec16_signed (int16_t i_dec16)
| Write given 16bit number as decimal value with sign. More...
e_lcd_5110_status | LCD_5110_send_data_byte (uint8_t i_data)
| Send one data Byte to LCD module. More...
e_lcd_5110_status | LCD_5110_send_command_byte (uint8_t i_cmd)
| Send one command Byte to LCD module. More...

## Variables
const unsigned char | LCD_5110_font6x8 [][6]
| Binary appearance all symbols in array. More...
portBASE_TYPE | xStatus
xSemaphoreHandle | mutexSPI
static uint8_t | i_LCD_line_counter = 0
| Global variables for counting LCD "lines" and determinate X position. More...
static uint8_t | i_LCD_x_position = 0
static uint8_t | i_add_LF_after_write = LCD_5110_DEFAULT_AUTO_LF
static uint8_t | i_auto_clear_display_flag = LCD_5110_DEFAULT_AUTO_LCD_CLEAR
static uint8_t | i_auto_clear_line_flag = LCD_5110_DEFAULT_AUTO_LINE_CLEAR

## Detailed Description

Generic driver for LCD used in nokia 5110.

Used for basic operations (init, clear, write text, ...) with LCD 5510.
It need HAL driver (which depend on used architecture) to work properly.

Created: 04.07.2012
Modified: 06.05.2014

Version
  1.1

Author
  Martin Stejskal

## Macro Definition Documentation

#define _LCD_5110_FONT_NOKIA_5110_

## Function Documentation

void LCD_5110_add_16bit_dec_unsigned_to_string | ( | char * | p_string,
|  | uint16_t | i_dec16
| ) |  |
| inline

Convert 16bit unsigned binary number to text value.

Parameters

  p_string | Pointer to string array. To this string will be written
  i_dec_number | 16bit unsigned value: 0~65535

void LCD_5110_add_8bit_dec_unsigned_to_string | ( | char * | p_string,
|  | uint8_t | i_dec_number
| ) |  |
| inline

Convert 8bit unsigned binary number to text value.

Parameters

  p_string | Pointer to string array. To this string will be written
  i_dec_number | 8bit unsigned value: 0~255

void LCD_5110_add_8bit_hex_to_sring | ( | char * | p_string,
|  | uint8_t | i_hex_number
| ) |  |

Convert input hexadecimal number to string and add it to input
string variable.

Parameters

  p_string | Pointer to string. To this string will be written result
  i_hex_number | 8bit number. Assume binary format

uint8_t LCD_5110_add_tens_to_string | ( | char * | p_string,
|  | uint8_t | i_dec_number
| ) |  |
| inline

From given number get tens and add tens to string.

Parameters

  p_string | Pointer to string array. To this string will be written
  i_dec_number | Number 0~99. If higher then behavior can be unexpected

Returns
  Tens (10, 20, 30 and so on) depend what detect

void LCD_5110_add_unit_to_string | ( | char * | p_string,
|  | uint8_t | i_dec_number
| ) |  |
| inline

From given number get units and add it to string.

Parameters

  p_string | Pointer to string array. To this string will be written
  i_dec_number | Number 0~9. If higher then behavior can be unexpected

void LCD_5110_auto_clear_display | ( | uint8_t | i_auto_clear_flag) |  |
| inline

Allow to set/clear flag which enable/disable auto clear display.

When is called LCD_5110_write*() functions, then after last line new text
is written to line 0. So old messages stay on LCD, but in some cases user
might want clear display and then write again to first line. Well, this
option can do this.

Parameters

  i_auto_clear_flag | Enable (1) or disable (0) auto clear display

void LCD_5110_auto_clear_line | ( | uint8_t | i_auto_clear_flag) |  |
| inline

Allow to set/clear flag which enable/disable auto clear line.

When call LCD_5110_write_*() function and this option is enabled, before
writing clear actual line. This is useful in most cases, but not at all.
So there is option.

Parameters

  i_auto_clear_flag | Enable (1) or disable (0) auto clear line

void LCD_5110_auto_newline | ( | uint8_t | i_auto_LF_flag) |  |
| inline

Allow to set/clear flag which enable/disable auto add new line.

When is called LCD_5110_write*() functions, then by default after every
write is new message added to new line. Sometimes it can be this annoying
so this function allow enable (1) or disable (0) this feature.

Parameters

  i_auto_LF_flag | Enable (1) or disable (0) auto add new line

e_lcd_5110_status LCD_5110_clear | ( | void | ) |  |

Clear screen and set cursor to 0,0. This function is called by
"LCD_5110_init".

Whole LCD is rewritten by 0x00. It is called by LCD_5110_init()

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_clear_line | ( | uint8_t | y_line) |  |

Clear selected line and set cursor to X position 0.

User select line which will be cleared. Function clear that line and set
cursor on the line begin.

Parameters

  y_line | Line index on LCD. Accepted value 0~5 else is set to 0

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_init | ( | void | ) |  |
| inline

Initialize LCD module and call clear screen function.

Also initialize SPI device.

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_send_command_byte | ( | uint8_t | i_cmd) |  |

Send one command Byte to LCD module.

Also lock and unlock device when RTOS support is enabled

Parameters

  i_cmd | Command which will be send to LCD module

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_send_data_byte | ( | uint8_t | i_data) |  |

Send one data Byte to LCD module.

Also lock and unlock device when RTOS support is enabled

Parameters

  i_Byte | Data byte which will be send to LCD module

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_set_line | ( | uint8_t | y_line) |  |
| inline

Only set active line on LCD nokia 5510.

Parameters

  y_line | Line index on LCD. Accepted value 0~5 else is set

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_set_X | ( | uint8_t | X_address) |  |
| inline

Only set X coordinate on LCD nokia 5510.

Parameters

  X_address | X coordinate. Accepted value 0~83 else is set to 0

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_show_digit | ( | uint8_t | i_digit) |  |
| inline

Print only one digit (0~F)

Parameters

  i_digit | Number to show. Minimum value is 0, maximum is 0xF. Anything else will not be displayed properly

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_write | ( | const char * | p_txt_to_show) |  |

Write text to LCD.

Text is given as pointer to char. Write characters until is found NULL. If message is not fit on one line, then message continues on the next line

Parameters

  p_txt_to_show | Pointer to string that ends NULL character

Example of using "LCD_5110_write":

i_status = some_function();
// Needed include lib. "stdio.h"
sprintf(&text[0], "Codec set status: %d", i_status);
LCD_5110_write( &text[0] );

Or:

LCD_5110_write("Text to show");

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_write_dec16_signed | ( | int16_t | i_dec16) |  |

Write given 16bit number as decimal value with sign.

Value on LCD: -32768~32767

Parameters

  i_dec16 | 16bit signed value

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_write_dec16_unsigned | ( | uint16_t | i_dec16) |  |

Write given 16bit number as decimal value without sign.

Value on LCD: 0~65535

Parameters

  i_dec16 | 16bit unsigned value

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_write_dec8_signed | ( | int8_t | i_dec8) |  |

Write given 8bit number as decimal value with sign.

Value on LCD: -128~127

Parameters

  i_dec8 | 8bit signed value

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_write_dec8_unsigned | ( | uint8_t | i_dec8) |  |

Write given 8bit number as decimal value without sign.

Value on LCD: 0~255

Parameters

  i_dec8 | 8bit unsigned value

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_write_hex16 | ( | uint16_t | i_hex16) |  |
| inline

Write given number as 16bit hexadecimal number.

Add prefix "0x" before written number

Parameters

  i_hex16 | 16bit binary value

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_write_hex32 | ( | uint32_t | i_hex32) |  |
| inline

Write given number as 32bit hexadecimal number.

Add prefix "0x" before written number

Parameters

  i_hex32 | 32bit binary value

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_write_hex8 | ( | uint8_t | i_hex8) |  |
| inline

Write given number as 8bit hexadecimal number.

Add prefix "0x" before written number

Parameters

  i_hex8 | 8bit binary value

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_write_to_line | ( | uint8_t | i_raw_data) |  |

Write argument through actual line.

Function do not change actual line number. This is useful for rewriting
lines. Also set X coordinates back to 0. If you want erase one line, just
call this function with value 0x00.

Parameters

  i_data | Raw binary data for LCD module

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_write_xy | ( | const char * | p_txt_to_show,
|  | int | x_position,
|  | int | y_line
| ) |  |
| inline

Write text to LCD at specified coordinates.

Text must end with NULL character. If message is not fit on one line, then message continues on the next line.

Parameters

  p_txt_to_show | Pointer to string that ends NULL character
  x_position | X coordinate. Accepted value 0~83 else is set to 0
  y_line | Line index on LCD. Accepted value 0~5 else is set to 0

Example of using "LCD_5110_write_xy":

i_status = some_function();
// Needed include lib. "stdio.h"
sprintf(&text[0], "Codec set status: %d", i_status);
LCD_5110_write_xy( &text[0], 3, 1 );

Or:

LCD_5110_write_xy("Text to show", 10, 0);

Returns
  LCD_5110_OK (0) if all OK

## Variable Documentation

uint8_t i_add_LF_after_write = LCD_5110_DEFAULT_AUTO_LF
| static

If is set to 1, after writing text thru LCD_5110_write() is new message
written new line. If value is 0, then new message continue on actual line
is possible.

uint8_t i_auto_clear_display_flag = LCD_5110_DEFAULT_AUTO_LCD_CLEAR
| static

If is cleared, then after writing text to last line continue on line 0.
All old informations stay on display. However in some cases is good idea
to clear display before continue again on line 0. Something as book page.
So if you want this feature, set this to one.

uint8_t i_auto_clear_line_flag = LCD_5110_DEFAULT_AUTO_LINE_CLEAR
| static

If bit is set, then always before writing (LCD_5110_write_*) clear line.
In most cases it can be useful, but not every time. So there is option.
This can be set also in runtime.

uint8_t i_LCD_line_counter = 0
| static

Global variables for counting LCD "lines" and determinate X position.

Counts "lines" on LCD, so next word can be easy written to next line
(easy to calculate)

uint8_t i_LCD_x_position = 0
| static

Determine X position on LCD

const unsigned char LCD_5110_font6x8[][6]

Binary appearance all symbols in array.

xSemaphoreHandle mutexSPI

portBASE_TYPE xStatus