-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcd.c
201 lines (167 loc) · 4.56 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/******************************************************************************************
File Name : lcd.c
Author&Editor Name : Ananth Deshpande
Professional Masters in Embedded Systems
Fall 2021, UCB.
Editor email id : ande9392@colorado.edu
IDE used for Coding : ccstudio IDE
Compiler : GCC
Date : 4th December 2021
Info on Code obtained from other sources:
This code has been obtained from TI C code examples and has been edited
according to our program needs
*******************************************************************************************/
/*header files*/
#include <stdio.h>
#include "msp.h"
#include "lcd.h"
#include "delay.h"
/*macros*/
#define RS 0x20 /*P3.5 mask*/
#define RW 0x40 /*P3.6 mask*/
#define EN 0x80 /*P3.7 mask*/
#define LCD_DELAY 250
#define ASCII_OFFSET 48
/***************************************************************************
* to execute commands to LCD
*
* Parameters: command --> the command for LCD
*
* Returns: void
**************************************************************************/
void LCD_command(register unsigned char command)
{
/*RS = 0, R/W = 0*/
P3->OUT &= ~(RS | RW);
/*put command on data bus*/
P4->OUT = command;
/*pulse E high*/
P3->OUT |= EN;
delayMs(0);
P3->OUT &= ~EN;
/*command 1 and 2 need up to 1.64ms*/
if(command < 4)
delayMs(4);
else
delayMs(1);/*all other 40 ms*/
}
/***************************************************************************
* initialise LCD
*
* Parameters: void
*
* Returns: void
**************************************************************************/
void LCD_init()
{
/*make P3 pins output for control*/
P3->DIR |= RS | RW | EN;
/*make P4 pins output for data*/
P4->DIR = 0xFF;
/*initialisation sequence*/
delayMs(30);
LCD_command(0x30);
delayMs(10);
LCD_command(0x30);
delayMs(1);
LCD_command(0x30);
LCD_command(0x38);
LCD_command(0x06);
LCD_command(0x01);
LCD_command(0x0F);
}
/***************************************************************************
* to send data to LCD
*
* Parameters: data --> data to be sent to LCD
*
* Returns: void
**************************************************************************/
void LCD_data(register unsigned char data)
{
/*RS = 1*/
P3->OUT |= RS;
/*R/W = 0*/
P3->OUT &= ~RW;
/*put data on bus*/
P4->OUT = data;
/*pulse E*/
P3->OUT |= EN;
delayMs(0);
/*clear E*/
P3->OUT &= ~EN;
/*wait for controller to do the display*/
delayMs(1);
}
/***************************************************************************
* to display string on LCD
*
* Parameters: str --> the string to be displayed
*
* Returns: void
**************************************************************************/
void displayString(char *str)
{
register int i = 0;
LCD_command(1);
delayMs(LCD_DELAY);
LCD_command(0x80);
for(i = 0; str[i] != '\0'; i++)
{
LCD_data(str[i]);
}
delayMs(LCD_DELAY);
}
/***************************************************************************
* to display frequency values on LCD
*
* Parameters: frequency --> frequency to be displayed
*
* Returns: void
**************************************************************************/
void displayFrequency(register int frequency)
{
register int temp1 = 0, temp2 = 0, temp3 = 0, temp4 = 0;
if(frequency <= 0)
{
displayString("Frequency is 0");
}
if(frequency >= 100)
{
temp1 = frequency / 100;
temp2 = frequency % 100;
}
else
{
temp2 = frequency;
}
temp3 = temp2 / 10;
temp4 = temp2 % 10;
displayString("Frequency ");
LCD_data(temp1 + ASCII_OFFSET);
LCD_data(temp3 + ASCII_OFFSET);
LCD_data(temp4 + ASCII_OFFSET);
}
/***************************************************************************
* to display boot up message
*
* Parameters: void
*
* Returns: void
**************************************************************************/
void displayBootUpMessage()
{
displayString("Guitar Tuner");
}
/***************************************************************************
* to display success message
*
* Parameters: void
*
* Returns: void
**************************************************************************/
void displaySucessMessage()
{
displayString("String tuned!!:)");
}
/***************************end of file*************************************/