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
| /*
* LCD_interfacing_along_with_UI.c
*
* Created: 8/12/2015 3:42:05 PM
* Author: Aastha
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
/* All the macro definitions related to LCD */
#define RS PB0
#define RW PB1
#define E PB2
#define SW_1_SELECT PC0
#define SW_2_UP PC1
#define SW_3_DOWN PC2
#define SW_4_LEFT PC3
#define SW_5_RIGHT PC4
#define data PORTD
#define SET_RS() (PORTB|=(1<<RS))
#define SET_RW() (PORTB|=(1<<RW))
#define SET_E() (PORTB|=(1<<E))
#define RESET_RS() (PORTB&=~(1<<RS))
#define RESET_RW() (PORTB&=~(1<<RW))
#define RESET_E() (PORTB&=~(1<<E))
void initalize_lcd(unsigned char cmd1,unsigned char cmd2,unsigned char cmd3);
void lcd_busy(void);
void write_string( char *str);
void write_data(unsigned char datas);
void send_command(unsigned char cmd);
void display_multiple_options(void);
int main(void)
{
DDRD=0b11111111; //making PORTD as output port for data
DDRB=0b00000111; //making PORTB for control signals
DDRC=0b0000000; //making PORTC as input port for switches
PORTC=0b1111111;
initalize_lcd(0x38,0x01,0x0E);
_delay_ms(50);
send_command(0xC5);
_delay_ms(50);
write_string("GUITAR");
_delay_ms(1000);
/*initalize_lcd(0x30,0x01,0x0E);
send_command(0xC0);*/
while(1)
{
/*if(bit_is_clear(PINC,SW_1_SELECT))
{
display_multiple_options();
break;
/*if(bit_is_clear(PINC,SW_2_UP))
{
}
else if(bit_is_clear(PINC,SW_3_DOWN))
{
}
else if(bit_is_clear(PINC,SW_4_LEFT))
{
}
else if(bit_is_clear(PINC,SW_5_RIGHT))
{
}
else
{
}
}
else
{
write_string("...PRESS SELECT BUTTON ");
_delay_ms(1000);
send_command(0x18);
}
}
return 0;*/
}
}
void initalize_lcd(unsigned char cmd1,unsigned char cmd2,unsigned char cmd3)
{
send_command(cmd1); //to display content in one/two line in 5x7 matrix
_delay_ms(1);
send_command(cmd2); //clearing the display including/not including RAM data
_delay_ms(1);
send_command(cmd3); //making cursor and display on
_delay_ms(1);
}
void send_command(unsigned char cmd)
{
lcd_busy();
data=cmd;
SET_E(); //setting the enable to latch data to data lines of LCD
RESET_RS(); //resetting register select to choose command register
RESET_RW(); //resetting R/W to write commands to data lines of LCD
_delay_ms(50);
RESET_E(); //resetting enable to send data to LCD
_delay_ms(50);
}
void write_string( char *str)
{
int i=0;
while(str[i]!='\0')
{
write_data(str[i]);
i++;
}
}
void write_data(unsigned char datas)
{
lcd_busy();
data=datas;
SET_E();
RESET_RW();
SET_RS();
_delay_ms(1);
RESET_E();
}
void lcd_busy()
{
DDRD=0b00000000;
RESET_RS(); //resetting RS to select command register
SET_RW(); //setting RW to read from LCD to micro controller
while(PORTD>=0x80) // when pin PD7 is 1 the LCD is busy
{
SET_E();
_delay_ms(1);
RESET_E();
}
DDRD=0b11111111;
}
/*void display_multiple_options()
{
initalize_lcd(0X38,0x01,0x0E);
_delay_ms(50);
send_command(0X85);
_delay_ms(1);
write_string("GUITAR");
send_command(0xC0);
_delay_ms(1);
write_string("AA");
_delay_ms(100);
}*/ |