# include/lc7981.h File Reference

`#include <avr/io.h>`
`#include <util/delay.h>`
`#include <avr/pgmspace.h>`

Go to the source code of this file.

## Defines

#define | LC7981_H_ LC7981_H_
| protects this file from beeing double included
#define | LCD_CTRL PORTA
| Port used for control signals.
#define | LCD_CRTL_DDR DDRA
| Data-Direction-Register for the control signals.
#define | LCD_RS PA4
| Register-Select Pin of the Display.
#define | LCD_RW PA2
| Read-Write-select Pin.
#define | LCD_EN PA0
| Strobe Pin.
#define | LCD_DATA PORTD
| Port used for data.
#define | LCD_DATA_PIN PIND
| Port used for reading the data.
#define | LCD_DATA_DDR DDRD
| Data-Direction-Register for data.
#define | lcd_rs_high() (LCD_CTRL |= (1 << LCD_RS))
| Set the Register-Select pin high.
#define | lcd_rs_low() (LCD_CTRL &= ~(1 << LCD_RS))
| Set the Register-Select pin low.
#define | lcd_rw_high() (LCD_CTRL |= (1 << LCD_RW))
| Set the Read-Write-Select pin high.
#define | lcd_rw_low() (LCD_CTRL &= ~(1 << LCD_RW))
| Set the Register-Select pin low.
#define | lcd_en_high() (LCD_CTRL |= (1 << LCD_EN))
| Set the strobe pin high.
#define | lcd_en_low() (LCD_CTRL &= ~(1 << LCD_EN))
| Set the strobe pin low.
#define | LCD_TEXT 0
| Constant for text mode.
#define | LCD_TEXT_LINES 10
| Number of lines in text mode.
#define | LCD_TEXT_COLUMNS 26
| Number of columns in text mode.
#define | LCD_GRAPHIC 1
| Constant for graphic mode.
#define | LCD_GRAPHIC_WIDTH 160
| Horizontal display size in pixels.
#define | LCD_GRAPHIC_HEIGHT 80
| Vertical display size in pixels.
#define | PIXEL_ON 1
| see lcd_plot_pixel
#define | PIXEL_OFF 0
| see lcd_plot_pixel

## Functions

void | lcd_init (uint8_t mode)
| lcd_init set the to default values.
void | lcd_clear ()
| Clears the display by setting the whole memory to 0.
void | lcd_write_text (char *txt)
| Outputs text in at the current cursor position.
void | lcd_gotoxy (uint8_t x, uint8_t y)
| Set the display cursor to a specific location.
void | lcd_plot_pixel (uint8_t x, uint8_t y, uint8_t set)
| set or unset a pixel at the specified location
void | lcd_plot_bitmap (uint8_t x, uint8_t y, PGM_P bitmap, uint8_t w, uint8_t h)
| This function will plot a bitmap with the upper left corner to the given coordinates.
void | lcd_plot_char (uint8_t x_off, uint8_t y_off, uint8_t c, uint8_t fw, uint8_t fh, PGM_P font)
| Plots a single character in graphicmode.
void | lcd_plot_text (uint8_t x_off, uint8_t y_off, const char *text, uint8_t fw, uint8_t fh, PGM_P font)
| Plots a text using lcd_plot_char.
void | lcd_plot_pgmtext (uint8_t x_off, uint8_t y_off, PGM_P text, uint8_t fw, uint8_t fh, PGM_P font)
static void | lcd_strobe ()
| Generates the strobe signal for writing data.
static void | lcd_write_command (uint8_t cmd, uint8_t data)
| Writes a command and a data byte to the lcd.
static uint8_t | lcd_read_byte ()
| Reads a byte from the display memory.

## Define Documentation

#define LC7981_H_ LC7981_H_

protects this file from beeing double included

#define LCD_CRTL_DDR DDRA

Data-Direction-Register for the control signals.

#define LCD_CTRL PORTA

Port used for control signals.

#define LCD_DATA PORTD

Port used for data.

#define LCD_DATA_DDR DDRD

Data-Direction-Register for data.

#define LCD_DATA_PIN PIND

Port used for reading the data.

#define LCD_EN PA0

Strobe Pin.

#define lcd_en_high | ( |  | ) | (LCD_CTRL |= (1 << LCD_EN))

Set the strobe pin high.

#define lcd_en_low | ( |  | ) | (LCD_CTRL &= ~(1 << LCD_EN))

Set the strobe pin low.

#define LCD_GRAPHIC 1

Constant for graphic mode.

#define LCD_GRAPHIC_HEIGHT 80

Vertical display size in pixels.

#define LCD_GRAPHIC_WIDTH 160

Horizontal display size in pixels.

#define LCD_RS PA4

Register-Select Pin of the Display.

#define lcd_rs_high | ( |  | ) | (LCD_CTRL |= (1 << LCD_RS))

Set the Register-Select pin high.

#define lcd_rs_low | ( |  | ) | (LCD_CTRL &= ~(1 << LCD_RS))

Set the Register-Select pin low.

#define LCD_RW PA2

