# 제목: LCD1602 IIC로 특수문자를 만들고 출력해보자.



# 내용: 알파벳이나 숫자 이외에 다른 문자를 표시하고 싶을 때 사용하는 방법이다. LCD의 한칸의 값은 가로 5칸 세로 8칸으로 총 40개의 점으로 구성되어 있다.


 만드는 법:


 1. 특수문자를 정의하자!


uint8_t character1[8] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};


특수문자의 이름을 정의하고 (character1) 그 값에 0x0 ~ 0x1f 값을 넣어주면된다.

첫번째 값부터 맨 윗 행에 대한 값을 정해주는데, 다 꺼진 것을 0x0, 다 켜진것은 0x1f 가 된다.

0x** 는 16진수 값이기 때문에 계산해서 입력해주어야한다.


예시) 

 16

8

4

2

1

3번째 칸만 켜지는 상황: 0x4


 16

8

4

2

1

3,4,5번째 칸이 켜지는 상황: 4+2+1 -(16진수로변환)> 0x7


 16

8

4

2

1

1, 5번째 칸만 켜지는 상황: 16+1 -> 17 -(16진수로변환)> 0x11


이렇게 총 8개의 값을 넣으면 특수문자 정의는 완료된다.



2. 특수문자를 등록하자!


lcd.createChar(0, character1);


createChar 메소드를 사용하여 등록할 수 있다. 필요에 맞게 해당 특수문자를 번호로 등록하고, 위에 정의했던 특수문자의 이름을 넣어주면 된다.


예시)

lcd.createChar(1, character2);

lcd.createChar(2, heart);



3. 특수문자를 쓰자!


lcd.write(0);

lcd.write(1);


write() 메소드를 사용하여 특수문자를 사용할 수 있다!

특정 위치에 사용하고 싶으면 setCursor()메소드를 사용하면 된다.


# 예제코드:


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
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
 
LiquidCrystal_I2C lcd(0x3F162);  // I2C LCD 객체 선언
 
uint8_t upstep0[8= {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};
uint8_t upstep1[8= {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1f};
uint8_t upstep2[8= {0x0,0x0,0x0,0x0,0x0,0x0,0x1f,0x1f};
uint8_t upstep3[8= {0x0,0x0,0x0,0x0,0x0,0x1f,0x1f,0x1f};
uint8_t upstep4[8= {0x0,0x0,0x0,0x0,0x1f,0x1f,0x1f,0x1f};
uint8_t upstep5[8= {0x0,0x0,0x0,0x1f,0x1f,0x1f,0x1f,0x1f};
uint8_t upstep6[8= {0x0,0x0,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};
uint8_t upstep7[8= {0x0,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};
uint8_t upstep8[8= {0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};
 
uint8_t rightstep0[8= {0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10};
uint8_t rightstep1[8= {0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18};
uint8_t rightstep2[8= {0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c};
uint8_t rightstep3[8= {0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e};
uint8_t rightstep4[8= {0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};
 
int i,j,k,m,n;
 
void setup() {
  lcd.begin();
  lcd.clear();
  lcd.home();
}
 
void loop() {
  upstepfill();
  rightstepfill();
}
 
void rightstepfill() {
 
  lcd.createChar(10,rightstep0);
  lcd.createChar(11,rightstep1);
  lcd.createChar(12,rightstep2);
  lcd.createChar(13,rightstep3);
  lcd.createChar(14,rightstep4);
  
  lcd.home();
  lcd.clear();
  for(m=0;m<16;m++){
      for(n=10;n<15;n++){
        lcd.setCursor(m,0);
        lcd.write(n);
        lcd.setCursor(m,1);
        lcd.write(n);
        delay(50);
      }
  }
}
void upstepfill() {
 
  lcd.createChar(0, upstep0);
  lcd.createChar(1, upstep1);
  lcd.createChar(2, upstep2);
  lcd.createChar(3, upstep3);
  lcd.createChar(4, upstep4);
  lcd.createChar(5, upstep5);
  lcd.createChar(6, upstep6);
  lcd.createChar(7, upstep7);
  lcd.createChar(8, upstep8);
  
  lcd.home();
  lcd.clear();
  for(i=1;i>=0;i--){
    for(k=0;k<9;k++){
      for(j=0;j<16;j++){
        lcd.setCursor(j,i);
        lcd.write(k);
      }
    }
    delay(200);
  }
}

cs


# 회로도(Fritzing):



# 실행결과:



# 비고: 


현재 예제에서는 8개가 넘는 캐릭터를 등록해서 사용하기 때문에

위와 같이 특수문자를 출력할 때마다 createChar()메소드를 사용한 것을 볼 수 있습니다. 


8개 이하일 경우 setup() 함수 안에 한번만 넣어주면 되고,

8개 초과일 경우 아래와 같이 사용할 때마다 생성 후 사용하시면 되겠습니다 =)


+ Recent posts