Amend lcd_goto() to be safe and not move cursor outside of screen limits and add screen positions definitions

This commit is contained in:
Silver Kits 2016-10-04 22:00:20 +03:00
parent 0825cd2f44
commit 2f5451d76e
2 changed files with 12 additions and 0 deletions

View File

@ -7,6 +7,8 @@ Version: 1.11
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include <avr/sfr_defs.h> #include <avr/sfr_defs.h>
#include <inttypes.h> #include <inttypes.h>
#define __ASSERT_USE_STDERR
#include <assert.h>
#include "hd44780.h" #include "hd44780.h"
#include "hd44780_settings.h" #include "hd44780_settings.h"
@ -495,6 +497,8 @@ Returns: none
*************************************************************************/ *************************************************************************/
void lcd_goto(uint8_t pos) void lcd_goto(uint8_t pos)
{ {
//Do not go outside of screen limits
assert(pos < LCD_COLS_MAX);
lcd_command((1<<LCD_DDRAM)+pos); lcd_command((1<<LCD_DDRAM)+pos);
} }

View File

@ -36,6 +36,14 @@ Version: 1.11
#define LCD_BUSY 7 // DB7: LCD is busy #define LCD_BUSY 7 // DB7: LCD is busy
// LCD columns and rows definitions
#define LCD_ROW_1 0
#define LCD_ROW_2 64
#define LCD_COLS_MAX 128
// Maximum character what can be displayed with 1 byte
#define MAX_CARACTER 255
void lcd_init(); void lcd_init();
void lcd_command(uint8_t cmd); void lcd_command(uint8_t cmd);