fremoclock  1_3A01
FREMO Clock - Software for UTG
lcd.c File Reference

LCD interface example. More...

Go to the source code of this file.

Macros

#define LCD_CLR   0
 DB0: clear display. More...
 
#define LCD_HOME   1
 DB1: return to home position. More...
 
#define LCD_ENTRY_MODE   2
 DB2: set entry mode. More...
 
#define LCD_ENTRY_INC   1
 DB1: 1=increment, 0=decrement. More...
 
#define LCD_ENTRY_SHIFT   2
 DB2: 1=display shift on. More...
 
#define LCD_ON   3
 DB3: turn lcd/cursor on. More...
 
#define LCD_ON_DISPLAY   2
 DB2: turn display on. More...
 
#define LCD_ON_CURSOR   1
 DB1: turn cursor on. More...
 
#define LCD_ON_BLINK   0
 DB0: blinking cursor ? More...
 
#define LCD_MOVE   4
 DB4: move cursor/display. More...
 
#define LCD_MOVE_DISP   3
 DB3: move display (0-> cursor) ? More...
 
#define LCD_MOVE_RIGHT   2
 DB2: move right (0-> left) ? More...
 
#define LCD_FUNCTION   5
 DB5: function set. More...
 
#define LCD_FUNCTION_8BIT   4
 DB4: set 8BIT mode (0->4BIT mode) More...
 
#define LCD_FUNCTION_2LINES   3
 DB3: two lines (0->one line) More...
 
#define LCD_FUNCTION_10DOTS   2
 DB2: 5x10 font (0->5x7 font) More...
 
#define LCD_CGRAM   6
 DB6: set CG RAM address. More...
 
#define LCD_DDRAM   7
 DB7: set DD RAM address. More...
 
#define LCD_BUSY   7
 DB7: LCD is busy. More...
 
#define LCD_ENTRY_DEC   0x04
 display shift off, dec cursor move dir More...
 
#define LCD_ENTRY_DEC_SHIFT   0x05
 display shift on, dec cursor move dir More...
 
#define LCD_ENTRY_INC_   0x06
 display shift off, inc cursor move dir More...
 
#define LCD_ENTRY_INC_SHIFT   0x07
 display shift on, inc cursor move dir More...
 
#define LCD_MOVE_CURSOR_LEFT   0x10
 move cursor left (decrement) More...
 
#define LCD_MOVE_CURSOR_RIGHT   0x14
 move cursor right (increment) More...
 
#define LCD_MOVE_DISP_LEFT   0x18
 shift display left More...
 
#define LCD_MOVE_DISP_RIGHT   0x1C
 shift display right More...
 
#define LCD_FUNCTION_4BIT_1LINE   0x20
 4-bit interface, single line, 5x7 dots More...
 
#define LCD_FUNCTION_4BIT_2LINES   0x28
 4-bit interface, dual line, 5x7 dots More...
 
#define LCD_FUNCTION_8BIT_1LINE   0x30
 8-bit interface, single line, 5x7 dots More...
 
#define LCD_FUNCTION_8BIT_2LINES   0x38
 8-bit interface, dual line, 5x7 dots More...
 
#define LCD_START_LINE1   0x00
 DDRAM address of first char of line 1. More...
 
#define LCD_START_LINE2   0x40
 DDRAM address of first char of line 2. More...
 
#define LCD_START_LINE3   0x10
 DDRAM address of first char of line 3. More...
 
#define LCD_START_LINE4   0x50
 DDRAM address of first char of line 4. More...
 
#define LCD_MODE_DEFAULT   ((1<<LCD_ENTRY_MODE) | (1<<LCD_ENTRY_INC) )
 
#define LCD_STROBE()   (sbi(LCD_E_PORT, LCD_E_PIN), cbi(LCD_E_PORT, LCD_E_PIN))
 
#define LCD_DATA_BITS   (_BV(LCD_DATA_D7_PIN) | _BV(LCD_DATA_D6_PIN) | _BV(LCD_DATA_D5_PIN) | _BV(LCD_DATA_D4_PIN))
 
#define TIME_S1_MS   ( 1*(F_CPU/4000) )
 
#define delay_us(us)   delay_short( ((TIME_S1_MS*(us))/1000) )
 

