0,0 → 1,164 |
/* --------------------------------------------------------------------------- |
* AVR_MLIB - HD 44780 LCD Display Driver |
* www.mlab.cz miho 2008 |
* --------------------------------------------------------------------------- |
* LCD display driver for standard Hitachi 1/2/4 line character LCD modules |
* for AVR processors. It uses 4 or 8 bit interface without readback. |
* In the Examples section there is a demo application for this library. |
* --------------------------------------------------------------------------- |
* 00.00 2008/03/28 First Version |
* --------------------------------------------------------------------------- |
*/ |
|
|
// What should be set and done before here |
// --------------------------------------- |
// |
// #include <stdio.h> // If you want to use printf, ... |
// |
// #define LCD_DATA B // 4 or 8 bits field (lsb bit of the port) |
// #define LCD_DATA_BIT 4 |
// |
// #define LCD_RS D // Register Select (port and bit) |
// #define LCD_RS_BIT 4 |
// |
// #define LCD_E D // Enable (port and bit) |
// #define LCD_E_BIT 3 |
// |
// |
// // LCD Display Parameters |
// #define LCD_INTERFACE_BITS 4 // 4 or 8 bit interface |
// #define LCD_LINES 1 // 1 or 2 or 4 lines |
// #define LCD_CHARS 20 // usualy 16 or 20, important for 4 line display only |
// |
// #include "lcd_hd44780.h" // Use LCD Library |
// |
// |
// How to use the library |
// ---------------------- |
// |
// void lcd_init(void) // Init LCD Display |
// |
// void lcd_home() // Goto Home |
// |
// void lcd_clear() // Clear Display |
// |
// void lcd_clear_home() // Clear Display and Goto Home with no Cursor |
// |
// void lcd_cursor_on() // Switch Cursor On |
// |
// void lcd_cursor_off() // Switch Cursor Off |
// |
// void lcd_cursor_left() // Move Cursor Left |
// |
// void lcd_cursor_right() // Move Cursor Right |
// |
// void lcd_gotoxy(uint8_t x, uint8_t y) // Move to Position (1,1 is the first position) |
// |
// int lcd_putc(char c) // LCD Char Output |
// |
// int lcd_putc_stream(char c, FILE *unused) // LCD Char Output (for Stream Library) |
// |
// |
// How to use printf |
// ----------------- |
// |
// 1) Define FILE structure |
// |
// static FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putc_stream, NULL, _FDEV_SETUP_WRITE); |
// |
// 2) Connect it with standard output |
// |
// stdout = &lcd_stream; // Connect stdout to LCD Stream |
// |
// 3) Use printf |
// |
// printf("\fHello World!\n------------"); |
// |
// 4) Use special chars |
// |
// \f - clear display and goto home |
// \n - goto the beginning of the next line |
// \r - goto to the beginning of curent line |
// \b - backspace |
// \v - start and end definition of user defined char |
// |
// |
// How to use User Defined symbols |
// ------------------------------- |
// |
// That is easy. Just print the definition to lcd. Look at the example |
// |
// printf("\v" "\x10" LCD_CHAR_BAT50 "\v"); // definition (redefines CGRAM content of the LCD) |
// printf("Battery Status \x10"); // usage |
// |
// \v starts the definition |
// \x10 first (of eight) user defined char |
// LCD_CHAR_BAT50 half battery symbol, you can define more symbols here (up to 8) |
// \v end of definition |
// |
|
#include "global.h" |
#include <avr/io.h> // Device Specific Defines |
#include <stdio.h> |
#include <util/delay.h> // Delay Routines |
|
// IO Pins MACROS |
#define GLUE(a,b) a##b |
#define PORT(a) GLUE(PORT,a) |
#define PIN(a) GLUE(PIN,a) |
#define DDR(a) GLUE(DDR,a) |
|
|
|
// LCD Port Settings |
#define LCD_DATA A // 4 or 8 bits field (lsb port) |
#define LCD_DATA_BIT 4 |
|
#define LCD_RS C // Register Select |
#define LCD_RS_BIT 2 |
|
#define LCD_E C // Enable |
#define LCD_E_BIT 4 |
|
// LCD Display Parameters |
#define LCD_INTERFACE_BITS 4 // 4 or 8 bit interface |
#define LCD_LINES 2 // 1 or 2 or 4 lines |
#define LCD_CHARS 18 // usualy 16 or 20, important for 4 line display only |
|
// Goto Home |
void lcd_home(void); |
|
// Clear Display |
void lcd_clear(void); |
|
// Switch Cursor On |
void lcd_cursor_on(void); |
|
// Switch Cursor Off |
void lcd_cursor_off(void); |
|
// Clear Display and Goto Home with no Cursor |
void lcd_clear_home(void); |
|
// Move to Position (1,1 is the first position) |
void lcd_gotoxy(uint8_t x, uint8_t y); |
|
// Increment Position |
void lcd_inc_pos(void); |
|
// Decrement Position |
void lcd_dec_pos(void); |
|
// Move Cursor Left |
void lcd_cursor_left(void); |
|
// Move Cursor Right |
void lcd_cursor_right(void); |
|
// Init LCD Display |
void lcd_init(void); |
|
// LCD Char Output |
int lcd_putc(char c); |
|