Skip to content

Commit

Permalink
Merge pull request #6 from petrmadecki/main
Browse files Browse the repository at this point in the history
Přidání podpory pro vlastní znak.
  • Loading branch information
petrmadecki authored Apr 13, 2023
2 parents 3784d27 + 953302b commit 170cfca
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 12 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Změny a vývoj projektu

## [next]:
## [Unreleased]:

## [1.1.5] - 2023-04-13

### Added:
- (#5) Přidání podpory pro vlastní znaky.


## [1.0.5] - 2023-03-31

Expand Down
38 changes: 31 additions & 7 deletions arm.uvoptx
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,18 @@
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>.\examples\example_04-LCD_02-customChar.c</PathWithFileName>
<FilenameWithoutPath>example_04-LCD_02-customChar.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>8</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>.\examples\example_05-KPAD_01.c</PathWithFileName>
<FilenameWithoutPath>example_05-KPAD_01.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
Expand All @@ -344,7 +356,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>8</FileNumber>
<FileNumber>9</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
Expand All @@ -356,7 +368,7 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>9</FileNumber>
<FileNumber>10</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
Expand All @@ -368,7 +380,19 @@
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>10</FileNumber>
<FileNumber>11</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>.\include\LCD_customChar_table.h</PathWithFileName>
<FilenameWithoutPath>LCD_customChar_table.h</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>12</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
Expand All @@ -388,7 +412,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>3</GroupNumber>
<FileNumber>11</FileNumber>
<FileNumber>13</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
Expand All @@ -400,7 +424,7 @@
</File>
<File>
<GroupNumber>3</GroupNumber>
<FileNumber>12</FileNumber>
<FileNumber>14</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
Expand All @@ -420,7 +444,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>13</FileNumber>
<FileNumber>15</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
Expand All @@ -432,7 +456,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>14</FileNumber>
<FileNumber>16</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
Expand Down
57 changes: 57 additions & 0 deletions arm.uvprojx
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,58 @@
</FileArmAds>
</FileOption>
</File>
<File>
<FileName>example_04-LCD_02-customChar.c</FileName>
<FileType>1</FileType>
<FilePath>.\examples\example_04-LCD_02-customChar.c</FilePath>
<FileOption>
<CommonProperty>
<UseCPPCompiler>2</UseCPPCompiler>
<RVCTCodeConst>0</RVCTCodeConst>
<RVCTZI>0</RVCTZI>
<RVCTOtherData>0</RVCTOtherData>
<ModuleSelection>0</ModuleSelection>
<IncludeInBuild>0</IncludeInBuild>
<AlwaysBuild>2</AlwaysBuild>
<GenerateAssemblyFile>2</GenerateAssemblyFile>
<AssembleAssemblyFile>2</AssembleAssemblyFile>
<PublicsOnly>2</PublicsOnly>
<StopOnExitCode>11</StopOnExitCode>
<CustomArgument></CustomArgument>
<IncludeLibraryModules></IncludeLibraryModules>
<ComprImg>1</ComprImg>
</CommonProperty>
<FileArmAds>
<Cads>
<interw>2</interw>
<Optim>0</Optim>
<oTime>2</oTime>
<SplitLS>2</SplitLS>
<OneElfS>2</OneElfS>
<Strict>2</Strict>
<EnumInt>2</EnumInt>
<PlainCh>2</PlainCh>
<Ropi>2</Ropi>
<Rwpi>2</Rwpi>
<wLevel>2</wLevel>
<uThumb>2</uThumb>
<uSurpInc>2</uSurpInc>
<uC99>2</uC99>
<useXO>2</useXO>
<v6Lang>0</v6Lang>
<v6LangP>0</v6LangP>
<vShortEn>2</vShortEn>
<vShortWch>2</vShortWch>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath></IncludePath>
</VariousControls>
</Cads>
</FileArmAds>
</FileOption>
</File>
<File>
<FileName>example_05-KPAD_01.c</FileName>
<FileType>1</FileType>
Expand Down Expand Up @@ -818,6 +870,11 @@
<FileType>5</FileType>
<FilePath>.\include\LCD.h</FilePath>
</File>
<File>
<FileName>LCD_customChar_table.h</FileName>
<FileType>5</FileType>
<FilePath>.\include\LCD_customChar_table.h</FilePath>
</File>
<File>
<FileName>KPAD.h</FileName>
<FileType>5</FileType>
Expand Down
4 changes: 2 additions & 2 deletions examples/example_04-LCD_01.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int main() {

while(1) {
LCD_set(LCD_CUR_ON); // Zapnuti kurzoru.
delay(STEP);
delay(STEP); // Pozdrzeni programu.

LCD_set(LCD_CUR_BLINK); // Zapnuti blikani kurzoru.
delay(STEP*2);
Expand All @@ -55,7 +55,7 @@ int main() {
LCD_print("Hello"); // Vypis retezce.
delay(STEP);

LCD_setCursor(0, 1); // Nastaveni pozice kurzoru.
LCD_setCursor(0, 1); // Nastaveni pozice kurzoru.

LCD_print("World!"); // Vypis retezce.
delay(STEP);
Expand Down
44 changes: 44 additions & 0 deletions examples/example_04-LCD_02-customChar.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
*************************************************************************************************
* @file example_04-LCD_02-customChar.c
* @author SPSE Havirov
* @version 1.0.0
* @date 11-April-2023 [v0.1]
* @history Viz CHANGELOG.md
* @brief Testovaci program pro zobrazeni vlastniho znaku na LCD s radicem HD44780.
*
*************************************************************************************************
* @attention
*
* Pripojeni LCD viz driver "LCD.h".
*
*************************************************************************************************
* @copyright Copyright SPSE Havirov (c) 2023 *
***********************************************
*/

#include "stm32f4xx.h" // Device header

#define STEP 500 // Krok v ms pro pozdrzeni programu.
#define CLK_DIV 1000 // Hodnota pro upravu CLK, viz hl. popisek v driveru pro praci s CLK.

#define LCD_COLS 8 // Pocet sloupcu pouziteho LCD.
#define LCD_ROWS 2 // Pocet radku pouziteho LCD.

#include "chrono.h" // Pripojeni driveru pro praci s CLK.
#include "LCD.h" // Pripojeni driveru pro praci s LCD.

#include "LCD_customChar_table.h" // Pripojeni tabulky s vlastnimi znaky.

int main() {
SystemCoreClockUpdate(); // Do SystemCoreClock se nahraje frekvence jadra, viz hl. popisek v driveru pro praci s CLK.
SysTick_Config(SystemCoreClock / CLK_DIV); // Konfigurace SysTick timeru, viz hl. popisek v driveru pro praci s CLK.

LCD_setup(); // Pocatecni nastaveni LCD, nutne pro dalsi praci s LCD.

LCD_customChar_write(0, batteryFull); // Ulozeni noveho znaku na zadanou pozici do CGRAM.

LCD_customChar_read(0); // Zobrazeni vlastniho znaku ze zadane pozice v pameti.

return 0; // Tento krok nebude nikdy vykonan z duvodu pouziti nekonecne smycky vyse (viz varovani pri kompilaci).
}
65 changes: 63 additions & 2 deletions include/LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void LCD_write_nibble(uint16_t nibble){
*
*/
void LCD_set(uint8_t cmd) {
LCD_busy(); // Casova prodleva pro zpracovani ridicich prikazu.
LCD_busy(); // Casova prodleva pro zpracovani ridicich prikazu.

GPIOE->BSRR = (1UL << (3+16)); // RS=0
GPIOE->BSRR = (1UL << (4+16)); // R/W=0
Expand Down Expand Up @@ -191,14 +191,75 @@ void LCD_setCursor(uint8_t col, uint8_t row) {
}
}

/**
* @brief Funkce pro zapis vlastniho znaku do CGRAM.
*
* @param position Pozice na kterou bude ulozen vlastni znak.
* customChar Vlastni znak.
*
*/
void LCD_customChar_write(uint8_t position, uint8_t *customChar) {
uint8_t i;

if (position < 8) {
GPIOE->BSRR = (1UL << 3); // RS=1

LCD_set(0x40 | (position << 3)); // Presun do pameti CGRAM na zadanou pozici.
// 0x40 = 0. pozice v CGRAM address
// 0x48 = 1. pozice v CGRAM address
// 0x50 = 2. pozice v CGRAM address
// 0x58 = 3. pozice v CGRAM address
// 0x60 = 4. pozice v CGRAM address
// 0x68 = 5. pozice v CGRAM address
// 0x70 = 6. pozice v CGRAM address
// 0x78 = 7. pozice v CGRAM address

for (i = 0; i < 8; i++) {
LCD_busy(); // Casova prodleva pro zpracovani ridicich prikazu.

GPIOE->BSRR = (1UL << 3); // RS=1
GPIOE->BSRR = (1UL << (4+16)); // R/W=0

LCD_write_nibble(customChar[i] >> 4); // Poslani 4 hornich bitu na zapis
LCD_write_nibble(customChar[i]); // Poslani 4 dolnich bitu na zapis

delay(1); // 1ms
}

LCD_set(0x80); // Navrat do pameti DDRAM.
}
}

/**
* @brief Funkce pro zobrazeni vlastniho znaku z CGRAM.
*
* @param position Hodnota pozice znaku v CGRAM.
*
*/
void LCD_customChar_read(uint8_t position) {
if (position < 8) {
uint8_t cmd = position;

LCD_busy(); // Casova prodleva pro zpracovani ridicich prikazu.

GPIOE->BSRR = (1UL << 3); // RS=1
GPIOE->BSRR = (1UL << 4); // R/W=1

LCD_write_nibble(cmd >> 4); // Poslani 4 hornich bitu na zapis
LCD_write_nibble(cmd); // Poslani 4 dolnich bitu na zapis

delay(1); // 1ms
}
}

/**
* @brief Funkce pro vypis 1 znaku na LCD.
*
* @param data Kod pro vypisovany znak, pripadne konkretni znak.
*
*/
void LCD_put(uint8_t data) {
LCD_busy(); // Casova prodleva pro zpracovani ridicich prikazu.
LCD_busy(); // Casova prodleva pro zpracovani ridicich prikazu.

GPIOE->BSRR = (1UL << 3); // RS=1
GPIOE->BSRR = (1UL << (4+16)); // R/W=0
Expand Down
55 changes: 55 additions & 0 deletions include/LCD_customChar_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
*************************************************************************************************
* @file LCD_customChar_table.h
* @author SPSE Havirov
* @version 1.0.0
* @date 11-April-2023 [v0.1]
* @history Viz CHANGELOG.md
* @brief Definovani vlastnich znaku pro LCD s radicem HD44780.
*
*************************************************************************************************
* @attention
*
* Pro generovani vlastnich znaku a jejich hexa kodu mozno vyuzit napriklad:
* https://maxpromer.github.io/LCD-Character-Creator/
*
*************************************************************************************************
* @copyright Copyright SPSE Havirov (c) 2023 *
***********************************************
*/

uint8_t fullChar[] =
{
0x1F, // xxx 11111
0x1F, // xxx 11111
0x1F, // xxx 11111
0x1F, // xxx 11111
0x1F, // xxx 11111
0x1F, // xxx 11111
0x1F, // xxx 11111
0x1F // xxx 11111
};

uint8_t emptyChar[] =
{
0x00, // xxx 00000
0x00, // xxx 00000
0x00, // xxx 00000
0x00, // xxx 00000
0x00, // xxx 00000
0x00, // xxx 00000
0x00, // xxx 00000
0x00, // xxx 00000
};

uint8_t batteryFull[] =
{
0x0E, // xxx 01110
0x1F, // xxx 11111
0x1F, // xxx 11111
0x1F, // xxx 11111
0x1F, // xxx 11111
0x1F, // xxx 11111
0x1F, // xxx 11111
0x1F // xxx 11111
};

0 comments on commit 170cfca

Please sign in to comment.