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
| #include <avr/io.h>
#define F_OSC 4000000
#include <util/delay.h>
#define _LCD_RETURN_HOME 0x02
#define LCD_RS 0
#define LCD_RW 1
#define LCD_EN 2
#define LCD PORTD
void LCD_Out(char*);
void LCD_Init();
void LCD_Cmd(unsigned char);
void LCD_Chr(unsigned char);
void CustomChar(char pos_row, char pos_char);
const char characterAnim[4][8] = {
{1,1,1,7,15,31,15,3},
{16,16,16,28,30,31,30,24},
{3,3,3,3,3,3,3,3},
{24,24,24,24,24,24,24,24}
};
void CustomChar(char pos_row, char pos_char){
unsigned char i, j = 0, value;
for(j = 0; j < 4; j++){
LCD_Cmd(64 + (j * 8));
for (i = 0; i <= 7; i++) Lcd_Chr(characterAnim[j][i]);
LCD_Cmd(_LCD_RETURN_HOME);
switch(pos_row){
case 1:
value = 0x80 + pos_char;
break;
case 2:
value = 0xC0 + pos_char;
break;
case 3:
value = 0x94 + pos_char;
break;
case 4:
value = 0xD4 + pos_char;
break;
};
Lcd_Cmd(value);
_delay_ms(250);
}
}
void LCD_Init(){
int i = 0;
LCD_Cmd(0x02);
LCD_Cmd(0x06);
LCD_Cmd(0x28);
LCD_Cmd(0x0C);
for(i=0; i <= 50; i++){
LCD_Cmd(0x1E);
_delay_ms(10);
}
}
void LCD_Cmd(unsigned char x){
LCD = x & 0xF0;
LCD &= ~(1 << LCD_RS);
LCD &= ~(1 << LCD_RW);
LCD |= (1 << LCD_EN);
_delay_ms(1);
LCD &= ~(1 << LCD_EN);
LCD = (x << 4) & 0xF0;
LCD &= ~(1 << LCD_RS);
LCD &= ~(1 << LCD_RW);
LCD |= (1 << LCD_EN);
_delay_ms(1);
LCD &= ~(1 << LCD_EN);
}
void LCD_Chr(unsigned char y){
LCD = y & 0xF0;
LCD |= (1 << LCD_RS);
LCD &= ~(1 << LCD_RW);
LCD |= (1 << LCD_EN);
_delay_ms(1);
LCD& = ~(1 << LCD_EN);
LCD = (y << 4) & 0xF0;
LCD |= (1 << LCD_RS);
LCD &= ~(1 << LCD_RW);
LCD |= (1 << LCD_EN);
_delay_ms(1);
LCD &= ~(1 << LCD_EN);
}
void LCD_Out(char *str){
unsigned int i = 0;
while(*str)
{
LCD_Chr(*str++);
}
}
int main()
{
DDRD = 0xFF;
PORTD = 0x00;
LCD_Init();
LCD_Cmd(0x80);
LCD_Out("Happy");
LCD_Cmd(0xC0);
LCD_Out("Anniversary");
while(1){
CustomChar(2, 14);
}
return 0;
} |