Read-Write-select Pin.

#define lcd_rw_high | ( |  | ) | (LCD_CTRL |= (1 << LCD_RW))

Set the Read-Write-Select pin high.

#define lcd_rw_low | ( |  | ) | (LCD_CTRL &= ~(1 << LCD_RW))

Set the Register-Select pin low.

#define LCD_TEXT 0

Constant for text mode.

#define LCD_TEXT_COLUMNS 26

Number of columns in text mode.

#define LCD_TEXT_LINES 10

Number of lines in text mode.

#define PIXEL_OFF 0

see lcd_plot_pixel

#define PIXEL_ON 1

see lcd_plot_pixel

## Function Documentation

void lcd_clear | ( |  | ) |

Clears the display by setting the whole memory to 0.

void lcd_gotoxy | ( | uint8_t | x,
|  | uint8_t | y |
| ) |  |  |

Set the display cursor to a specific location.

Right now this does only work in text mode, since there's no need for it now in graphics mode.
If the x and y values are to big, the function does nothing.

Parameters:

  | x | the horizontal cursorposition (starts at 0)
  | y | the vertical cursorposition (starts at 0)

void lcd_init | ( | uint8_t | mode | ) |

lcd_init set the to default values.

Parameters:

  | mode | LCD_TEXT for text mode and LCD_GRAPHIC for graphic mode

void lcd_plot_bitmap | ( | uint8_t | x_off,
|  | uint8_t | y_off,
|  | PGM_P | bitmap,
|  | uint8_t | w,
|  | uint8_t | h |
| ) |  |  |

This function will plot a bitmap with the upper left corner to the given coordinates.

If the bitmap doesn't fit on the display at this location, nothing is drawn at all.
Unset pixels are treated as transparent
This function is by far the most tricky piece of code in this project,
don't worry if you don't understand it at first sight.
And if you know a better way to do this, tell me.

Parameters:

  | x_off | horizontal position of the bitmap
  | y_off | vertical position of the bitmap
  | bitmap | pointer to the bitmap in pgmspace
  | w | width of the bitmap
  | h | height of the bitmap

This function is dedicated to Greta, one of the most important persons in my life so far.

void lcd_plot_char | ( | uint8_t | x_off,
|  | uint8_t | y_off,
|  | uint8_t | c,
|  | uint8_t | fw,
|  | uint8_t | fh,
|  | PGM_P | font |
| ) |  |  |

Plots a single character in graphicmode.

Each character of the font is stored linewise.
This means for a 8x8 Pixel font the 8 bytes are needed.
The first byte is the first line and the last byte is the last line.
The next 8byte are the next character.
If the position is too close to the display edge so it can't be displayed completely,
It won't be displayed at all.

Parameters:

  | x_off | horizontal position of the character
  | y_off | vertical position of the character
  | c | the character or it's ascii code
  | fw | width of the font
  | fh | height of the font
  | font | pointer to the flash area where the font is stored

void lcd_plot_pgmtext | ( | uint8_t | x_off,
|  | uint8_t | y_off,
|  | PGM_P | text,
|  | uint8_t | fw,
|  | uint8_t | fh,
|  | PGM_P | font |
| ) |  |  |

void lcd_plot_pixel | ( | uint8_t | x,
|  | uint8_t | y,
|  | uint8_t | set |
| ) |  |  |

set or unset a pixel at the specified location

Parameters:

  | x | horizontal position of the pixel (starts at 0)
  | y | horizontal position of the pixel (starts at 0)
  | set | can be PIXEL_ON or PIXEL_OFF

void lcd_plot_text | ( | uint8_t | x_off,
|  | uint8_t | y_off,
|  | const char * | text,
|  | uint8_t | fw,
|  | uint8_t | fh,
|  | PGM_P | font |
| ) |  |  |

Plots a text using lcd_plot_char.

Parameters:

  | x_off | horizontal position of the character
  | y_off | vertical position of the character
  | text | the text that is plotted
  | fw | width of the font
  | fh | height of the font
  | font | pointer to the flash area where the font is stored

See also:
  lcd_plot_char

static uint8_t lcd_read_byte | ( |  | ) | `[inline, static]`

Reads a byte from the display memory.

lcd_gotoxy can be used to set the location. Important : lcd_gotoxy doesn't work in graphics mode yet.

Returns:
  the byte which has been read

See also:
  lcd_gotoxy

static void lcd_strobe | ( |  | ) | `[inline, static]`

Generates the strobe signal for writing data.

This function is meant for internal usage only.

static void lcd_write_command | ( | uint8_t | cmd,
|  | uint8_t | data |
| ) |  |  | `[inline, static]`

Writes a command and a data byte to the lcd.

Parameters:

  | cmd | the command byte
  | data | the data that is going to be written after the command

void lcd_write_text | ( | char * | txt | ) |

Outputs text in at the current cursor position.

If a \n occurs in the last line of the display, all the other line will be 'scrolled' up. This function is textmode only. The the second line becomes the first, the third the second and so on ...

Parameters:

  | txt | the text