Fix hd44780 formatting and add modifications descriptions to files headers
This commit is contained in:
parent
51951fcea1
commit
6dac14ab59
246
lib/hd44780_111/hd44780.c
Executable file → Normal file
246
lib/hd44780_111/hd44780.c
Executable file → Normal file
@ -2,8 +2,10 @@
|
|||||||
Title : HD44780 Library
|
Title : HD44780 Library
|
||||||
Author : SA Development
|
Author : SA Development
|
||||||
Version: 1.11
|
Version: 1.11
|
||||||
|
Modifications for: Arduino Mega 2560
|
||||||
|
Itead Studio Arduino 1602 LED Keypad Shield
|
||||||
|
Modified by: Silver Kits <silver.kits@eesti.ee> October 2016
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
#include <avr/sfr_defs.h>
|
#include <avr/sfr_defs.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
@ -159,92 +161,120 @@ static unsigned char ActiveDisplay=1;
|
|||||||
static inline void lcd_e_port_low()
|
static inline void lcd_e_port_low()
|
||||||
{
|
{
|
||||||
#if (LCD_DISPLAYS>1)
|
#if (LCD_DISPLAYS>1)
|
||||||
switch (ActiveDisplay)
|
|
||||||
{
|
switch (ActiveDisplay) {
|
||||||
case 2 : LCD_E2_PORT&=~_BV(LCD_E2_PIN);
|
case 2 :
|
||||||
|
LCD_E2_PORT &= ~_BV(LCD_E2_PIN);
|
||||||
break;
|
break;
|
||||||
#if (LCD_DISPLAYS>=3)
|
#if (LCD_DISPLAYS>=3)
|
||||||
case 3 : LCD_E3_PORT&=~_BV(LCD_E3_PIN);
|
|
||||||
|
case 3 :
|
||||||
|
LCD_E3_PORT &= ~_BV(LCD_E3_PIN);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if (LCD_DISPLAYS==4)
|
#if (LCD_DISPLAYS==4)
|
||||||
case 4 : LCD_E4_PORT&=~_BV(LCD_E4_PIN);
|
|
||||||
|
case 4 :
|
||||||
|
LCD_E4_PORT &= ~_BV(LCD_E4_PIN);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default :
|
default :
|
||||||
#endif
|
#endif
|
||||||
LCD_E_PORT &= ~_BV(LCD_E_PIN);
|
LCD_E_PORT &= ~_BV(LCD_E_PIN);
|
||||||
#if (LCD_DISPLAYS>1)
|
#if (LCD_DISPLAYS>1)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void lcd_e_port_high()
|
static inline void lcd_e_port_high()
|
||||||
{
|
{
|
||||||
#if (LCD_DISPLAYS>1)
|
#if (LCD_DISPLAYS>1)
|
||||||
switch (ActiveDisplay)
|
|
||||||
{
|
switch (ActiveDisplay) {
|
||||||
case 2 : LCD_E2_PORT|=_BV(LCD_E2_PIN);
|
case 2 :
|
||||||
|
LCD_E2_PORT |= _BV(LCD_E2_PIN);
|
||||||
break;
|
break;
|
||||||
#if (LCD_DISPLAYS>=3)
|
#if (LCD_DISPLAYS>=3)
|
||||||
case 3 : LCD_E3_PORT|=_BV(LCD_E3_PIN);
|
|
||||||
|
case 3 :
|
||||||
|
LCD_E3_PORT |= _BV(LCD_E3_PIN);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if (LCD_DISPLAYS==4)
|
#if (LCD_DISPLAYS==4)
|
||||||
case 4 : LCD_E4_PORT|=_BV(LCD_E4_PIN);
|
|
||||||
|
case 4 :
|
||||||
|
LCD_E4_PORT |= _BV(LCD_E4_PIN);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default :
|
default :
|
||||||
#endif
|
#endif
|
||||||
LCD_E_PORT |= _BV(LCD_E_PIN);
|
LCD_E_PORT |= _BV(LCD_E_PIN);
|
||||||
#if (LCD_DISPLAYS>1)
|
#if (LCD_DISPLAYS>1)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void lcd_e_ddr_low()
|
static inline void lcd_e_ddr_low()
|
||||||
{
|
{
|
||||||
#if (LCD_DISPLAYS>1)
|
#if (LCD_DISPLAYS>1)
|
||||||
switch (ActiveDisplay)
|
|
||||||
{
|
switch (ActiveDisplay) {
|
||||||
case 2 : DDR(LCD_E2_PORT)&=~_BV(LCD_E2_PIN);
|
case 2 :
|
||||||
|
DDR(LCD_E2_PORT) &= ~_BV(LCD_E2_PIN);
|
||||||
break;
|
break;
|
||||||
#if (LCD_DISPLAYS>=3)
|
#if (LCD_DISPLAYS>=3)
|
||||||
case 3 : DDR(LCD_E3_PORT)&=~_BV(LCD_E3_PIN);
|
|
||||||
|
case 3 :
|
||||||
|
DDR(LCD_E3_PORT) &= ~_BV(LCD_E3_PIN);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if (LCD_DISPLAYS==4)
|
#if (LCD_DISPLAYS==4)
|
||||||
case 4 : DDR(LCD_E4_PORT)&=~_BV(LCD_E4_PIN);
|
|
||||||
|
case 4 :
|
||||||
|
DDR(LCD_E4_PORT) &= ~_BV(LCD_E4_PIN);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default :
|
default :
|
||||||
#endif
|
#endif
|
||||||
DDR(LCD_E_PORT) &= ~_BV(LCD_E_PIN);
|
DDR(LCD_E_PORT) &= ~_BV(LCD_E_PIN);
|
||||||
#if (LCD_DISPLAYS>1)
|
#if (LCD_DISPLAYS>1)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void lcd_e_ddr_high()
|
static inline void lcd_e_ddr_high()
|
||||||
{
|
{
|
||||||
#if (LCD_DISPLAYS>1)
|
#if (LCD_DISPLAYS>1)
|
||||||
switch (ActiveDisplay)
|
|
||||||
{
|
switch (ActiveDisplay) {
|
||||||
case 2 : DDR(LCD_E2_PORT)|=_BV(LCD_E2_PIN);
|
case 2 :
|
||||||
|
DDR(LCD_E2_PORT) |= _BV(LCD_E2_PIN);
|
||||||
break;
|
break;
|
||||||
#if (LCD_DISPLAYS>=3)
|
#if (LCD_DISPLAYS>=3)
|
||||||
case 3 : DDR(LCD_E3_PORT)|=_BV(LCD_E3_PIN);
|
|
||||||
|
case 3 :
|
||||||
|
DDR(LCD_E3_PORT) |= _BV(LCD_E3_PIN);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if (LCD_DISPLAYS==4)
|
#if (LCD_DISPLAYS==4)
|
||||||
case 4 : DDR(LCD_E4_PORT)|=_BV(LCD_E4_PIN);
|
|
||||||
|
case 4 :
|
||||||
|
DDR(LCD_E4_PORT) |= _BV(LCD_E4_PIN);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default :
|
default :
|
||||||
#endif
|
#endif
|
||||||
DDR(LCD_E_PORT) |= _BV(LCD_E_PIN);
|
DDR(LCD_E_PORT) |= _BV(LCD_E_PIN);
|
||||||
#if (LCD_DISPLAYS>1)
|
#if (LCD_DISPLAYS>1)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,9 +290,12 @@ static void lcd_waitbusy(void)
|
|||||||
register uint8_t c;
|
register uint8_t c;
|
||||||
unsigned int ul1 = 0;
|
unsigned int ul1 = 0;
|
||||||
|
|
||||||
while ( ((c=lcd_read(0)) & (1<<LCD_BUSY)) && ul1<((F_CPU/16384>=16)?F_CPU/16384:16)) // Wait Until Busy Flag is Cleared
|
while ( ((c = lcd_read(0)) & (1 << LCD_BUSY)) &&
|
||||||
|
ul1 < ((F_CPU / 16384 >= 16) ? F_CPU / 16384 :
|
||||||
|
16)) { // Wait Until Busy Flag is Cleared
|
||||||
ul1++;
|
ul1++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -276,57 +309,49 @@ Returns: byte read from LCD controller
|
|||||||
static uint8_t lcd_read(uint8_t rs)
|
static uint8_t lcd_read(uint8_t rs)
|
||||||
{
|
{
|
||||||
uint8_t data;
|
uint8_t data;
|
||||||
|
|
||||||
#if (WAIT_MODE==1 && RW_LINE_IMPLEMENTED==1)
|
#if (WAIT_MODE==1 && RW_LINE_IMPLEMENTED==1)
|
||||||
if (rs)
|
|
||||||
|
if (rs) {
|
||||||
lcd_waitbusy();
|
lcd_waitbusy();
|
||||||
if (PrevCmdInvolvedAddressCounter)
|
}
|
||||||
{
|
|
||||||
|
if (PrevCmdInvolvedAddressCounter) {
|
||||||
Delay_us(5);
|
Delay_us(5);
|
||||||
PrevCmdInvolvedAddressCounter = 0;
|
PrevCmdInvolvedAddressCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (rs)
|
if (rs) {
|
||||||
{
|
|
||||||
lcd_rs_port_high(); // RS=1: Read Data
|
lcd_rs_port_high(); // RS=1: Read Data
|
||||||
#if (WAIT_MODE==1 && RW_LINE_IMPLEMENTED==1)
|
#if (WAIT_MODE==1 && RW_LINE_IMPLEMENTED==1)
|
||||||
PrevCmdInvolvedAddressCounter = 1;
|
PrevCmdInvolvedAddressCounter = 1;
|
||||||
#endif
|
#endif
|
||||||
|
} else {
|
||||||
|
lcd_rs_port_low(); // RS=0: Read Busy Flag
|
||||||
}
|
}
|
||||||
else lcd_rs_port_low(); // RS=0: Read Busy Flag
|
|
||||||
|
|
||||||
|
|
||||||
lcd_rw_port_high(); // RW=1: Read Mode
|
lcd_rw_port_high(); // RW=1: Read Mode
|
||||||
|
|
||||||
#if LCD_BITS==4
|
#if LCD_BITS==4
|
||||||
lcd_db7_ddr_low(); // Configure Data Pins as Input
|
lcd_db7_ddr_low(); // Configure Data Pins as Input
|
||||||
lcd_db6_ddr_low();
|
lcd_db6_ddr_low();
|
||||||
lcd_db5_ddr_low();
|
lcd_db5_ddr_low();
|
||||||
lcd_db4_ddr_low();
|
lcd_db4_ddr_low();
|
||||||
|
|
||||||
lcd_e_port_high(); // Read High Nibble First
|
lcd_e_port_high(); // Read High Nibble First
|
||||||
Delay_ns(500);
|
Delay_ns(500);
|
||||||
|
|
||||||
data = lcd_db4_pin_get() << 4 | lcd_db5_pin_get() << 5 |
|
data = lcd_db4_pin_get() << 4 | lcd_db5_pin_get() << 5 |
|
||||||
lcd_db6_pin_get() << 6 | lcd_db7_pin_get() << 7;
|
lcd_db6_pin_get() << 6 | lcd_db7_pin_get() << 7;
|
||||||
|
|
||||||
lcd_e_port_low();
|
lcd_e_port_low();
|
||||||
Delay_ns(500);
|
Delay_ns(500);
|
||||||
|
|
||||||
lcd_e_port_high(); // Read Low Nibble
|
lcd_e_port_high(); // Read Low Nibble
|
||||||
Delay_ns(500);
|
Delay_ns(500);
|
||||||
|
|
||||||
data |= lcd_db4_pin_get() << 0 | lcd_db5_pin_get() << 1 |
|
data |= lcd_db4_pin_get() << 0 | lcd_db5_pin_get() << 1 |
|
||||||
lcd_db6_pin_get() << 2 | lcd_db7_pin_get() << 3;
|
lcd_db6_pin_get() << 2 | lcd_db7_pin_get() << 3;
|
||||||
|
|
||||||
lcd_e_port_low();
|
lcd_e_port_low();
|
||||||
|
|
||||||
lcd_db7_ddr_high(); // Configure Data Pins as Output
|
lcd_db7_ddr_high(); // Configure Data Pins as Output
|
||||||
lcd_db6_ddr_high();
|
lcd_db6_ddr_high();
|
||||||
lcd_db5_ddr_high();
|
lcd_db5_ddr_high();
|
||||||
lcd_db4_ddr_high();
|
lcd_db4_ddr_high();
|
||||||
|
|
||||||
lcd_db7_port_high(); // Pins High (Inactive)
|
lcd_db7_port_high(); // Pins High (Inactive)
|
||||||
lcd_db6_port_high();
|
lcd_db6_port_high();
|
||||||
lcd_db5_port_high();
|
lcd_db5_port_high();
|
||||||
@ -340,17 +365,13 @@ static uint8_t lcd_read(uint8_t rs)
|
|||||||
lcd_db2_ddr_low();
|
lcd_db2_ddr_low();
|
||||||
lcd_db1_ddr_low();
|
lcd_db1_ddr_low();
|
||||||
lcd_db0_ddr_low();
|
lcd_db0_ddr_low();
|
||||||
|
|
||||||
lcd_e_port_high();
|
lcd_e_port_high();
|
||||||
Delay_ns(500);
|
Delay_ns(500);
|
||||||
|
|
||||||
data = lcd_db7_pin_get() << 7 | lcd_db6_pin_get() << 6 |
|
data = lcd_db7_pin_get() << 7 | lcd_db6_pin_get() << 6 |
|
||||||
lcd_db5_pin_get() << 5 | lcd_db4_pin_get() << 4 |
|
lcd_db5_pin_get() << 5 | lcd_db4_pin_get() << 4 |
|
||||||
lcd_db3_pin_get() << 3 | lcd_db2_pin_get() << 2 |
|
lcd_db3_pin_get() << 3 | lcd_db2_pin_get() << 2 |
|
||||||
lcd_db1_pin_get() << 1 | lcd_db0_pin_get();
|
lcd_db1_pin_get() << 1 | lcd_db0_pin_get();
|
||||||
|
|
||||||
lcd_e_port_low();
|
lcd_e_port_low();
|
||||||
|
|
||||||
lcd_db7_ddr_high(); // Configure Data Pins as Output
|
lcd_db7_ddr_high(); // Configure Data Pins as Output
|
||||||
lcd_db6_ddr_high();
|
lcd_db6_ddr_high();
|
||||||
lcd_db5_ddr_high();
|
lcd_db5_ddr_high();
|
||||||
@ -359,7 +380,6 @@ static uint8_t lcd_read(uint8_t rs)
|
|||||||
lcd_db2_ddr_high();
|
lcd_db2_ddr_high();
|
||||||
lcd_db1_ddr_high();
|
lcd_db1_ddr_high();
|
||||||
lcd_db0_ddr_high();
|
lcd_db0_ddr_high();
|
||||||
|
|
||||||
lcd_db7_port_high(); // Pins High (Inactive)
|
lcd_db7_port_high(); // Pins High (Inactive)
|
||||||
lcd_db6_port_high();
|
lcd_db6_port_high();
|
||||||
lcd_db5_port_high();
|
lcd_db5_port_high();
|
||||||
@ -369,13 +389,15 @@ static uint8_t lcd_read(uint8_t rs)
|
|||||||
lcd_db1_port_high();
|
lcd_db1_port_high();
|
||||||
lcd_db0_port_high();
|
lcd_db0_port_high();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
lcd_rw_port_low();
|
lcd_rw_port_low();
|
||||||
|
|
||||||
#if (WAIT_MODE==0 || RW_LINE_IMPLEMENTED==0)
|
#if (WAIT_MODE==0 || RW_LINE_IMPLEMENTED==0)
|
||||||
if (rs)
|
|
||||||
|
if (rs) {
|
||||||
Delay_us(40);
|
Delay_us(40);
|
||||||
else Delay_us(1);
|
} else {
|
||||||
|
Delay_us(1);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@ -398,22 +420,20 @@ static void lcd_write(uint8_t data,uint8_t rs)
|
|||||||
{
|
{
|
||||||
#if (WAIT_MODE==1 && RW_LINE_IMPLEMENTED==1)
|
#if (WAIT_MODE==1 && RW_LINE_IMPLEMENTED==1)
|
||||||
lcd_waitbusy();
|
lcd_waitbusy();
|
||||||
if (PrevCmdInvolvedAddressCounter)
|
|
||||||
{
|
if (PrevCmdInvolvedAddressCounter) {
|
||||||
Delay_us(5);
|
Delay_us(5);
|
||||||
PrevCmdInvolvedAddressCounter = 0;
|
PrevCmdInvolvedAddressCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (rs)
|
if (rs) {
|
||||||
{
|
|
||||||
lcd_rs_port_high(); // RS=1: Write Character
|
lcd_rs_port_high(); // RS=1: Write Character
|
||||||
#if (WAIT_MODE==1 && RW_LINE_IMPLEMENTED==1)
|
#if (WAIT_MODE==1 && RW_LINE_IMPLEMENTED==1)
|
||||||
PrevCmdInvolvedAddressCounter = 1;
|
PrevCmdInvolvedAddressCounter = 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
lcd_rs_port_low(); // RS=0: Write Command
|
lcd_rs_port_low(); // RS=0: Write Command
|
||||||
#if (WAIT_MODE==1 && RW_LINE_IMPLEMENTED==1)
|
#if (WAIT_MODE==1 && RW_LINE_IMPLEMENTED==1)
|
||||||
PrevCmdInvolvedAddressCounter = 0;
|
PrevCmdInvolvedAddressCounter = 0;
|
||||||
@ -425,29 +445,22 @@ static void lcd_write(uint8_t data,uint8_t rs)
|
|||||||
lcd_db6_port_set(data & _BV(6));
|
lcd_db6_port_set(data & _BV(6));
|
||||||
lcd_db5_port_set(data & _BV(5));
|
lcd_db5_port_set(data & _BV(5));
|
||||||
lcd_db4_port_set(data & _BV(4));
|
lcd_db4_port_set(data & _BV(4));
|
||||||
|
|
||||||
Delay_ns(100);
|
Delay_ns(100);
|
||||||
lcd_e_port_high();
|
lcd_e_port_high();
|
||||||
|
|
||||||
Delay_ns(500);
|
Delay_ns(500);
|
||||||
lcd_e_port_low();
|
lcd_e_port_low();
|
||||||
|
|
||||||
lcd_db7_port_set(data & _BV(3)); //Output High Nibble
|
lcd_db7_port_set(data & _BV(3)); //Output High Nibble
|
||||||
lcd_db6_port_set(data & _BV(2));
|
lcd_db6_port_set(data & _BV(2));
|
||||||
lcd_db5_port_set(data & _BV(1));
|
lcd_db5_port_set(data & _BV(1));
|
||||||
lcd_db4_port_set(data & _BV(0));
|
lcd_db4_port_set(data & _BV(0));
|
||||||
|
|
||||||
Delay_ns(100);
|
Delay_ns(100);
|
||||||
lcd_e_port_high();
|
lcd_e_port_high();
|
||||||
|
|
||||||
Delay_ns(500);
|
Delay_ns(500);
|
||||||
lcd_e_port_low();
|
lcd_e_port_low();
|
||||||
|
|
||||||
lcd_db7_port_high(); // All Data Pins High (Inactive)
|
lcd_db7_port_high(); // All Data Pins High (Inactive)
|
||||||
lcd_db6_port_high();
|
lcd_db6_port_high();
|
||||||
lcd_db5_port_high();
|
lcd_db5_port_high();
|
||||||
lcd_db4_port_high();
|
lcd_db4_port_high();
|
||||||
|
|
||||||
#else //using 8-Bit_Mode
|
#else //using 8-Bit_Mode
|
||||||
lcd_db7_port_set(data & _BV(7)); //Output High Nibble
|
lcd_db7_port_set(data & _BV(7)); //Output High Nibble
|
||||||
lcd_db6_port_set(data & _BV(6));
|
lcd_db6_port_set(data & _BV(6));
|
||||||
@ -457,12 +470,10 @@ static void lcd_write(uint8_t data,uint8_t rs)
|
|||||||
lcd_db2_port_set(data & _BV(2));
|
lcd_db2_port_set(data & _BV(2));
|
||||||
lcd_db1_port_set(data & _BV(1));
|
lcd_db1_port_set(data & _BV(1));
|
||||||
lcd_db0_port_set(data & _BV(0));
|
lcd_db0_port_set(data & _BV(0));
|
||||||
|
|
||||||
Delay_ns(100);
|
Delay_ns(100);
|
||||||
lcd_e_port_high();
|
lcd_e_port_high();
|
||||||
Delay_ns(500);
|
Delay_ns(500);
|
||||||
lcd_e_port_low();
|
lcd_e_port_low();
|
||||||
|
|
||||||
lcd_db7_port_high(); // All Data Pins High (Inactive)
|
lcd_db7_port_high(); // All Data Pins High (Inactive)
|
||||||
lcd_db6_port_high();
|
lcd_db6_port_high();
|
||||||
lcd_db5_port_high();
|
lcd_db5_port_high();
|
||||||
@ -472,11 +483,15 @@ static void lcd_write(uint8_t data,uint8_t rs)
|
|||||||
lcd_db1_port_high();
|
lcd_db1_port_high();
|
||||||
lcd_db0_port_high();
|
lcd_db0_port_high();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (WAIT_MODE==0 || RW_LINE_IMPLEMENTED==0)
|
#if (WAIT_MODE==0 || RW_LINE_IMPLEMENTED==0)
|
||||||
if (!rs && data<=((1<<LCD_CLR) | (1<<LCD_HOME))) // Is command clrscr or home?
|
|
||||||
|
if (!rs &&
|
||||||
|
data <= ((1 << LCD_CLR) | (1 << LCD_HOME))) { // Is command clrscr or home?
|
||||||
Delay_us(1640);
|
Delay_us(1640);
|
||||||
else Delay_us(40);
|
} else {
|
||||||
|
Delay_us(40);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -545,9 +560,10 @@ void lcd_puts(const char *s)
|
|||||||
{
|
{
|
||||||
register char c;
|
register char c;
|
||||||
|
|
||||||
while ((c=*s++))
|
while ((c = *s++)) {
|
||||||
lcd_putc(c);
|
lcd_putc(c);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
@ -559,9 +575,10 @@ void lcd_puts_P(const char *progmem_s)
|
|||||||
{
|
{
|
||||||
register char c;
|
register char c;
|
||||||
|
|
||||||
while ((c=pgm_read_byte(progmem_s++)))
|
while ((c = pgm_read_byte(progmem_s++))) {
|
||||||
lcd_putc(c);
|
lcd_putc(c);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
Initialize display
|
Initialize display
|
||||||
@ -586,14 +603,12 @@ void lcd_init()
|
|||||||
lcd_db1_ddr_high();
|
lcd_db1_ddr_high();
|
||||||
lcd_db0_ddr_high();
|
lcd_db0_ddr_high();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Set All Control Lines Low
|
//Set All Control Lines Low
|
||||||
lcd_e_port_low();
|
lcd_e_port_low();
|
||||||
lcd_rs_port_low();
|
lcd_rs_port_low();
|
||||||
#if RW_LINE_IMPLEMENTED==1
|
#if RW_LINE_IMPLEMENTED==1
|
||||||
lcd_rw_port_low();
|
lcd_rw_port_low();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Set All Data Lines High
|
//Set All Data Lines High
|
||||||
lcd_db7_port_high();
|
lcd_db7_port_high();
|
||||||
lcd_db6_port_high();
|
lcd_db6_port_high();
|
||||||
@ -605,10 +620,8 @@ void lcd_init()
|
|||||||
lcd_db1_port_high();
|
lcd_db1_port_high();
|
||||||
lcd_db0_port_high();
|
lcd_db0_port_high();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Startup Delay
|
//Startup Delay
|
||||||
Delay_ms(DELAY_RESET);
|
Delay_ms(DELAY_RESET);
|
||||||
|
|
||||||
//Initialize Display
|
//Initialize Display
|
||||||
lcd_db7_port_low();
|
lcd_db7_port_low();
|
||||||
lcd_db6_port_low();
|
lcd_db6_port_low();
|
||||||
@ -616,21 +629,15 @@ void lcd_init()
|
|||||||
lcd_e_port_high();
|
lcd_e_port_high();
|
||||||
Delay_ns(500);
|
Delay_ns(500);
|
||||||
lcd_e_port_low();
|
lcd_e_port_low();
|
||||||
|
|
||||||
Delay_us(4100);
|
Delay_us(4100);
|
||||||
|
|
||||||
lcd_e_port_high();
|
lcd_e_port_high();
|
||||||
Delay_ns(500);
|
Delay_ns(500);
|
||||||
lcd_e_port_low();
|
lcd_e_port_low();
|
||||||
|
|
||||||
Delay_us(100);
|
Delay_us(100);
|
||||||
|
|
||||||
lcd_e_port_high();
|
lcd_e_port_high();
|
||||||
Delay_ns(500);
|
Delay_ns(500);
|
||||||
lcd_e_port_low();
|
lcd_e_port_low();
|
||||||
|
|
||||||
Delay_us(40);
|
Delay_us(40);
|
||||||
|
|
||||||
//Init differs between 4-bit and 8-bit from here
|
//Init differs between 4-bit and 8-bit from here
|
||||||
#if (LCD_BITS==4)
|
#if (LCD_BITS==4)
|
||||||
lcd_db4_port_low();
|
lcd_db4_port_low();
|
||||||
@ -639,34 +646,48 @@ void lcd_init()
|
|||||||
Delay_ns(500);
|
Delay_ns(500);
|
||||||
lcd_e_port_low();
|
lcd_e_port_low();
|
||||||
Delay_us(40);
|
Delay_us(40);
|
||||||
|
|
||||||
lcd_db4_port_low();
|
lcd_db4_port_low();
|
||||||
Delay_ns(100);
|
Delay_ns(100);
|
||||||
lcd_e_port_high();
|
lcd_e_port_high();
|
||||||
Delay_ns(500);
|
Delay_ns(500);
|
||||||
lcd_e_port_low();
|
lcd_e_port_low();
|
||||||
Delay_ns(500);
|
Delay_ns(500);
|
||||||
|
|
||||||
#if (LCD_DISPLAYS==1)
|
#if (LCD_DISPLAYS==1)
|
||||||
if (LCD_DISPLAY_LINES>1)
|
|
||||||
|
if (LCD_DISPLAY_LINES > 1) {
|
||||||
lcd_db7_port_high();
|
lcd_db7_port_high();
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
switch (ActiveDisplay)
|
|
||||||
{
|
switch (ActiveDisplay) {
|
||||||
case 1 : c=LCD_DISPLAY_LINES; break;
|
case 1 :
|
||||||
case 2 : c=LCD_DISPLAY2_LINES; break;
|
c = LCD_DISPLAY_LINES;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2 :
|
||||||
|
c = LCD_DISPLAY2_LINES;
|
||||||
|
break;
|
||||||
#if (LCD_DISPLAYS>=3)
|
#if (LCD_DISPLAYS>=3)
|
||||||
case 3 : c=LCD_DISPLAY3_LINES; break;
|
|
||||||
|
case 3 :
|
||||||
|
c = LCD_DISPLAY3_LINES;
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if (LCD_DISPLAYS==4)
|
#if (LCD_DISPLAYS==4)
|
||||||
case 4 : c=LCD_DISPLAY4_LINES; break;
|
|
||||||
|
case 4 :
|
||||||
|
c = LCD_DISPLAY4_LINES;
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (c>1)
|
|
||||||
lcd_db7_port_high();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
if (c > 1) {
|
||||||
|
lcd_db7_port_high();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Delay_ns(100);
|
Delay_ns(100);
|
||||||
lcd_e_port_high();
|
lcd_e_port_high();
|
||||||
Delay_ns(500);
|
Delay_ns(500);
|
||||||
@ -674,25 +695,41 @@ void lcd_init()
|
|||||||
Delay_us(40);
|
Delay_us(40);
|
||||||
#else
|
#else
|
||||||
#if (LCD_DISPLAYS==1)
|
#if (LCD_DISPLAYS==1)
|
||||||
if (LCD_DISPLAY_LINES<2)
|
|
||||||
|
if (LCD_DISPLAY_LINES < 2) {
|
||||||
lcd_db3_port_low();
|
lcd_db3_port_low();
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
switch (ActiveDisplay)
|
|
||||||
{
|
switch (ActiveDisplay) {
|
||||||
case 1 : c=LCD_DISPLAY_LINES; break;
|
case 1 :
|
||||||
case 2 : c=LCD_DISPLAY2_LINES; break;
|
c = LCD_DISPLAY_LINES;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2 :
|
||||||
|
c = LCD_DISPLAY2_LINES;
|
||||||
|
break;
|
||||||
#if (LCD_DISPLAYS>=3)
|
#if (LCD_DISPLAYS>=3)
|
||||||
case 3 : c=LCD_DISPLAY3_LINES; break;
|
|
||||||
|
case 3 :
|
||||||
|
c = LCD_DISPLAY3_LINES;
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if (LCD_DISPLAYS==4)
|
#if (LCD_DISPLAYS==4)
|
||||||
case 4 : c=LCD_DISPLAY4_LINES; break;
|
|
||||||
|
case 4 :
|
||||||
|
c = LCD_DISPLAY4_LINES;
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (c<2)
|
|
||||||
lcd_db3_port_low();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
if (c < 2) {
|
||||||
|
lcd_db3_port_low();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
lcd_db2_port_low();
|
lcd_db2_port_low();
|
||||||
Delay_ns(100);
|
Delay_ns(100);
|
||||||
lcd_e_port_high();
|
lcd_e_port_high();
|
||||||
@ -700,16 +737,12 @@ void lcd_init()
|
|||||||
lcd_e_port_low();
|
lcd_e_port_low();
|
||||||
Delay_us(40);
|
Delay_us(40);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Display Off
|
//Display Off
|
||||||
lcd_command(_BV(LCD_DISPLAYMODE));
|
lcd_command(_BV(LCD_DISPLAYMODE));
|
||||||
|
|
||||||
//Display Clear
|
//Display Clear
|
||||||
lcd_clrscr();
|
lcd_clrscr();
|
||||||
|
|
||||||
//Entry Mode Set
|
//Entry Mode Set
|
||||||
lcd_command(_BV(LCD_ENTRY_MODE) | _BV(LCD_ENTRY_INC));
|
lcd_command(_BV(LCD_ENTRY_MODE) | _BV(LCD_ENTRY_INC));
|
||||||
|
|
||||||
//Display On
|
//Display On
|
||||||
lcd_command(_BV(LCD_DISPLAYMODE) | _BV(LCD_DISPLAYMODE_ON));
|
lcd_command(_BV(LCD_DISPLAYMODE) | _BV(LCD_DISPLAYMODE_ON));
|
||||||
}
|
}
|
||||||
@ -717,9 +750,10 @@ void lcd_init()
|
|||||||
#if (LCD_DISPLAYS>1)
|
#if (LCD_DISPLAYS>1)
|
||||||
void lcd_use_display(int ADisplay)
|
void lcd_use_display(int ADisplay)
|
||||||
{
|
{
|
||||||
if (ADisplay>=1 && ADisplay<=LCD_DISPLAYS)
|
if (ADisplay >= 1 && ADisplay <= LCD_DISPLAYS) {
|
||||||
ActiveDisplay = ADisplay;
|
ActiveDisplay = ADisplay;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
Title : HD44780 Library
|
Title : HD44780 Library
|
||||||
Author : SA Development
|
Author : SA Development
|
||||||
Version: 1.11
|
Version: 1.11
|
||||||
|
Modifications for: Arduino Mega 2560
|
||||||
|
Itead Studio Arduino 1602 LED Keypad Shield
|
||||||
|
Modified by: Silver Kits <silver.kits@eesti.ee> October 2016
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#ifndef HD44780_H
|
#ifndef HD44780_H
|
||||||
#define HD44780_H
|
#define HD44780_H
|
||||||
|
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
Title : HD44780 Library
|
||||||
|
Author : SA Development
|
||||||
|
Version: 1.11
|
||||||
|
Modifications for: Arduino Mega 2560
|
||||||
|
Itead Studio Arduino 1602 LED Keypad Shield
|
||||||
|
Modified by: Silver Kits <silver.kits@eesti.ee> October 2016
|
||||||
|
*****************************************************************************/
|
||||||
#ifndef HD44780_SETTINGS_H
|
#ifndef HD44780_SETTINGS_H
|
||||||
#define HD44780_SETTINGS_H
|
#define HD44780_SETTINGS_H
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user