Skip to content

Commit

Permalink
Moved library files to their own folder, fixed Eclipse project name s…
Browse files Browse the repository at this point in the history
…howing up wrong, added comments
  • Loading branch information
verilog-indeed committed Jan 28, 2022
1 parent 570932e commit 7ab9491
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 30 deletions.
7 changes: 4 additions & 3 deletions .cproject
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.addtools.printsize.270767906" name="Print size" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.addtools.printsize" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.id.1067738656" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.id" useByScannerDiscovery="false" value="1287942917" valueType="string"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="ilg.gnuarmeclipse.managedbuild.cross.targetPlatform.381837967" isAbstract="false" osList="all" superClass="ilg.gnuarmeclipse.managedbuild.cross.targetPlatform"/>
<builder buildPath="${workspace_loc:/cm3_led}/Debug" id="ilg.gnuarmeclipse.managedbuild.cross.builder.709403317" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="ilg.gnuarmeclipse.managedbuild.cross.builder"/>
<builder buildPath="${workspace_loc:/nano_4k_1602_lcd}/Debug" id="ilg.gnuarmeclipse.managedbuild.cross.builder.709403317" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="ilg.gnuarmeclipse.managedbuild.cross.builder"/>
<tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler.1070187887" name="Cross ARM GNU Assembler" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler">
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.usepreprocessor.979684167" name="Use preprocessor" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.usepreprocessor" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.defs.730269158" name="Defined symbols (-D)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.defs" useByScannerDiscovery="false" valueType="definedSymbols">
Expand All @@ -55,6 +55,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/PERIPHERAL/Includes}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/SYSTEM}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/USER}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/LCD_LIBRARY/Includes}&quot;"/>
</option>
<inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.input.520716099" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.input"/>
</tool>
Expand Down Expand Up @@ -157,7 +158,7 @@
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.addtools.createflash.304134769" name="Create flash image" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.addtools.createflash" value="true" valueType="boolean"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.addtools.printsize.312527454" name="Print size" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.addtools.printsize" value="true" valueType="boolean"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="ilg.gnuarmeclipse.managedbuild.cross.targetPlatform.1839952297" isAbstract="false" osList="all" superClass="ilg.gnuarmeclipse.managedbuild.cross.targetPlatform"/>
<builder buildPath="${workspace_loc:/cm3_led}/Release" id="ilg.gnuarmeclipse.managedbuild.cross.builder.585223164" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="ilg.gnuarmeclipse.managedbuild.cross.builder"/>
<builder buildPath="${workspace_loc:/nano_4k_1602_lcd}/Release" id="ilg.gnuarmeclipse.managedbuild.cross.builder.585223164" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="ilg.gnuarmeclipse.managedbuild.cross.builder"/>
<tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler.1055752618" name="Cross ARM GNU Assembler" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler">
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.usepreprocessor.1169123101" name="Use preprocessor" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.usepreprocessor" value="true" valueType="boolean"/>
<inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler.input.2095620982" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler.input"/>
Expand Down Expand Up @@ -196,7 +197,7 @@
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="cm3_led.ilg.gnuarmeclipse.managedbuild.cross.target.elf.1265870973" name="Executable" projectType="ilg.gnuarmeclipse.managedbuild.cross.target.elf"/>
<project id="nano_4k_1602_lcd.ilg.gnuarmeclipse.managedbuild.cross.target.elf.1265870973" name="Executable" projectType="ilg.gnuarmeclipse.managedbuild.cross.target.elf"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
./Debug/*
Debug/
2 changes: 1 addition & 1 deletion .project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>cm3_led</name>
<name>nano_4k_1602_lcd</name>
<comment></comment>
<projects>
</projects>
Expand Down
25 changes: 25 additions & 0 deletions .settings/language.settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1637121516" name="Debug">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="380660608850552377" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.release.308824391" name="Release">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="357097478580585823" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
</project>
File renamed without changes.
13 changes: 9 additions & 4 deletions USER/lcd_hd44780.h → LCD_LIBRARY/Includes/lcd_hd44780.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* lcd_hd44780.h
*
* Created on: 22 Jan 2022
* Author: trashcan
* Author: Dhia Zerrari
*/

#ifndef __LCD_HD44780_H_
Expand All @@ -11,12 +11,17 @@
#include "gw1ns4c.h"
#include <stdbool.h>

//----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
Expand Down Expand Up @@ -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_ */
File renamed without changes.
26 changes: 16 additions & 10 deletions USER/lcd_hd44780.c → LCD_LIBRARY/Sources/lcd_hd44780.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* Author: Dhia Zerrari
*/

// RS E D4-D7
// O4 O5 O0-O3
/* Includes ------------------------------------------------------------------*/
#include "gw1ns4c.h"
#include "lcd_hd44780.h"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}

Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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--)
;
Expand Down
25 changes: 14 additions & 11 deletions USER/main.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <stdbool.h>
Expand Down Expand Up @@ -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++;
}
}
Expand Down

0 comments on commit 7ab9491

Please sign in to comment.