-
Notifications
You must be signed in to change notification settings - Fork 0
/
textLCD.c
94 lines (91 loc) · 1.88 KB
/
textLCD.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
#include <avr/io.h>
#include <util/delay.h>
#define sbit(x,y) (x|=(1<<y)) // y번째 비트 1
#define cbit(x,y) (x&=~(1<<y)) // y번째 비트 0
#define RS_SET sbit(PORTC,0) //C포트 0번째 1 0001
#define RS_CLEAR cbit(PORTC,0) // C 포트 0번째 0
#define RW_SET sbit(PORTC,1) // C포트 1번째 1 0010
#define RW_CLEAR cbit(PORTC,1)
#define E_SET sbit(PORTC,2) // C 포트 2번째 1 0100
#define E_CLEAR cbit(PORTC,2)
#define LIGHT_SET sbit(PORTC,3) // C 포트 3번째 1 1000
#define LIGHT_CLEAR cbit(PORTC,3)
#define BUSY bit_is_set(PINB,7) // B포트 7 번째 1인지 검사
unsigned char display_data1[] = "Hello LCD world";
unsigned char display_data2[] = "N403";
void lcd_busy() {
DDRB = 0x00;
do {
E_CLEAR;
_delay_ms(20);
RS_CLEAR;
RW_SET;
E_SET;
_delay_ms(20);
} while (BUSY);
E_CLEAR;
DDRB = 0xFF;
}
void lcd_enable() {
E_SET;
_delay_ms(20);
E_CLEAR;
}
void lcd_func_set() {
RW_CLEAR;
RS_CLEAR;
PORTB = 0x38;
lcd_enable();
}
void lcd_command(unsigned char lcd_data) {
lcd_busy();
RW_CLEAR;
RS_CLEAR;
PORTB = lcd_data;
lcd_enable();
}
void lcd_init() // lcd 초기화
{
E_CLEAR;
_delay_ms(20);
lcd_func_set();
_delay_ms(20);
lcd_func_set();
_delay_ms(20);
lcd_func_set();
_delay_ms(20);
lcd_command(0x3C);
lcd_command(0x08);
lcd_command(0x01);
lcd_command(0x06);
}
void lcd_write_char(unsigned char lcd_data) {
lcd_busy();
RW_CLEAR;
RS_SET;
PORTB = lcd_data;
lcd_enable();
RS_CLEAR;
}
void lcd_display() {
unsigned char i;
LIGHT_SET;
lcd_command(0x0C); //디스플레이를 켜고, 커서를 꺼짐
lcd_command(0x02); //홈 리턴
for (i = 0; i < 16; i++) {
lcd_write_char(display_data1[i]);
}
lcd_command(0xc0); // 두번째 라인 시작점으로 커서 이동
for (i = 0; i < 16; i++) {
lcd_write_char(display_data2[i]);
}
}
int main() {
DDRB = 0xff;
DDRC = 0xff;
PORTC = 0x00;
lcd_init();
lcd_display();
while (1) {
};
}