Functions

static void delay_short (uint16_t number_of_loops)
 
static void lcd_write (uint8_t c)
 Write a byte to the LCD in 4 bit mode. More...
 
void lcd_clear (void)
 Clear and home the LCD. More...
 
void lcd_puts (const char *s)
 Write a string of characters to the LCD. More...
 
void lcd_puts_P (const char *s)
 Write a string from progmem of chars to the LCD. More...
 
void lcd_putc (char c)
 Write a character to the LCD. More...
 
void lcd_goto (uint8_t x, uint8_t y)
 Go to the specified position. More...
 
void lcd_clrxy (uint8_t x, uint8_t y, uint8_t count)
 Clear count characters starting at position (x,y). More...
 
void lcd_word (uint16_t value, uint8_t width)
 Write numeric value to the LCD. More...
 
void lcd_init (lcdDisplayMode_t dispAttr)
 Initialize the LCD - call before anything else. More...
 

Detailed Description

LCD interface example.

Uses routines from delay.c This code will interface to a standard LCD controller like the Hitachi HD44780. It uses it in 4 bit mode.

Ported to AVR-GCC by Alex Shepherd and modified to be compatible with previous LCD API

Version
$Id: lcd.c 159 2016-09-03 06:51:47Z pischky $
Author
Craig Lee
Alex Shepherd

Definition in file lcd.c.

Macro Definition Documentation

#define delay_us (   us)    delay_short( ((TIME_S1_MS*(us))/1000) )

Definition at line 136 of file lcd.c.

#define LCD_BUSY   7

DB7: LCD is busy.

Definition at line 105 of file lcd.c.

#define LCD_CGRAM   6

DB6: set CG RAM address.

Definition at line 103 of file lcd.c.

#define LCD_CLR   0

DB0: clear display.

Definition at line 87 of file lcd.c.

#define LCD_DATA_BITS   (_BV(LCD_DATA_D7_PIN) | _BV(LCD_DATA_D6_PIN) | _BV(LCD_DATA_D5_PIN) | _BV(LCD_DATA_D4_PIN))

Definition at line 133 of file lcd.c.

#define LCD_DDRAM   7

DB7: set DD RAM address.

Definition at line 104 of file lcd.c.

#define LCD_ENTRY_DEC   0x04

display shift off, dec cursor move dir

Definition at line 108 of file lcd.c.

#define LCD_ENTRY_DEC_SHIFT   0x05

display shift on, dec cursor move dir

Definition at line 109 of file lcd.c.

#define LCD_ENTRY_INC   1

DB1: 1=increment, 0=decrement.

Definition at line 90 of file lcd.c.

#define LCD_ENTRY_INC_   0x06

display shift off, inc cursor move dir

Definition at line 110 of file lcd.c.

#define LCD_ENTRY_INC_SHIFT   0x07

display shift on, inc cursor move dir

Definition at line 111 of file lcd.c.

#define LCD_ENTRY_MODE   2

DB2: set entry mode.

Definition at line 89 of file lcd.c.

#define LCD_ENTRY_SHIFT   2

DB2: 1=display shift on.

Definition at line 91 of file lcd.c.

#define LCD_FUNCTION   5

DB5: function set.

Definition at line 99 of file lcd.c.

#define LCD_FUNCTION_10DOTS   2

DB2: 5x10 font (0->5x7 font)

Definition at line 102 of file lcd.c.

#define LCD_FUNCTION_2LINES   3

DB3: two lines (0->one line)

Definition at line 101 of file lcd.c.

#define LCD_FUNCTION_4BIT_1LINE   0x20

4-bit interface, single line, 5x7 dots

Definition at line 120 of file lcd.c.

#define LCD_FUNCTION_4BIT_2LINES   0x28

4-bit interface, dual line, 5x7 dots

Definition at line 121 of file lcd.c.

#define LCD_FUNCTION_8BIT   4

DB4: set 8BIT mode (0->4BIT mode)

Definition at line 100 of file lcd.c.

#define LCD_FUNCTION_8BIT_1LINE   0x30

8-bit interface, single line, 5x7 dots

Definition at line 122 of file lcd.c.

#define LCD_FUNCTION_8BIT_2LINES   0x38

