-
Notifications
You must be signed in to change notification settings - Fork 0
/
LCD.c
137 lines (112 loc) · 2.52 KB
/
LCD.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* =================================================================
Filename: LCD.c
Author: Corey Davyduke
Creation date: 2011-11-28
Last modified date: 2011-11-29
Description: This file contains the source code to talk to
the LCD display.
=================================================================
*/
/* The LCD I/O registers are represented by a volatile array.
Address is fixed at link time. For this particular example,
the _gdm_lcd_*** addresses are defined in the `memory.x' file. */
extern volatile unsigned char _gdm_lcd_cmd;
extern volatile unsigned char _gdm_lcd_data;
int main ()
{
LCD_Init();
LCD_WriteMessage("Hello, world!");
return 0;
}
void LCD_Init()
{
LCD_DisplayFunction();
LCD_DisplayOn_CursorAndBlinkOn();
LCD_CursorIncrement_ShiftOff();
LCD_Clear();
}
// Clear display, cursor to home
void LCD_Clear()
{
LCD_Command(0x01);
}
void LCD_CursorHome()
{
LCD_Command(0x02);
}
void LCD_CursorDecrement_ShiftOff()
{
LCD_Command(0x04);
}
void LCD_CursorDecrement_ShiftOn()
{
LCD_Command(0x05);
}
void LCD_CursorIncrement_ShiftOff()
{
LCD_Command(0x06);
}
void LCD_CursorIncrement_ShiftOn()
{
LCD_Command(0x07);
}
// Display, cursor and blink off
void LCD_DisplayOff()
{
LCD_Command(0x08);
}
void LCD_DisplayOn_CursorAndBlinkOff()
{
LCD_Command(0x0c);
}
void LCD_DisplayOn_CursorOnBlinkOff()
{
LCD_Command(0x0e);
}
void LCD_DisplayOn_CursorAndBlinkOn()
{
LCD_Command(0x0f);
}
void LCD_Cursor_ShiftLeft()
{
LCD_Command(0x10);
}
void LCD_Cursor_ShiftRight()
{
LCD_Command(0x14);
}
void LCD_Display_ShiftLeft()
{
LCD_Command(0x18);
}
void LCD_Display_ShiftRight()
{
LCD_Command(0x1c);
}
// Display Function (default 2x40 size)
void LCD_DisplayFunction()
{
LCD_Command(0x3c);
}
// Write a string to the LCD display
void LCD_WriteMessage(char *szMessage)
{
while(*szMessage) LCD_Write(*szMessage++);
}
// Issue a command to the LCD command register
void LCD_Command(unsigned char cval)
{
LCD_Busy(); // Wait for busy to clear
_gdm_lcd_cmd = cval; // Ouptut command
}
// Write a character to the LCD data register
void LCD_Write(char dval)
{
LCD_Busy(); // Wait for busy to clear
_gdm_lcd_data = dval; // Output character
}
// Wait for the LCD busy pin to clear
void LCD_Busy()
{
while (_gdm_lcd_cmd & 0x80);
}