|
@@ -1,13 +1,14 @@
|
|
|
-//-------------------------------------------------------------------------------------------------
|
|
|
-// Wyœwietlacz alfanumeryczny ze sterownikiem HD44780
|
|
|
-// Sterowanie w trybie 8-bitowym z odczytem flagi zajêtoœci
|
|
|
-// Plik : HD44780.c
|
|
|
-// Mikrokontroler : Atmel AVR
|
|
|
-// Kompilator : avr-gcc
|
|
|
-// Autor : Rados³aw Kwiecieñ
|
|
|
-// �ród³o : http://radzio.dxp.pl/hd44780/
|
|
|
-// Data : 24.03.2007
|
|
|
-//-------------------------------------------------------------------------------------------------
|
|
|
+/*-------------------------------------------------------------------------------------------------
|
|
|
+ * Wyœwietlacz alfanumeryczny ze sterownikiem HD44780
|
|
|
+ * Sterowanie w trybie 8-bitowym z odczytem flagi zajêtoœci
|
|
|
+ * Plik : HD44780.c
|
|
|
+ * Mikrokontroler : Atmel AVR
|
|
|
+ * Kompilator : avr-gcc
|
|
|
+ * Autor : Rados³aw Kwiecieñ
|
|
|
+ * �ród³o : http://radzio.dxp.pl/hd44780/
|
|
|
+ * Data : 24.03.2007
|
|
|
+ * Modified: k4be, 2022 (I2C access mode)
|
|
|
+ * ------------------------------------------------------------------------------------------------ */
|
|
|
|
|
|
#include "HD44780.h"
|
|
|
#include <avr/pgmspace.h>
|
|
@@ -20,12 +21,13 @@
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
void _LCD_Write(unsigned char dataToWrite)
|
|
|
{
|
|
|
-LCD_DATA_DIR = 0xFF;
|
|
|
+ LCD_DATA_OUTPUT();
|
|
|
|
|
|
-LCD_RW_PORT &= ~LCD_RW;
|
|
|
-LCD_E_PORT |= LCD_E;
|
|
|
-LCD_DATA_PORT = dataToWrite;
|
|
|
-LCD_E_PORT &= ~LCD_E;
|
|
|
+ expander_set_bit_no_send(LCD_RW_PORT, LCD_RW, 0);
|
|
|
+ expander_set_bit_no_send(LCD_E_PORT, LCD_E, 1);
|
|
|
+ exp_output[0] = dataToWrite;
|
|
|
+ expander_write(0);
|
|
|
+ expander_set_bit(LCD_E_PORT, LCD_E, 0);
|
|
|
}
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
//
|
|
@@ -35,16 +37,15 @@ LCD_E_PORT &= ~LCD_E;
|
|
|
|
|
|
unsigned char _LCD_Read(void)
|
|
|
{
|
|
|
-unsigned char tmp = 0;
|
|
|
+ unsigned char tmp = 0;
|
|
|
|
|
|
-LCD_DATA_DIR = 0x00;
|
|
|
+ LCD_DATA_INPUT();
|
|
|
|
|
|
-LCD_RW_PORT |= LCD_RW;
|
|
|
-LCD_E_PORT |= LCD_E;
|
|
|
-_delay_us(1); //tu zmieni³em
|
|
|
-tmp = LCD_DATA_PIN;
|
|
|
-LCD_E_PORT &= ~LCD_E;
|
|
|
-return tmp;
|
|
|
+ expander_set_bit_no_send(LCD_RW_PORT, LCD_RW, 1);
|
|
|
+ expander_set_bit(LCD_E_PORT, LCD_E, 1);
|
|
|
+ tmp = expander_read_byte(0, 0);
|
|
|
+ expander_set_bit(LCD_E_PORT, LCD_E, 0);
|
|
|
+ return tmp;
|
|
|
}
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
@@ -54,9 +55,9 @@ return tmp;
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
void LCD_WriteCommand(unsigned char commandToWrite)
|
|
|
{
|
|
|
-LCD_RS_PORT &= ~LCD_RS;
|
|
|
-_LCD_Write(commandToWrite);
|
|
|
-while(LCD_ReadStatus()&0x80);
|
|
|
+ expander_set_bit(LCD_RS_PORT, LCD_RS, 0);
|
|
|
+ _LCD_Write(commandToWrite);
|
|
|
+ while(LCD_ReadStatus()&0x80);
|
|
|
}
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
@@ -66,9 +67,9 @@ while(LCD_ReadStatus()&0x80);
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
unsigned char LCD_ReadStatus(void)
|
|
|
{
|
|
|
-LCD_RS_PORT &= ~LCD_RS;
|
|
|
-return _LCD_Read();
|
|
|
-return 0;
|
|
|
+ expander_set_bit(LCD_RS_PORT, LCD_RS, 0);
|
|
|
+ return _LCD_Read();
|
|
|
+ return 0;
|
|
|
}
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
//
|
|
@@ -77,9 +78,9 @@ return 0;
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
void LCD_WriteData(unsigned char dataToWrite)
|
|
|
{
|
|
|
-LCD_RS_PORT |= LCD_RS;
|
|
|
-_LCD_Write(dataToWrite);
|
|
|
-while(LCD_ReadStatus()&0x80);
|
|
|
+ expander_set_bit(LCD_RS_PORT, LCD_RS, 1);
|
|
|
+ _LCD_Write(dataToWrite);
|
|
|
+ while(LCD_ReadStatus()&0x80);
|
|
|
}
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
//
|
|
@@ -88,8 +89,8 @@ while(LCD_ReadStatus()&0x80);
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
unsigned char LCD_ReadData(void)
|
|
|
{
|
|
|
-LCD_RS_PORT |= LCD_RS;
|
|
|
-return _LCD_Read();
|
|
|
+ expander_set_bit(LCD_RS_PORT, LCD_RS, 1);
|
|
|
+ return _LCD_Read();
|
|
|
}
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
//
|
|
@@ -98,15 +99,15 @@ return _LCD_Read();
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
void LCD_WriteText(const char * text)
|
|
|
{
|
|
|
-while(*text)
|
|
|
- LCD_WriteData(*text++);
|
|
|
+ while(*text)
|
|
|
+ LCD_WriteData(*text++);
|
|
|
}
|
|
|
|
|
|
void LCD_WriteTextP(const char *text)
|
|
|
{
|
|
|
-char a;
|
|
|
-while((a = pgm_read_byte(text++)))
|
|
|
- LCD_WriteData(a);
|
|
|
+ char a;
|
|
|
+ while((a = pgm_read_byte(text++)))
|
|
|
+ LCD_WriteData(a);
|
|
|
}
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
//
|
|
@@ -115,7 +116,7 @@ while((a = pgm_read_byte(text++)))
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
void LCD_GoTo(unsigned char x, unsigned char y)
|
|
|
{
|
|
|
-LCD_WriteCommand(HD44780_DDRAM_SET | (x + (0x40 * y)));
|
|
|
+ LCD_WriteCommand(HD44780_DDRAM_SET | (x + (0x40 * y)));
|
|
|
}
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
//
|
|
@@ -124,8 +125,8 @@ LCD_WriteCommand(HD44780_DDRAM_SET | (x + (0x40 * y)));
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
void LCD_Clear(void)
|
|
|
{
|
|
|
-LCD_WriteCommand(HD44780_CLEAR);
|
|
|
-_delay_ms(2);
|
|
|
+ LCD_WriteCommand(HD44780_CLEAR);
|
|
|
+ _delay_ms(2);
|
|
|
}
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
//
|
|
@@ -134,8 +135,8 @@ _delay_ms(2);
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
void LCD_Home(void)
|
|
|
{
|
|
|
-LCD_WriteCommand(HD44780_HOME);
|
|
|
-_delay_ms(2);
|
|
|
+ LCD_WriteCommand(HD44780_HOME);
|
|
|
+ _delay_ms(2);
|
|
|
}
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
//
|
|
@@ -144,29 +145,28 @@ _delay_ms(2);
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
void LCD_Initalize(void)
|
|
|
{
|
|
|
-unsigned char i;
|
|
|
-LCD_DATA_DIR = 0xFF;
|
|
|
-LCD_E_DIR |= LCD_E; //
|
|
|
-LCD_RS_DIR |= LCD_RS; //
|
|
|
-LCD_RW_DIR |= LCD_RW;
|
|
|
-LCD_RS_PORT &= ~LCD_RS; // wyzerowanie linii RS
|
|
|
-LCD_E_PORT &= ~LCD_E; // wyzerowanie linii E
|
|
|
-LCD_RW_PORT &= ~LCD_RW;
|
|
|
-_delay_ms(100); // oczekiwanie na ustalibizowanie siê napiecia zasilajacego
|
|
|
+ unsigned char i;
|
|
|
+ LCD_DATA_OUTPUT();
|
|
|
+
|
|
|
+ expander_set_bit_no_send(LCD_RS_PORT, LCD_RS, 0); // wyzerowanie linii RS
|
|
|
+ expander_set_bit_no_send(LCD_E_PORT, LCD_E, 0); // wyzerowanie linii E
|
|
|
+ expander_set_bit(LCD_RW_PORT, LCD_RW, 0);
|
|
|
+ _delay_ms(100); // oczekiwanie na ustalibizowanie siê napiecia zasilajacego
|
|
|
|
|
|
-for(i = 0; i < 3; i++) // trzykrotne powtórzenie bloku instrukcji
|
|
|
- {
|
|
|
- LCD_E_PORT |= LCD_E;
|
|
|
- LCD_DATA_PORT = 0x3F;
|
|
|
- LCD_E_PORT &= ~LCD_E;
|
|
|
- _delay_ms(5); // czekaj 5ms
|
|
|
- }
|
|
|
+ exp_output[0] = 0x3F;
|
|
|
+ expander_write(0);
|
|
|
+ for(i = 0; i < 3; i++) // trzykrotne powtórzenie bloku instrukcji
|
|
|
+ {
|
|
|
+ expander_set_bit(LCD_E, LCD_E, 1);
|
|
|
+ expander_set_bit(LCD_E, LCD_E, 0);
|
|
|
+ _delay_ms(5); // czekaj 5ms
|
|
|
+ }
|
|
|
|
|
|
-LCD_WriteCommand(HD44780_FUNCTION_SET | HD44780_FONT5x7 | HD44780_TWO_LINE | HD44780_8_BIT); // interfejs 4-bity, 2-linie, znak 5x7
|
|
|
-LCD_WriteCommand(HD44780_DISPLAY_ONOFF | HD44780_DISPLAY_OFF); // wy³¹czenie wyswietlacza
|
|
|
-//LCD_WriteCommand(HD44780_CLEAR); // czyszczenie zawartosæi pamieci DDRAM
|
|
|
-LCD_WriteCommand(HD44780_ENTRY_MODE | HD44780_EM_SHIFT_CURSOR | HD44780_EM_INCREMENT);// inkrementaja adresu i przesuwanie kursora
|
|
|
-LCD_WriteCommand(HD44780_DISPLAY_ONOFF | HD44780_DISPLAY_ON | HD44780_CURSOR_OFF | HD44780_CURSOR_NOBLINK); // w³¹cz LCD, bez kursora i mrugania
|
|
|
+ LCD_WriteCommand(HD44780_FUNCTION_SET | HD44780_FONT5x7 | HD44780_TWO_LINE | HD44780_8_BIT); // interfejs 4-bity, 2-linie, znak 5x7
|
|
|
+ LCD_WriteCommand(HD44780_DISPLAY_ONOFF | HD44780_DISPLAY_OFF); // wy³¹czenie wyswietlacza
|
|
|
+ //LCD_WriteCommand(HD44780_CLEAR); // czyszczenie zawartosæi pamieci DDRAM
|
|
|
+ LCD_WriteCommand(HD44780_ENTRY_MODE | HD44780_EM_SHIFT_CURSOR | HD44780_EM_INCREMENT);// inkrementaja adresu i przesuwanie kursora
|
|
|
+ LCD_WriteCommand(HD44780_DISPLAY_ONOFF | HD44780_DISPLAY_ON | HD44780_CURSOR_OFF | HD44780_CURSOR_NOBLINK); // w³¹cz LCD, bez kursora i mrugania
|
|
|
}
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------
|