8-bit interface, dual line, 5x7 dots

Definition at line 123 of file lcd.c.

#define LCD_HOME   1

DB1: return to home position.

Definition at line 88 of file lcd.c.

#define LCD_MODE_DEFAULT   ((1<<LCD_ENTRY_MODE) | (1<<LCD_ENTRY_INC) )

Definition at line 130 of file lcd.c.

#define LCD_MOVE   4

DB4: move cursor/display.

Definition at line 96 of file lcd.c.

#define LCD_MOVE_CURSOR_LEFT   0x10

move cursor left (decrement)

Definition at line 114 of file lcd.c.

#define LCD_MOVE_CURSOR_RIGHT   0x14

move cursor right (increment)

Definition at line 115 of file lcd.c.

#define LCD_MOVE_DISP   3

DB3: move display (0-> cursor) ?

Definition at line 97 of file lcd.c.

#define LCD_MOVE_DISP_LEFT   0x18

shift display left

Definition at line 116 of file lcd.c.

#define LCD_MOVE_DISP_RIGHT   0x1C

shift display right

Definition at line 117 of file lcd.c.

#define LCD_MOVE_RIGHT   2

DB2: move right (0-> left) ?

Definition at line 98 of file lcd.c.

#define LCD_ON   3

DB3: turn lcd/cursor on.

Definition at line 92 of file lcd.c.

#define LCD_ON_BLINK   0

DB0: blinking cursor ?

Definition at line 95 of file lcd.c.

#define LCD_ON_CURSOR   1

DB1: turn cursor on.

Definition at line 94 of file lcd.c.

#define LCD_ON_DISPLAY   2

DB2: turn display on.

Definition at line 93 of file lcd.c.

#define LCD_START_LINE1   0x00

DDRAM address of first char of line 1.

Definition at line 125 of file lcd.c.

#define LCD_START_LINE2   0x40

DDRAM address of first char of line 2.

Definition at line 126 of file lcd.c.

#define LCD_START_LINE3   0x10

DDRAM address of first char of line 3.

Definition at line 127 of file lcd.c.

#define LCD_START_LINE4   0x50

DDRAM address of first char of line 4.

Definition at line 128 of file lcd.c.

#define LCD_STROBE ( )    (sbi(LCD_E_PORT, LCD_E_PIN), cbi(LCD_E_PORT, LCD_E_PIN))

Definition at line 132 of file lcd.c.

#define TIME_S1_MS   ( 1*(F_CPU/4000) )

Definition at line 135 of file lcd.c.

Function Documentation

static void delay_short ( uint16_t  number_of_loops)
static

Definition at line 138 of file lcd.c.

void lcd_clear ( void  )

Clear and home the LCD.

Definition at line 179 of file lcd.c.

Here is the call graph for this function:

void lcd_clrxy ( uint8_t  x,
uint8_t  y,
uint8_t  count 
)

Clear count characters starting at position (x,y).

Definition at line 222 of file lcd.c.

Here is the call graph for this function:

void lcd_goto ( uint8_t  x,
uint8_t  y 
)

Go to the specified position.

Definition at line 210 of file lcd.c.

Here is the call graph for this function:

void lcd_init ( lcdDisplayMode_t  dispAttr)

Initialize the LCD - call before anything else.

Parameters
dispAttrthe mode to use (on/off, cursor)

Definition at line 244 of file lcd.c.

Here is the call graph for this function:

void lcd_putc ( char  c)

Write a character to the LCD.

Definition at line 204 of file lcd.c.

Here is the call graph for this function:

void lcd_puts ( const char *  s)

Write a string of characters to the LCD.

Definition at line 186 of file lcd.c.

Here is the call graph for this function:

void lcd_puts_P ( const char *  s)

Write a string from progmem of chars to the LCD.

Definition at line 192 of file lcd.c.

Here is the call graph for this function:

void lcd_word ( uint16_t  value,
uint8_t  width 
)

Write numeric value to the LCD.

Definition at line 232 of file lcd.c.

Here is the call graph for this function:

static void lcd_write ( uint8_t  c)
static

Write a byte to the LCD in 4 bit mode.

lcd_write is used for commands and characters. Set LCD_RS_PIN before usage.

Definition at line 157 of file lcd.c.