-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLCD_Program.c
110 lines (88 loc) · 2.64 KB
/
LCD_Program.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* LCD_Program.c
*
* Created: 12/20/2023 5:40:07 PM
* Author: mosta
*/
#define F_CPU 16000000UL
#include <util/delay.h>
#include "STBD_TYPES.h"
#include <stdio.h>
#include "DIO_interface.h"
#include "LCD_conifg.h"
#include "LCD_Interface.h"
void LCD_voidInit(void)
{
DIO_voidSetPinDir(LCD_U8_DATA_PORT, LCD_U8_D4 ,DIO_U8_OUTPUT);
DIO_voidSetPinDir(LCD_U8_DATA_PORT, LCD_U8_D5 ,DIO_U8_OUTPUT);
DIO_voidSetPinDir(LCD_U8_DATA_PORT, LCD_U8_D6 ,DIO_U8_OUTPUT);
DIO_voidSetPinDir(LCD_U8_DATA_PORT, LCD_U8_D7 ,DIO_U8_OUTPUT);
DIO_voidSetPinDir(LCD_U8_CONTROL_PORT, LCD_U8_RS ,DIO_U8_OUTPUT);
DIO_voidSetPinDir(LCD_U8_CONTROL_PORT, LCD_U8_RW ,DIO_U8_OUTPUT);
DIO_voidSetPinDir(LCD_U8_CONTROL_PORT, LCD_U8_EN ,DIO_U8_OUTPUT);
_delay_ms(35);
LCD_voidSendCommand(Return_Home);
_delay_ms(2);
LCD_voidSendCommand(bit4_2line_5x8font);
_delay_ms(2);
LCD_voidSendCommand(displayOn_cursorON);
_delay_ms(2);
LCD_voidSendCommand(Entry_Mode);
_delay_ms(2);
LCD_voidSendCommand(Clear_Display);
_delay_ms(2);
}
void LCD_voidSendData(u8 LCD_u8_Data)
{
DIO_voidSetPinVal(LCD_U8_CONTROL_PORT, LCD_U8_RS ,DIO_U8_HIGH);
DIO_voidSetPinVal(LCD_U8_CONTROL_PORT, LCD_U8_RW ,DIO_U8_LOW);
DIO_voidSetPortValue(LCD_U8_DATA_PORT , LCD_u8_Data & 0b11110000);
DIO_voidSetPinVal(LCD_U8_CONTROL_PORT, LCD_U8_EN ,DIO_U8_HIGH);
_delay_ms(1);
DIO_voidSetPinVal(LCD_U8_CONTROL_PORT, LCD_U8_EN ,DIO_U8_LOW);
_delay_ms(1);
DIO_voidSetPortValue(LCD_U8_DATA_PORT , (LCD_u8_Data << 4) & 0b11110000);
DIO_voidSetPinVal(LCD_U8_CONTROL_PORT, LCD_U8_EN ,DIO_U8_HIGH);
_delay_ms(1);
DIO_voidSetPinVal(LCD_U8_CONTROL_PORT, LCD_U8_EN ,DIO_U8_LOW);
_delay_ms(1);
}
void LCD_voidSendCommand(u8 LCD_u8_Command)
{
DIO_voidSetPinVal(LCD_U8_CONTROL_PORT, LCD_U8_RS ,DIO_U8_LOW);
DIO_voidSetPinVal(LCD_U8_CONTROL_PORT, LCD_U8_RW ,DIO_U8_LOW);
DIO_voidSetPortValue(LCD_U8_DATA_PORT , LCD_u8_Command & 0b11110000);
DIO_voidSetPinVal(LCD_U8_CONTROL_PORT, LCD_U8_EN ,DIO_U8_HIGH);
_delay_ms(1);
DIO_voidSetPinVal(LCD_U8_CONTROL_PORT, LCD_U8_EN ,DIO_U8_LOW);
_delay_ms(1);
DIO_voidSetPortValue(LCD_U8_DATA_PORT , (LCD_u8_Command << 4) & 0b11110000);
DIO_voidSetPinVal(LCD_U8_CONTROL_PORT, LCD_U8_EN ,DIO_U8_HIGH);
_delay_ms(1);
DIO_voidSetPinVal(LCD_U8_CONTROL_PORT, LCD_U8_EN ,DIO_U8_LOW);
_delay_ms(1);
}
void LCD_voidSendString(s8 String[])
{
u8 index = 0;
while(String[index] != '\0' )
{
LCD_voidSendData(String[index]);
index++;
}
}
void LCD_Int_to_String(u16 input)
{
s8 str[5];
sprintf(str,"%u",input);
LCD_voidSendString(str);
}
void LCD_gotoxy(u8 x, u8 y)
{
u8 address;
if (y == 0)
address = 0x80 + x;
else
address = 0xC0 + x;
LCD_voidSendCommand(address);
}