LevelMeter-Display  2.0
An ultrasonic Level Meter for Stormwater Cisterns
Macros | Functions | Variables
lcd.c File Reference

Routines for handling the LC-Display. More...

Include dependency graph for lcd.c:

Macros

#define LCD_DDR   DDRC
 
#define LCD_EN   3
 
#define LCD_LIGHT   0
 
#define LCD_PIN   PINC
 
#define LCD_PORT   PORTC
 
#define LCD_RS   1
 
#define LCD_RW   2
 

Functions

void InitLCD (void)
 Initializes the LC-Display. More...
 
bool LCDBuildHBarChar (uint8_t nBars)
 Builds a Bar Graph Character for horizontal Bars. More...
 
bool LCDBuildVBarChar (uint8_t nBars)
 Builds a Character for vertical Bar Graph. More...
 
bool LCDBuildVBarChars (uint8_t nBars)
 Builds the Character Array for vertical Bar Graphs. More...
 
void LCDClear (void)
 Clears the LCD and sets Cursor to Home Postion. More...
 
void LCDGoTo (uint8_t pos)
 Sets the Cursor Position. More...
 
int8_t LCDHBarGraph (uint8_t line, uint8_t val)
 Prints a Line of Bar Graph. The rest of the line is cleared. More...
 
void LCDInitCGRAM ()
 Initializes the Character Generator RAM. More...
 
void LCDPrintLine_P (uint8_t line, const char *fmt,...)
 Printf for one complete Line of the Display. More...
 
char LCDRead (void)
 Reads a Byte from the LCD. More...
 
char LCDReadCmd (void)
 
char LCDReadNibble (void)
 Reads a nibble from LCD. More...
 
void LCDWait (void)
 Waits until the LCD is ready. More...
 
void LCDWrite (char c)
 Writes a Byte to the Display. More...
 
void LCDWriteCmd (char c)
 Writes a Command-Byte to the Display. More...
 
void LCDWriteData (char c)
 Writes a Data-Byte to the Display. More...
 
void LCDWriteNibble (char c)
 Writes a nibble to the LCD. More...
 
void LCDWriteString (const char *s)
 Displays a String. More...
 
int putchar_LCD (char c, FILE *file)
 The Putchar-Routine for the LCD. More...
 

Variables

FILE lcd =FDEV_SETUP_STREAM(putchar_LCD,NULL,_FDEV_SETUP_WRITE)
 
uint8_t lcdVbarChar [LCD_MAX_LINES]
 Holds the characters for Vertical Bar Graph from Line 3 to 0. More...
 

Detailed Description

Routines for handling the LC-Display.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Macro Definition Documentation

◆ LCD_DDR

#define LCD_DDR   DDRC

◆ LCD_EN

#define LCD_EN   3

◆ LCD_LIGHT

#define LCD_LIGHT   0

◆ LCD_PIN

#define LCD_PIN   PINC

◆ LCD_PORT

#define LCD_PORT   PORTC

◆ LCD_RS

#define LCD_RS   1

◆ LCD_RW

#define LCD_RW   2

Function Documentation

◆ InitLCD()

void InitLCD ( void  )

Initializes the LC-Display.

References delay50ms(), delay50us(), delay5ms(), LCD_DDR, LCD_EN, LCD_LIGHT, LCD_PORT, LCDClear(), LCDInitCGRAM(), and LCDWriteCmd().

Referenced by Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LCDBuildHBarChar()

bool LCDBuildHBarChar ( uint8_t  nBars)

Builds a Bar Graph Character for horizontal Bars.

The horizontal bar graph character can be printed as character code 2

Parameters
nBarsThe number of black Columns (0..5)
Returns
True if OK, false if not

References LCDWriteCmd(), and LCDWriteData().

Referenced by LCDHBarGraph().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LCDBuildVBarChar()

bool LCDBuildVBarChar ( uint8_t  nBars)

Builds a Character for vertical Bar Graph.

The vertical bar graph character can be printed as character code 3

Parameters
nBarsThe number of black Lines (0..8)
Returns
True if OK, false if not

References LCDGoTo(), LCDWriteCmd(), and LCDWriteData().

Referenced by LCDBuildVBarChars().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LCDBuildVBarChars()

bool LCDBuildVBarChars ( uint8_t  nBars)

Builds the Character Array for vertical Bar Graphs.

Parameters
nBarsThe number of black Bars
Returns
True if OK, false if not

References config, displayMetrics, confStruct_t::displayType, LCDBuildVBarChar(), lcdVbarChar, and displayMetrics_T::nLines.

Referenced by VBarGraphPrepare(), and VBarTest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LCDClear()

void LCDClear ( void  )

Clears the LCD and sets Cursor to Home Postion.

References LCDWriteCmd().

Referenced by CmdCalibrate(), CmdSetDisplay(), HBarTest(), InitLCD(), ShowScreen(), and VBarTest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LCDGoTo()

void LCDGoTo ( uint8_t  pos)

Sets the Cursor Position.

    Lines start at 0 and 64 for the 2x16 and
    0,64,20 and 84 for the 4x20-Display
Parameters
posThe Position

References LCDWriteCmd().

