diff --git a/.cproject b/.cproject
index 9d9007b..5ca759f 100644
--- a/.cproject
+++ b/.cproject
@@ -41,7 +41,7 @@
-
+
@@ -157,7 +158,7 @@
-
+
@@ -196,7 +197,7 @@
-
+
diff --git a/.gitignore b/.gitignore
index 9baa986..f240e72 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1 @@
-./Debug/*
+Debug/
diff --git a/.project b/.project
index 390e31c..7de8960 100644
--- a/.project
+++ b/.project
@@ -1,6 +1,6 @@
- cm3_led
+ nano_4k_1602_lcd
diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml
new file mode 100644
index 0000000..4a66895
--- /dev/null
+++ b/.settings/language.settings.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/USER/gpio_wrapper.h b/LCD_LIBRARY/Includes/gpio_wrapper.h
similarity index 100%
rename from USER/gpio_wrapper.h
rename to LCD_LIBRARY/Includes/gpio_wrapper.h
diff --git a/USER/lcd_hd44780.h b/LCD_LIBRARY/Includes/lcd_hd44780.h
similarity index 81%
rename from USER/lcd_hd44780.h
rename to LCD_LIBRARY/Includes/lcd_hd44780.h
index 5eb99a5..feb3ce6 100644
--- a/USER/lcd_hd44780.h
+++ b/LCD_LIBRARY/Includes/lcd_hd44780.h
@@ -2,7 +2,7 @@
* lcd_hd44780.h
*
* Created on: 22 Jan 2022
- * Author: trashcan
+ * Author: Dhia Zerrari
*/
#ifndef __LCD_HD44780_H_
@@ -11,12 +11,17 @@
#include "gw1ns4c.h"
#include
-//----Change these three lines depending on which GPIO you actually connected to your LCD
+/*---Change these three lines depending on which GPIO you actually connected to your LCD---*/
+
//D7-D4 which serves both D7-D4 then D3-D0 alternately in 4-bit mode
#define LCD_4BIT_DATA (GPIO_Pin_3 | GPIO_Pin_2 | GPIO_Pin_1 | GPIO_Pin_0)
+
+//Enable pin
#define LCD_ENABLE GPIO_Pin_5
+
+//RS pin
#define LCD_REGISTER_SEL GPIO_Pin_4
-//--------------------------------------------------------------------------------
+/*-----------------------------------------------------------------------------------------*/
// E RS D7-D4
@@ -47,7 +52,7 @@ void LCD_WriteChar(char c);
void LCD_WriteString(char *string);
void LCD_WriteByteToNibbleBus(int byte);
void LCD_GPIOInit();
-void delay_ms(__IO uint32_t delay_ms);
+void LCD_DelayMS(__IO uint32_t delay_ms);
#endif /* __LCD_HD44780_H_ */
diff --git a/USER/gpio_wrapper.c b/LCD_LIBRARY/Sources/gpio_wrapper.c
similarity index 100%
rename from USER/gpio_wrapper.c
rename to LCD_LIBRARY/Sources/gpio_wrapper.c
diff --git a/USER/lcd_hd44780.c b/LCD_LIBRARY/Sources/lcd_hd44780.c
similarity index 93%
rename from USER/lcd_hd44780.c
rename to LCD_LIBRARY/Sources/lcd_hd44780.c
index 5393e74..4dd3513 100644
--- a/USER/lcd_hd44780.c
+++ b/LCD_LIBRARY/Sources/lcd_hd44780.c
@@ -5,8 +5,6 @@
* Author: Dhia Zerrari
*/
-// RS E D4-D7
-// O4 O5 O0-O3
/* Includes ------------------------------------------------------------------*/
#include "gw1ns4c.h"
#include "lcd_hd44780.h"
@@ -59,17 +57,17 @@ void LCD_GPIOInit() {
* This reset should be followed by the rest of the init procedure (function set, entry mode etc)
* */
void LCD_Reset() {
- delay_ms(100); //wait for LCD power on if cold boot
+ LCD_DelayMS(100); //wait for LCD power on if cold boot
LCD_SetInstructionMode();
int instructionVector = 0b0011;
writeVector(LCD_4BIT_DATA, instructionVector);
LCD_NibbleTransaction();
- delay_ms(1);
+ LCD_DelayMS(1);
//reread same data (0011) as per procedure described in manual
LCD_NibbleTransaction();
- delay_ms(1);
+ LCD_DelayMS(1);
LCD_NibbleTransaction();
instructionVector = 0b0010;
@@ -136,7 +134,7 @@ void LCD_SetInstructionMode() {
* */
void LCD_NibbleTransaction() {
writeBit(LCD_ENABLE, true); //Enable LCD and start receiving nibble
- delay_ms(5);
+ LCD_DelayMS(5);
writeBit(LCD_ENABLE, false); //Disable LCD
}
@@ -160,8 +158,8 @@ void LCD_CreateCustomChar(unsigned int customCharIndex, int* glyphData) {
/**
* Sets the address for character generator RAM, the next data write will be interpreted as CG data
- * Each custom character bitmap occupies 7 addresses (5x8 mode), or 10 addresses (5x10 mode, not a typo)
- * followed by a row reserved for the cursor to show.
+ * Each custom character bitmap occupies 8 addresses (5x8 mode), or 11 addresses (5x10 mode, not a typo)
+ * The last row is shared with the cursor if it is enabled.
* */
void LCD_SetGeneratorRAMAddress(unsigned int address) {
LCD_SetInstructionMode();
@@ -186,12 +184,18 @@ void LCD_LineSelect(int line) {
LCD_SetDisplayRAMAddress(line == 0? 0x0: 0x40);
}
+/**
+ * Activate LCD printout on-screen, enable/disable cursor and cursor blink
+ * */
void LCD_DisplayEnable(bool displayON, bool cursorON, bool cursorBlinks) {
LCD_SetInstructionMode();
int instructionVector = 0b00001000 | (displayON << 2) | (cursorON << 1) | (cursorBlinks);
LCD_WriteByteToNibbleBus(instructionVector);
}
+/**
+ * Example of initializing LCD in 4-bit mode
+ * */
void LCD_Init() {
//Cycle one instruction/data transfer to avoid confusing the nibbles later on
LCD_NibbleTransaction();
@@ -240,8 +244,10 @@ void LCD_WriteByteToNibbleBus(int byte) {
LCD_NibbleTransaction(); //send B3-B0 through D7-D4
}
-//delay ms
-void delay_ms(__IO uint32_t delay_ms) {
+/**
+ * Waste CPU cycles for delay, weird name to avoid possible mixups
+ * */
+void LCD_DelayMS(__IO uint32_t delay_ms) {
for (delay_ms = (SystemCoreClock >> 13) * delay_ms; delay_ms != 0;
delay_ms--)
;
diff --git a/USER/main.c b/USER/main.c
index d2271f6..675502e 100644
--- a/USER/main.c
+++ b/USER/main.c
@@ -1,6 +1,9 @@
-// RS E D4-D7
-// O4 O5 O0-O3
-/* Includes ------------------------------------------------------------------*/
+/*
+ * Example code for showing the LCD library in action
+ * Prints a counter of how many days there have been without school, if days last 300ms that is.
+ *
+ */
+
#include "gw1ns4c.h"
#include
#include
@@ -33,19 +36,19 @@ int sadGlyph[8] = {0b10001,
int main(void) {
SystemInit(); //Initializes system
LCD_Init(); //Initializes LCD
- LCD_CreateCustomChar(0, smileyGlyph);
+ LCD_CreateCustomChar(0, smileyGlyph); //send custom character data to LCD to make a smiley at index 0
LCD_WriteString("No School Day: ");
- LCD_WriteChar(0);
- int counter = 0xA0;
+ LCD_WriteChar(0); //Write the aforementioned smiley character
+ int counter = 0;
while (true) {
- LCD_LineSelect(1);
- snprintf(message, 16, "%s #%d", " ", counter);
+ LCD_LineSelect(1); //Cursor back to beginning of second line
+ snprintf(message, 16, "%s #%d", " ", counter); //print empty space followed by count number and the hash sign
LCD_WriteString(message);
- for (int i = 0; i < 40; i++) {
+ for (int i = 0; i < 40; i++) { //shift entire display to the right until it wraps back around where it started
LCD_DisplayShift(true);
- delay_ms(1);
+ LCD_DelayMS(1);
}
- delay_ms(300);
+ LCD_DelayMS(300);
counter++;
}
}