Skip to content

Commit a96ec93

Browse files
committed
Impeoved some functions implementations in CLCD_program.c. Addes a test file, CLCD_test.c
1 parent c405966 commit a96ec93

File tree

6 files changed

+79
-28
lines changed

6 files changed

+79
-28
lines changed

HAL/CLCD/CLCD_config.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/*****************************************************************************
1+
/**
22
* @file CLCD_config.h
33
* @author Abdulrahman Aboghanima ([email protected])
44
* @brief User configuration for the CLCD
55
* @version 0.1
66
* @date 2022-01-26
7-
*
87
* @copyright Copyright (c) 2022
98
*
10-
****************************************************************************/
9+
*/
10+
1111
/** @addtogroup HAL_drivers
1212
* @{ @addtogroup CLCD_drivers
1313
* @{ @addtogroup CLCD_config

HAL/CLCD/CLCD_output.gif

105 KB
Loading

HAL/CLCD/CLCD_private.h

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1+
/**
2+
*
3+
* @file CLCD_private.h
4+
* @brief Contains private Macros to then `CLCD_Module`
5+
* @author Abdulrahman Aboghanima
6+
* @date Fri Mar 11 17:58:49 2022
7+
* @copyright Copyright (c) 2022
8+
* @version 0.1
9+
*
10+
*/
11+
112
#ifndef _CLCD_PRIVATE_H_
213
#define _CLCD_PRIVATE_H_
314

415

5-
6-
716
/**
8-
* @brief USE 4-bit mode LCD
9-
*
17+
* @brief USE 4-bit mode LCD
1018
*/
1119
#define MODE_4_BIT 1
1220

1321
/**
1422
* @brief USE 8-bit mode LCD
15-
*
1623
*/
1724
#define MODE_8_BIT 2
1825

HAL/CLCD/CLCD_program.c

+9-20
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
* @file CLCD_program.c
33
* @author Abdulrahman Aboghanima ([email protected])
44
* @brief The implementations of the CLCD_drivers
5-
* @version 0.1
5+
* @version 0.2
66
* @copyright Copyright (c) 2022
77
*/
88
#include "../../LIB/STD_TYPES.h"
99
#include "../../LIB/BIT_MATH.h"
10-
#include "CLCD_interface.h"
11-
#include "CLCD_config.h"
1210
#include "CLCD_private.h"
11+
#include "CLCD_config.h"
12+
#include "CLCD_interface.h"
1313
#include <util/delay.h>
14+
1415
static inline void setEnableForSomeTime()
1516
{
1617
DIO_SetPinValue(CLCD_CTRL_PORT, CLCD_EN_PIN, DIO_PIN_HIGH);
@@ -59,7 +60,7 @@ static inline void CLCD_SendData(const uint8_t Data)
5960
}
6061
void CLCD_Clear(void)
6162
{
62-
CLCD_SendCommand(0b00000001);
63+
CLCD_SendCommand(0b00000010);
6364
}
6465
void CLCD_Blink(void)
6566
{
@@ -105,31 +106,19 @@ void CLCD_Init(void)
105106

106107
void CLCD_SendString(const char *string)
107108
{
108-
uint8_t i=0;
109-
while(string[i]!='\0')
110-
CLCD_SendData(string[i++]);
111-
109+
while(*string!='\0') CLCD_SendData(*string++);
112110
}
113111

114112
void CLCD_GoTOXY(const uint8_t XPos, const uint8_t YPos)
115113
{
116-
uint8_t localAddress=0;
117-
if(XPos==0){
118-
/* location is in the first line */
119-
localAddress=YPos;
120-
}
121-
else if(XPos==1){
122-
/* location is in the second line */
123-
localAddress=YPos+0x40;
124-
}
125114
/* Set bit number 7 for Setting DDRAM Address command then send the command */
126-
CLCD_SendCommand(0x80|localAddress);
115+
/* If the XPos==0, it's the first line, else it is the second*/
116+
CLCD_SendCommand(0x80|( XPos ? YPos+0x40 : YPos));
127117
}
128118

129119
void CLCD_SendSpecialChar(const uint8_t *charArray, const uint8_t charIndex, const uint8_t XPos, const uint8_t YPos)
130120
{
131-
/* Command for writing on the CGRAM*/
132-
CLCD_SendCommand(charIndex*8 | 0x40);
121+
CLCD_SendCommand(charIndex*8 | 0x40); /* Command for writing on the CGRAM*/
133122

134123
/*
135124
* The Data now is going to be sent in the CGRAM

HAL/CLCD/CLCD_test.c

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* main.c
3+
*
4+
* Created on: Aug 21, 2021
5+
* Author: Abdulrahman Aboghanima
6+
*/
7+
#include "../../LIB/STD_TYPES.h"
8+
#include "../../HAL/CLCD/CLCD_interface.h"
9+
#include "../../MCAL/DIO/DIO_interface.h"
10+
#include <util/delay.h>
11+
12+
int main(void){
13+
14+
const uint8_t customChar[][8] = {
15+
{0x00, 0x00, 0x07, 0x14, 0x1F, 0x00, 0x10, 0x00},
16+
{0x00, 0x00, 0x04, 0x04, 0x1F, 0x00, 0x00, 0x00},
17+
{0x06, 0x06, 0x06, 0x06, 0x1E, 0x00, 0x00, 0x00},
18+
{0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x04, 0x08},
19+
{0x00, 0x0C, 0x02, 0x01, 0x1F, 0x00, 0x00, 0x00},
20+
{0x00, 0x00, 0x0E, 0x0A, 0x1F, 0x00, 0x00, 0x00},
21+
{0x00, 0x00, 0x04, 0x11, 0x11, 0x11, 0x0E, 0x00}
22+
};
23+
24+
CLCD_Init();
25+
26+
for(uint8_t i=0; i<7; i++)
27+
CLCD_SendSpecialChar(customChar[i], i, 0, 12-i);
28+
29+
CLCD_GoTOXY(1, 6);
30+
CLCD_SendString(utoa(1234, 10));
31+
32+
while(1){
33+
34+
CLCD_Init();
35+
CLCD_GoTOXY(0, 0);
36+
CLCD_SendString("Welcome to Repo");
37+
_delay_ms(100);
38+
CLCD_Init();
39+
CLCD_GoTOXY(1, 1);
40+
CLCD_SendString("Welcome to Repo");
41+
_delay_ms(100);
42+
43+
}
44+
45+
return 0;
46+
47+
}

HAL/CLCD/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# CLCD, Character Liquid Crystal Display, module.
2+
3+
A driver with simple functions to interface with the *LCD*.
4+
5+
(**NOTE**: *It has been tested on the 16x2 display only.*)
6+
7+
8+
![Simulation of the CLCD](./CLCD_output.gif)

0 commit comments

Comments
 (0)