Referenced by EnterDouble(), LCDBuildVBarChar(), LCDHBarGraph(), LCDPrintLine_P(), and ShowScreen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LCDHBarGraph()

int8_t LCDHBarGraph ( uint8_t  line,
uint8_t  val 
)

Prints a Line of Bar Graph. The rest of the line is cleared.

Parameters
lineThe 0-based Line Number
valThe number of black Lines to draw. This is not a percent value! Maximum is five times the width of the display (i.e. 100 for 4x20 and 80 for 2x16).
Returns
-1 on Error, 0 if OK

References config, displayMetrics, confStruct_t::displayType, LCDBuildHBarChar(), LCDGoTo(), LCDWriteData(), displayMetrics_T::nLines, displayMetrics_T::startLine, and displayMetrics_T::width.

Referenced by HBarGraphPerCent(), and HBarTest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LCDInitCGRAM()

void LCDInitCGRAM ( )

Initializes the Character Generator RAM.

This routine basically defines the antenna-character (DCF77-symbol). Since a character 0 cannot be used for printf, we use character 1 for it.
The symbols for bargraph display use character codes 2 to 6. Character code 7 is unused until now.

References LCDWriteCmd(), and LCDWriteData().

Referenced by InitLCD().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LCDPrintLine_P()

void LCDPrintLine_P ( uint8_t  line,
const char *  fmt,
  ... 
)

Printf for one complete Line of the Display.

This is a handy printf-like function for outputting display content. It ensures that no more characters are written than one line can hold and automatically deletes all characters beyond the content so that no fragments of the previous content remain visible.

Parameters
lineThe line to print on (0-based)
fmtA printf-like format string
...Optional further parameters
Returns

References config, displayMetrics, confStruct_t::displayType, LCD_MAX_WIDTH, LCDGoTo(), LCDWriteData(), LCDWriteString(), displayMetrics_T::nLines, displayMetrics_T::startLine, and displayMetrics_T::width.

Referenced by FTest485(), HBarTest(), ShowScreen(), and VBarTestPrint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LCDRead()

char LCDRead ( void  )

Reads a Byte from the LCD.

References LCDReadNibble().

Referenced by LCDReadCmd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LCDReadCmd()

char LCDReadCmd ( void  )

References LCD_PORT, LCD_RS, and LCDRead().

Referenced by LCDWait().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LCDReadNibble()

char LCDReadNibble ( void  )

Reads a nibble from LCD.

Returns
Character with data in four MSBs, LSBs are zero

References LCD_DDR, LCD_EN, LCD_PIN, LCD_PORT, and LCD_RW.

Referenced by LCDRead().

Here is the caller graph for this function:

◆ LCDWait()

void LCDWait ( void  )

Waits until the LCD is ready.

References LCDReadCmd().

Referenced by LCDWriteCmd(), and LCDWriteData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LCDWrite()

void LCDWrite ( char  c)

Writes a Byte to the Display.

The state of the RS-pin decides weather it is data or command.

Parameters
cThe Byte

References LCD_DDR, LCD_PORT, LCD_RW, and LCDWriteNibble().

Referenced by LCDWriteCmd(), and LCDWriteData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LCDWriteCmd()

void LCDWriteCmd ( char  c)

Writes a Command-Byte to the Display.

Parameters
cThe Byte

References LCD_PORT, LCD_RS, LCDWait(), and LCDWrite().

Referenced by InitLCD(), LCDBuildHBarChar(), LCDBuildVBarChar(), LCDClear(), LCDGoTo(), and LCDInitCGRAM().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LCDWriteData()

void LCDWriteData ( char  c)

Writes a Data-Byte to the Display.

Parameters
cThe Byte

References LCD_PORT, LCD_RS, LCDWait(), and LCDWrite().

Referenced by LCDBuildHBarChar(), LCDBuildVBarChar(), LCDHBarGraph(), LCDInitCGRAM(), LCDPrintLine_P(), LCDWriteString(), and putchar_LCD().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LCDWriteNibble()

void LCDWriteNibble ( char  c)

Writes a nibble to the LCD.

Parameters
cThe Character. Only the upper nibble is used

References LCD_EN, and LCD_PORT.

Referenced by LCDWrite().

Here is the caller graph for this function:

◆ LCDWriteString()

void LCDWriteString ( const char *  s)

Displays a String.

Parameters
sThe String

References LCDWriteData().

Referenced by LCDPrintLine_P().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ putchar_LCD()

int putchar_LCD ( char  c,
FILE *  file 
)

The Putchar-Routine for the LCD.

Parameters
cThe Character
fileA pointer to the file (unused)
Returns
Always 0

References config, DISPLAY_ANALOG, confStruct_t::displayType, and LCDWriteData().

Here is the call graph for this function:

Variable Documentation

◆ lcd

FILE lcd =FDEV_SETUP_STREAM(putchar_LCD,NULL,_FDEV_SETUP_WRITE)

Referenced by Init().

◆ lcdVbarChar

uint8_t lcdVbarChar

Holds the characters for Vertical Bar Graph from Line 3 to 0.

Referenced by LCDBuildVBarChars(), ShowScreen(), and VBarTestPrint().