Presentation is loading. Please wait.

Presentation is loading. Please wait.

컴퓨터정보공학과 권춘우 ARDUINO (센서활용프로그래밍/ICT융합실무) - 3 Digit 7 Segment LED - RGB LED(3 Color) - LCD 디스플레이.

Similar presentations


Presentation on theme: "컴퓨터정보공학과 권춘우 ARDUINO (센서활용프로그래밍/ICT융합실무) - 3 Digit 7 Segment LED - RGB LED(3 Color) - LCD 디스플레이."— Presentation transcript:

1 컴퓨터정보공학과 권춘우 ARDUINO (센서활용프로그래밍/ICT융합실무) - 3 Digit 7 Segment LED - RGB LED(3 Color) - LCD 디스플레이

2 목차 3 Digit 7 Segment LED RGB LED(3 Color) LCD 디스플레이 패러럴 LCD 디스플레이

3 3 Digit 7 Segment LED

4 LED 순차적으로 표시하기 사이트(추후 검토자료)

5 3 Digit 7 Segment LED - Data Sheet

6 3 Digit 7 Segment LED – 핀 번호 & 세그먼트
12 11 10 9 8 7 1 2 3 4 5 6 3 Digit 7 Segment LED 핀 번호 NC (연결 없음)

7 3 Digit 7 Segment LED - 배선도 3 Digit 7 Segment LED 핀 번호 Auduino 출력 핀 번호
13 11 9 7 5 3 12 11 10 9 8 7 12 10 8 6 4 1 2 3 4 5 6 3 Digit 7 Segment LED 핀 번호 NC (연결 없음) [Connection] 3 DIGIT LED 세그 먼트 아두이노 1 e 9 2 d 8 3 DP 12 4 c 7 5 g 11 6 NC b Dig-3 Dig-2 10 f a Dig-1 13 LED #8 LED #12 LED #9 LED #3 LED #5 LED #10 LED #1 LED #2 LED #4 LED #7 LED #11 3 Digit 7 Segment LED 핀 번호

8 3 Digit 7 Segment LED - 회로도 3 Digit 7 Segment LED 부품 내부

9 (실습-1) 3 Digit 7 Segment LED
int digits[10][7]= { //a.b.c.d.e.f.g {0,0,0,0,0,0,1},//0 {1,0,0,1,1,1,1},//1 {0,0,1,0,0,1,0},//2 {0,0,0,0,1,1,0},//3 {1,0,0,1,1,0,0},//4 {0,1,0,0,1,0,0},//5 {0,1,0,0,0,0,0},//6 {0,0,0,1,1,1,1},//7 {0,0,0,0,0,0,0},//8 {0,0,0,1,1,0,0}//9 }; void setup() { for(int i=3;i<=13;i++) pinMode(i,OUTPUT); } digitalWrite(13,HIGH); //digit-1 digitalWrite(3,LOW); //digit-2 digitalWrite(4,LOW); //digit-3 digitalWrite(12,0); //DP pin high 대신 low 면 도트가 켜진다 int num=0; void loop() for(int j=0;j<10;j++) // 서그먼트 숫자표현 for(int i=5;i<12;i++) { //핀번호 digitalWrite(i,digits[j][i-5]); // 시작위치 [0][0]으로 맞춘다 delay(1000);

10 (실습-2) 시리얼 모니터 이용 숫자 표시(한자리)
int digits[10][7]= { //a.b.c.d.e.f.g {0,0,0,0,0,0,1}, //0 {1,0,0,1,1,1,1}, //1 {0,0,1,0,0,1,0}, //2 {0,0,0,0,1,1,0}, //3 {1,0,0,1,1,0,0}, //4 {0,1,0,0,1,0,0}, //5 {0,1,0,0,0,0,0}, //6 {0,0,0,1,1,1,1}, //7 {0,0,0,0,0,0,0}, //8 {0,0,0,1,1,0,0} //9 }; void setup() { for(int i=3;i<=13;i++) pinMode(i,OUTPUT); } digitalWrite(13,HIGH); //digit-1 digitalWrite(3,LOW); //digit-2 digitalWrite(4,LOW); //digit-3 digitalWrite(12,HIGH); //DP pin high 대신 low 면 도트가 켜진다 Serial.begin(9600);} int num=1; void loop() int count=0; if(Serial.available()) num=Serial.parseInt(); for(int i=5;i<12;i++) { digitalWrite(i,digits[num][i-5]); }

11 (실습-3) 시리얼 모니터 이용 숫자 표시(두자리)
int digits[10][7]= { //a.b.c.d.e.f.g {0,0,0,0,0,0,1}, //0 {1,0,0,1,1,1,1}, //1 {0,0,1,0,0,1,0}, //2 {0,0,0,0,1,1,0}, //3 {1,0,0,1,1,0,0}, //4 {0,1,0,0,1,0,0}, //5 {0,1,0,0,0,0,0}, //6 {0,0,0,1,1,1,1}, //7 {0,0,0,0,0,0,0}, //8 {0,0,0,1,1,0,0} //9 }; void setup() for(int i=3;i<=13;i++) pinMode(i,OUTPUT); digitalWrite(13,HIGH); //digit-1 digitalWrite(3,HIGH); //digit-2 digitalWrite(4,LOW); //digit-3 digitalWrite(12,HIGH); //DP pin high 대신 low 면 도트가 켜진다 Serial.begin(9600); } int num=00; //초기숫자 int num1=0; int num2=0; void loop() { if(Serial.available()) num=Serial.parseInt(); } num1=num/10; // 몫 num2=num%10; //나머지 digitalWrite(3,LOW); digitalWrite(13,HIGH); for(int i=5;i<12;i++) { digitalWrite(i,digits[num1][i-5]); //몫을 첫번째 넣는다 delay(10); digitalWrite(3,HIGH); digitalWrite(13,LOW); digitalWrite(i,digits[num2][i-5]); //나머지를 두번째 넣는다

12 (실습-4) 시리얼 모니터 이용 숫자 표시(세자리)
int digits[10][7]= { //a.b.c.d.e.f.g {0,0,0,0,0,0,1}, //0 {1,0,0,1,1,1,1}, //1 {0,0,1,0,0,1,0}, //2 {0,0,0,0,1,1,0}, //3 {1,0,0,1,1,0,0}, //4 {0,1,0,0,1,0,0}, //5 {0,1,0,0,0,0,0}, //6 {0,0,0,1,1,1,1}, //7 {0,0,0,0,0,0,0}, //8 {0,0,0,1,1,0,0} //9 }; void setup() for(int i=3;i<=13;i++) pinMode(i,OUTPUT); digitalWrite(13,HIGH); //digit-1 digitalWrite(3,HIGH); //digit-2 digitalWrite(4,HIGH); //digit-3 digitalWrite(12,HIGH);//DP pin high 대신 low 면 도트가 켜진다 Serial.begin(9600); } int num=127; //초기값 int num1=0; //몫 int num2=0; //나머지 int num3=0; //나머지의 몫 int num4=0; //나머지의 나머지 void loop() { if(Serial.available()) num=Serial.parseInt(); num1=num/100; //1 num2=num%100; //27 num3=num2/10; //2 num4=num2%10; //7 digitalWrite(3,LOW); digitalWrite(4,LOW); digitalWrite(13,HIGH); //몫 for(int i=5;i<12;i++) { digitalWrite(i,digits[num1][i-5]); //몫을 첫번째 넣는다 } // 백의자리 보인다

13 (실습-4) 시리얼 모니터 이용 숫자 표시(세자리)
delay(5); digitalWrite(4,LOW); digitalWrite(3,HIGH); digitalWrite(13,LOW); for(int i=5;i<12;i++) { digitalWrite(i,digits[num3][i-5]); //나머지의 몫 } // 십의 자리 보인다 digitalWrite(4,HIGH); digitalWrite(3,LOW); digitalWrite(i,digits[num4][i-5]); //나머지의 나머지 } //1의자리 보인다 }

14 (수업과제) 3 Digit 7 Segment LED
Digit-2와 Digit-3에 동시에 숫자가 표시되도록 스케치에서 수정 소수점은 표시하지 않음 (실습-2) 시리얼 모니터 이용 숫자 표시(한자리) : 동영상 생성 제출 Digit-2에만 숫자가 표시되도록 스케치 수정 동영상 생성 시 시리얼 입력 숫자의 개수는 3-4개로 함 (실습-3) 시리얼 모니터 이용 숫자 표시(두자리) : 동영상 생성 제출| Digit-2와 Digit-3에 숫자가 표시되도록 스케치 수정 (실습-4) 시리얼 모니터 이용 숫자 표시(세자리) : 동영상 생성 제출 시리얼 입력한 숫자를 표시하되 2번째 Digit에는 소수점이 표시되도록 스케치 수정 (예) 시리얼 입력 '589' 경우 : LED 표시 내용 '58.9‘

15 RGB LED(3 Color)

16 RGB LED(3 Color) 활용 준비물 Common Cathode RGB LED (Type-1) (Type-2)

17 RGB LED(3 Color) 활용 - 배선도 B G R

18 RGB LED(3 Color) 활용 – 회로도(Schematic)

19 RGB LED(3 Color) 활용 – 스케치(1/2)
// 펄스폭 변조(PWM) 이용 RGB Color LED의 색상을 순차적으로 변경 int ledpinRed = 11; int ledpinGreen = 9; int ledpinBlue = 10; unsigned int tr, tg, tb; unsigned int p = 0; void wheel(unsigned int i) { unsigned int k; unsigned int m; i = i%0x300; m = i&0xFF; k = i&0x300; switch(k) { case 0x0000: tr = 0xFF - m; // Red Decrement tg = m; // Green Increment tb = 0; // Blue Off break; case 0x0100: tr = 0; // Red Off tg = 0xFF - m; // Green Decrement tb = m; // Blue Increment case 0x0200: tr = m; // Red Increment tg = 0; // Green Off tb = 0xFF - m; // Blue Decrement }

20 RGB LED(3 Color) 활용 – 스케치(2/2)
// …………… 계속 …………….. void setup() { // put your setup code here, to run once: } void loop() { wheel(p); analogWrite(ledpinRed, tr); analogWrite(ledpinGreen, tg); analogWrite(ledpinBlue, tb); delay(15); p++; p %= 0x300; (실습 내용) loop() 에서 delay() 값을 5, 50, 500, 1000으로 수정하여 동작을 확인하라. Red와 Blue 색만 변경하도록 프로그램을 수정하라. -> (동작을 동영상으로 제출) 이 프로그램의 동작을 분석하라. -> (보고서 작성 후 제출)

21 LCD(Liquid Crystal Display, p107)

22 LCD(Liquid Crystal Display)
□ 손목시계, TV, 핸드폰 등 우리 생활의 많은 부분에서 사용 됨 □ 그래픽 LCD, TFT LCD, Character LCD 등 종류가 다양 □ 아두이노 Character LCD 지원 □ 시리얼 방식 □ 패러럴 방식

23 LCD Controller(HD44780) Hitachi HD44780 LCD controller data sheet download (click!) alphanumeric dot matrix liquid crystal display (LCD) controller(Hitachi 개발) Max addressing : 80 chars : 80 x 8 bit display RAM MPU interface : 4-bit or 8-bit Size : 8 characters x 1 row, 8x2, 16x1, 16×2, 20×2, 20×4 등 가능 Custom size : (32, 40, 80) characters x (1, 2, 4 or 8 lines) ASCII characters, Japanese Kana characters, some symbols : 240 character fonts 208 character fonts (5x8 dot), 32 character fonts (5x10 dot) Backlight 지원 HD44780U

24 LCD Controller(HD44780) 사용 Interface MPU - LCD controller - LCD(Liquid Crystal Display) LCD MPU / Arduino / etc. HD44780U LCD LCD

25 LCD Controller(HD44780) 사용 MPU - LCD controller Interface

26 HD44780U Block Diagram & Pin Functions

27 HD44780U - 기능 설명 RS(Register Selector) : IR(0), DR(1) 선택
IR(instruction register) : 명령어 코드, DDRAM/CGRAM 주소정보 저장 DR(data register) : DDRAM/CGRAM 저장/읽은 데이터 일시 저장 BF(Busy Flag) : chip 내부 상태가 Busy 여부 상태 의미 BF : RS=0 & 𝑅/ 𝑊 =1 상태에서 읽은 데이터의 DB7이 BF 상태 값 BF=1 : HD44780U가 Internal operation mode 상태로 다음 명령어가 받아 들여지지 않음 BF=0 : 다음 명령어 가능 (프로그램에서 받드시 BF=0임을 확인한 후 명령어 수행) AC(Address Counter) : DDRAM/CGRAM의 주소를 지정 명령어 주소가 IR에 저장되면 IR 값이 AC로 보내짐 DDRAM/CGRAM의 선택도 동시에 일어나야 함

28 HD44780U – DDRAM DDRAM(Display Data RAM) 1-line Display 경우 (N=0)
8-bit 문자코드로 된 Display 데이터를 저장 저장 용량 : 80 character or 80 x 8 bits Display로 사용되지 않은 경우 일반 데이터 RAM으로 사용 가능 DDRAM 주소는 ADD는 AC(address counter)에 16값으로 설정 1-line Display 경우 (N=0) DDRAM Address 1-Line Display 1-Line x 8-Character Display

29 HD44780U – DDRAM 2-line Display 경우 (N=1) : 8-char x 2-line 표시 경우 (Case 1) 2-Line Display 2-Line x 8-Character Display

30 HD44780U – DDRAM 2-line Display 경우 (N=1) : 8-char x 2-line 표시 경우(Case 2) 2-Line Display 2-Line x 8-Character Display

31 HD44780U – CGROM/CGRAM CGROM(Character Generator ROM)
240 characters patterns(8-bit character code) 208 5x8 dot character patterns 32 5x10 dot character patterns User-defined character patterns by mask-programmed ROM Character Pattern(5x8) 예 A11-A4 : character code A3-A0 : character patterns의 line position O4-O0 : character pattern data O5-O7 : ‘0’ Line 9 – line 15 : ‘0’ Character Pattern(5x10) 예 Line 11 – line 15 : ‘0’

32 HD44780U – CGROM/CGRAM Character Codes & Character Patterns (ROM Code : A00) CGRAM (Character Generator RAM) 사용자가 저장하여 사용할 수 있는 character patterns Character Codes Table의 첫째 열에 해당하는 코드 Character code : 0000xxxx / 0001xxxx 8 5x8 dot character patterns 4 5x10 dot character patterns

33 HD44780 Instruction(명령어) Instruction Outline 명령어 개요
MPU의 HD44780 제어 : IR(Instruction Register)와 DR(Data Register) 만 사용 MPU의 HD44780 내부 동작을 결정하는 신호(signal) RS(Register Selection), 𝑅/ 𝑊 (read/write), DB0-DB7(data bus) 4개 구분 명령어 HD44780 기능 관련 : display format, data length 등 내부 RAM 주소 설정 내부 RAM에 데이터 전달 : 표시할 글자를 RAM에 전달하는 것(명령어 대부분) 기타 기능 처리 내부 RAM 주소는 data write 후 자동으로 1 증가/감소 : 프로그래밍 부담 감소 명령어 수행 경우 BF(Busy Flag)가 ‘1’로 설정되기 때문에, MPU는 다른 명령어를 보내기 전에 BF=0 임을 확인하여야 함

34 HD44780 Instruction(명령어) Instructions

35 HD44780 Instruction(명령어) Instructions (cont)

36 HD44780 명령어 설명 Clear Display Return Home Entry Mode Set
Display On/Off Control Cursor/Display Shift Function Set Set CGRAM Address Set DDRAM Address Read Busy Flag and Address Write Data to CG or DDRAM Read Data from CG/DDRAM

37 HD44780 명령어 설명 Instruction Codes

38 HD44780 명령어 설명 Instruction Codes

39 HD44780 Instruction-Display 연관성
8-bit operation, 8-digit x 1-line display with internal reset The HD44780U functions must be set by the function set instruction prior to the display. Since the display data RAM can store data for 80 characters, the RAM can be used for displays such as for advertising when combined with the display shift operation. Since the display shift operation changes only the display position with DDRAM contents unchanged, the first display data entered into DDRAM can be output when the return home operation is performed. 4-bit operation, 8-digit x 1-line display with internal reset The program must set all functions prior to the 4-bit operation. When the power is turned on, 8-bit operation is automatically selected and the first write is performed as an 8-bit operation. Since DB0 to DB3 are not connected, a rewrite is then required. However, since one operation is completed in two accesses for 4-bit operation, a rewrite is needed to set the functions (see Table 12). Thus, DB4 to DB7 of the function set instruction is written twice. nstruction.

40 HD44780 Instruction-Display 연관성
8-bit operation, 8-digit x 2-line display For a 2-line display, the cursor automatically moves from the first to the second line after the 40th digit of the first line has been written. Thus, if there are only 8 characters in the first line, the DDRAM address must be again set after the 8th character is completed. Note that the display shift operation is performed for the first and second lines. In the example of Table 13, the display shift is performed when the cursor is on the second line. However, if the shift operation is performed when the cursor is on the first line, both the first and second lines move together. If the shift is repeated, the display of the second line will not move to the first line. The same display will only shift within its own line for the number of times the shift is repeated. Note: When using the internal reset, the electrical characteristics in the Power Supply Conditions Using Internal Reset Circuit table must be satisfied. If not, the HD44780U must be initialized by instructions. See the section, Initializing by Instruction.

41 HD44780 Instruction-Display 프로그램 예시
8-Bit Operation, 8-Digit x 1-Line Display Example with Internal Reset

42 HD44780 Instruction-Display 프로그램 예시
8-Bit Operation, 8-Digit x 1-Line Display Example with Internal Reset (cont)

43 HD44780 Instruction-Display 프로그램 예시
8-Bit Operation, 8-Digit x 1-Line Display Example with Internal Reset (cont)

44 HD44780 Instruction-Display 프로그램 예시
4-Bit Operation, 8-Digit x 1-Line Display Example with Internal Reset

45 HD44780 Instruction-Display 프로그램 예시
8-Bit Operation, 8-Digit x 2-Line Display Example with Internal Reset

46 HD44780 Instruction-Display 프로그램 예시
8-Bit Operation, 8-Digit x 2-Line Display Example with Internal Reset (cont)

47 HD44780 초기화(Initializing) 8-bit Interface

48 HD44780 초기화(Initializing) 4-bit Interface

49 LCD(Liquid Crystal Display
패러럴 LCD 디스플레이(4-bit 모드) (p108) 패러럴 LCD 디스플레이(8-bit 모드) (p113)

50 패러럴 LCD 디스플레이(4-bit 모드) (p108)
Character LCD 모듈 : 16x1 LCD Module Hitachi HD44780 호환 컨트롤러 사용 데이터 처리 : 4-bit bus 회로 측면에서 배선이 용이 LCD 관련 프로그래밍 라이브러리 : Liquid Crystal Library #include <LiquidCrystal.h> 아두이노 IDE 포함

51 Character LCD Module (Hitachi HD44780)
Pin # Symbol 비고 1 Vss GND LCD GND (0V) 2 Vdd LCD 전원 LCD 전원 (+3.3~5V) 3 V0 LCD 밝기 조절 가변저항(보통 10KΩ)으로 표시 글자의 밝기 조절 4 RS Register Selector RS=0 명령 레지스터 선택, RS=1 데이터 레지스터 선택 5 R/W Read/Write R/W=0 레지스터 쓰기 모드, R/W=1 레지스터 읽기 모드 6 Enable Clock Enable falling-edge trigger (신호 1/HIGH) -> 0/LOW) 7 Data Bit0 Data I/O 4-bit 모드 경우 사용 않음 8 Data Bit1 9 Data Bit2 10 Data Bit3 11 Data Bit4 4-bit/8-bit 모드 경우 사용 (4-bit 모드를 많이 사용 12 Data Bit5 13 Data Bit6 14 Data Bit7 15 LCD+/A Backlight Anode 백라이트 전원 (5V) 16 LCD-/K Backlight Cathode 백라이트 GND (0V) 16 1

52 패러럴 LCD 디스플레이(4bit) - 배선도
LCD-Arudino UNO 핀 연결 LCD UNO 1 Vss GND 2 Vdd 5V 3 V0 Contrast 4 RS D12 5 R/W 6 Enable D11 7 Data Bit0 NC 8 Data Bit1 9 Data Bit2 10 Data Bit3 11 Data Bit4 D5 12 Data Bit5 D4 13 Data Bit6 D3 14 Data Bit7 D2 15 LCD+/A 16 LCD-/K 1 3 5 7 9 11 13 15

53 패러럴 LCD 디스플레이(4bit) - 회로도(Schematic)

54 아두이노 프로그램 – LiquidCrystal Library
LiquidCrystal Library #include <LiquidCrystal.h> Arduino 보드가 Hitachi HD44780 (or a compatible) chipset 기반 LCD 제어 LCD 모듈과 4-bit 또는 8-bit mode에 동작 함수(function) ( LiquidCrystal() begin() clear() home() setCursor() write() print() cursor() noCursor() peek() blink() noBlink() display() noDisplay() scrollDisplayLeft() scrollDisplayRight() autoscroll() noAutoscroll() leftToRight() rightToLeft() createChar()

55 패러럴 LCD 디스플레이(4bit) – 스케치(1)
Hello world // include the library code; // 참조 : #include<LiquidCrystal.h> // initialize the library with the numbers of the interface pins // LCD (RS, Enable, D4, D5, D6, D7) 핀에 대응하는 아두이노 핀 LiquidCrystal lcd(12,11,5,4,3,2); void setup() { // setup the LCD’s number of columns and rows; lcd.begin(16,2); } void loop() lcd.setCursor(0,0); // print a message to the LCD lcd.print("Hello, world!!"); // set the cursor to column 0, line 1 // note : line 1 is the second row, since counting begins with 0 lcd.setCursor(0,1); lcd.print(“My name is Kwon!"); delay(1000); 아두이노의 LCD 라이브러리를 사용하기 위해 헤더 파일을 추가 라이브러리 사용을 위해 초기화 (rs, rw, enable, data bit) LiquidCrystal lcd(RS, Enable, D4, D5, D6, D7) LiquidCrystal lcdl(rs, rw, enable, d4, d5, d6, d7) LiquidCrystal lcd(rs, enable, d0, d1, d2, d3, d4, d5, d6, d7)  LiquidCrystal lcd(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7) LCD 스크린 디스플레이의 폭과 높이 설정 LCD 라이브러리 명령어에 앞서 호출 LCD 커서 위치를 결정(LCD에 Display할 좌표) - 이어서 쓰는 글자가 표시되는 위치 - 시작 위치 값 : 0 LCD 에 텍스트를 표시 LCD의 2번째 행, 1번째 열에 글자 표시 (0이 시작점이기 때문) (Hello world) 1번째 행에 “Hello, world!” 2번째 행에 “My name is Kwon!”를 표시

56 패러럴 LCD 디스플레이(4bit) – 스케치(2)
SerialDisplay // include the library code: #include <LiquidCrystal.h> char a; int start=0; // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); // initialize the serial communications: Serial.begin(9600); } void loop() { if (start == 0) lcd.setCursor(0,0); lcd.clear(); lcd.print("+ -"); delay(700); lcd.print("- +"); // when characters arrive over the serial port... if (Serial.available()) { // wait a bit for the entire message to arrive start = 1; delay(100); // clear the screen // read all the available characters while (Serial.available() > 0) { // display each character to the LCD lcd.write(a=Serial.read()); Serial.write(a); 직렬포트 데이터 도착 - 리턴 값 : 읽을 수 있는 바이트 수 - 수신버퍼에 저장(64 byte) 입력되는 직렬 데이터를 읽음 - 리턴 값 : 입력되는 직렬 데이터(int) (데이터 입력 없는 경우 -1 리턴) LCD 스크린에 1개 글자를 표시 지우고 커서를 좌-상에 위치 시킴 LCD 스크린을 지우고 커서를 좌-상에 위치 시킴 (SerialDisplay) Serial 모니터 창에 입력한 글자를 LCD에 표시

57 패러럴 LCD 디스플레이(4bit) – 스케치(3)
CursorBlink // include the library code: #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("Dongyang Mirae"); lcd.setCursor(2,1); lcd.print("University!"); } void loop() { // Turn off the blinking cursor: lcd.noBlink(); delay(3000); // Turn on the blinking cursor: lcd.blink(); LCD 커서 깜박임을 ON blink() , OFF noBlink() (CursorBlink) LCD에 Cursor가 3초 간격으로 Blink 상태가 변경 : ON-OFF

58 패러럴 LCD 디스플레이(4bit) – 스케치(3)
TextDirection // include the library code: #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int thisChar = 'a'; void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); // turn on the cursor: lcd.cursor(); } void loop() { // reverse directions at 'h': if (thisChar == 'h' || thisChar == 'v') { // go right for the next letter lcd.rightToLeft(); // reverse again at 'o': if (thisChar == 'o') { // go left for the next letter lcd.leftToRight(); // reset at 'z': if (thisChar > 'z') { delay(2000); lcd.clear(); // go to (0,0): lcd.home(); // start again at 0 thisChar = 'a'; // print the character lcd.write(thisChar); // wait a second: delay(500); // increment the letter: thisChar++; LCD 커서를 상-좌에 위치 LCD에 표시하는 텍스트의 방향을 설정 leftToRight() : 왼쪽-> 오른쪽 (default) rightToLeft() : 오른쪽->왼쪽 (TextDirection) LCD에 알파벳이 a-z까지 표시하는데 입력 방향이 변경 : Left->Right, Right->Left

59 패러럴 LCD 디스플레이(4bit) – 스케치(5)
AutoScroll // include the library code: #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); } void loop() { // set the cursor to (0,0): lcd.setCursor(0, 0); // print from 0 to 9: for (int thisChar = 0; thisChar < 10; thisChar++) { lcd.print(thisChar); delay(100); // set the cursor to (0,1): lcd.setCursor(0, 1); // print from a to k: for (char thisChar = 'a'; thisChar <= 'k'; thisChar++) { lcd.write(thisChar); // set the cursor to (16,1): lcd.setCursor(16, 1); // set the display to automatically scroll: lcd.autoscroll(); delay(500); // turn off automatic scrolling lcd.noAutoscroll(); // clear screen for the next loop: lcd.clear(); LCD의 자동 스크롤 기능 ON 표시되는 글자가 이전 글자를 한 칸 밀어내는 효과 left-to-right 방향(default) : 왼쪽으로 스크롤 right-to-left 방향 : 오른쪽으로 스크롤 (AutoScroll) 입력한 글자가 자동으로 Scroll하도록 LCD에 표시

60 패러럴 LCD 디스플레이(8-bit 모드) (p113)
Character LCD 모듈 : 16x1 LCD Module Hitachi HD44780 호환 컨트롤러 사용 데이터 처리 : 8-bit bus (데이터 송신하는데 8개의 데이터 선이 필요) 배선은 복잡하지만 LCD에 문자를 디스플레이 하는 속도가 4-bit 모드보다 빠름 RS(Register Select), R/W(Read/Write), Enable 등의 제어 필요 LCD 관련 프로그래밍 라이브러리 : Liquid Crystal Library #include <LiquidCrystal.h> 아두이노 IDE 포함

61 패러럴 LCD 디스플레이(8bit) - 배선도
LCD-Arudino UNO 핀 연결 LCD UNO 1 Vss GND 2 Vdd 5V 3 V0 Contrast 4 RS D12 5 R/W D11 6 Enable D2 7 Data Bit0 D3 8 Data Bit1 D4 9 Data Bit2 D5 10 Data Bit3 D6 11 Data Bit4 12 Data Bit5 13 Data Bit6 14 Data Bit7 15 LCD+/A 16 LCD-/K 1 3 5 7 9 11 13 15

62 패러럴 LCD 디스플레이(8bit) - 회로도(Schematic)

63 패러럴 LCD 디스플레이(8bit) - 스케치
int int DI = 12; int RW = 11; int DB[] = {3, 4, 5, 6, 7, 8, 9, 10}; int Enable = 2; void LcdCommandWrite(int value){ // poll all the pins int i=0; for(i=DB[0];i<=DI;i++){ digitalWrite(i,value & 01); value >>= 1; } digitalWrite(Enable, LOW); delayMicroseconds(1); // send a pulse to enable digitalWrite(Enable, HIGH); delayMicroseconds(1); // pause 1 ms according to datasheet void LcdDataWrite(int value){ int i = 0; digitalWrite(DI, HIGH); digitalWrite(RW, LOW); for(i=DB[0];i<=DB[7];i++){ void initLCD(){ delay(100); // initiatize LCD after a short pause // needed by the LCDs controller LcdCommandWrite(0x3A); // function set; // 8-bit interface, 2 display lines, display ON delay(10); LcdCommandWrite(0x0E); // display control; // turn display ON, cursor ON, no blinking LcdCommandWrite(0x01); // clear display, set cursor position to zero LcdCommandWrite(0x06); // entry mode set; // increment automatically, no display shift // continue to the next slide LCD 라이브러리를 사용하지 않은 관계로, HD44780 Controller 초기화나 DDRAM 데이터 쓰기 등을 위해서는 직접 컨트롤러에 접근(Access)하여야 함. 이러한 처리로 Sketch code가 복잡하며 HD44780 Data Sheet의 참조가 필요

64 패러럴 LCD 디스플레이(8bit) - 스케치
// this is the function used to send data to the // LCD screen in the proper format, the others are // working at lower level void printLCD(const char *s){ int count = 0; while(*s){ if(count == 8){ LcdCommandWrite(0xC0); // jump to the second part of the display; delay(5); } if(count>=16){ break; LcdDataWrite(*s++); count++; void setup() { // put your setup code here, to run once: int i = 0; for(i=Enable; i<=DI; i++){ pinMode(i,OUTPUT); initLCD(); void loop() { // put your main code here, to run repeatedly: LcdCommandWrite(0x02); delay(10); // write the welcome message printLCD("Dept of Computer"); delay(500);

65 시리얼 LCD 디스플레이 시리얼 LCD 디스플레이 데이터 송신 : 1개 데이터 선만 필요
LCD에 다양한 문자 표시 : Serial.print() 명령어를 사용 기능 지원을 위해서는 시리얼 LCD 제품에 별도의 마이크로프로세서 장착 필요 : UART 기능 시리얼 통신으로 수신한 데이터를 LCD에 적합한 데이터로 전환 brightness of backlight contrast

66 시리얼 LCD 디스플레이 - 배선도 D1 Serial LCD Arduino 5V GND TxD Rx(Pin 0) RxD
Tx(Pin 1) Serial LCD Module (LCD1602/LCD1604/LCD2004)

67 시리얼 LCD 명령어 Serial LCD의 onboard microcontroller chip
UART 인터페이스를 통해 전송되어 온 시리얼 문자(serial characters)를 번역하여 LCD에 표시 LCD 제어를 위한 직렬포트 명령어 명령 형식 : $cmd [par1] [par2]\n 시작 : ”$” $와 CMD 사이에 빈칸 없음, CMD와 [part1], [part2] 등 사이에는 빈칸 있음 시작 후부터 전달된 시리얼 문자는 모두 LCD에 표시 : 변수값 경우도 LCD에 표시 끝 : “\n”(newline)(아두이노 경우) 대소문자 구분 없음 “GO” : 커서를 새로운 위치로 이동 “PRINT” : 커서 위치에 직렬 글자 표시 “CLEAR“ : 화면 내용 삭제 "HOME" : 커서를 최초 위치(상-좌)로 이동 "CURSOR" : 커서 양식을 설정 1번째 파라미터(parameter) : 커서 표시 여부(1 or 0) 2번째 파라미터(parameter) : 커서 깜박임 여부(1 or 0).

68 시리얼 LCD 명령어 - LCD1602/1604/2004 명령어 형식 설명 예제(Arduino) LCD1602
$lcd1602\n LCD 선택 : LCD1602 LCD1604 LCD2004 - 명령어 1회 실행 필요 Serial.print("$LCD1602 \n"); Serial.print("$LCD1604 \n"); Serial.print("$LCD2004 \n"); LCD1604 $lcd1604\n LCD2004 $lcd2004\n HOME $home\n 커서를 LCD의 시작위치(0,0)로 이동 Serial.print("$HOME\n"); GO $GO x y\n 커서를 LCD 좌표 (x,y)로 이동. - x : 행, y : 열 (1부터 시작) Serial.print("$GO 2 10\n"); CLEAR $clear\n LCD 상의 모든 글자를 지우고 커서를 시작위치 (0,0)로 이동 Serial.print("$CLEAR\n"); PRINT $print [para]\n 글자 [para]를 현재 커서 위치에 표시 Serial.print("$PRINT Hello World!\n"); CURSOR $cursor [status]\n 커서 상태를 설정 : ON/OFF, 또는 깜박임 1번째 Parameter : 커서 ON(1), OFF(0) 2번째 Parameter : 커서 BLINKING(1) 여부 Serial.print("$CURSORON\n"); Serial.print("$CURSOROFF\n"); Serial.print("$CURSORBLINKING\n"); CLOSE $close\n LCD 표시 끔 Serial.print("$CLOSE \n"); OPEN $open\n LCD 표시 켬 Serial.print("$OPEN \n");

69 시리얼 LCD 디스플레이(1) - 스케치 // 스케치 예시(1) – Serial LCD Display LCD1602/1604/2004 void setup() { Serial.begin(9600); } void loop() Serial.print("$CLEAR\n"); // \r\n도 가능 \r(0x0D, CR), \n(0x0A, LF) // 커서 상태 : 켜기/끄기, 깜박이기/깜박이지 않기 Serial.print("$CURSOR 1 1\n"); // 커서 켜기 깜박이기 Serial.print("$GO 1 4\n"); Serial.print("$PRINT DONGYANG\n"); delay(3000); Serial.print("$GO 2 1\n"); Serial.print("$PRINT Mirae Univ !!\n"); Serial.print("$Go 2 5\n"); delay(3000); Serial.print("$CURSOR 1 0\n"); // 커서 켜기 깜박이지 않음 Serial.print("$CURSOR 1 1\n"); // 커서 켜기 깜박임 Serial.print("$CURSOR 0 0\n"); // 커서 끄기 깜박이지 않음 }

70 시리얼 LCD 디스플레이(2) - 스케치 // 스케치 예시(2) – Serial LCD Display LCD1602/1604/2004 void setup(void) { Serial.begin(9600); // baud 9600 /** set LCD type LCD1602, LCD1604 and LCD2004 are supported**/ Serial.print("$LCD1602\n"); delay(2000); Serial.print("$clear\n"); // clear screen Serial.print("$Home\n"); // go home (top left corner) Serial.print("$CURSOR BLINKING\n"); // cursor on and blinking Serial.print("$go 0 0\n"); // move cursor delay(500); Serial.print("$go 1 0\n"); Serial.print("$go 0 1\n"); Serial.print("$go 1 1\n"); Serial.print("$cURSor OFf\n"); // cursor off delay(100); Serial.print("$go 0 0\n"); } void loop(void) { Serial.print("$go 1 3\n"); Serial.print("$prinT DONGYANG \n"); // write to LCD */ Serial.print("$go 2 1\n"); Serial.print("$prinT MIRAE \n"); Serial.print("$prinT Univ. !!\n"); delay(2000); Serial.print("$clear\n"); delay(1000);

71 시리얼 LCD 디스플레이(3) – 변수값 표시 // 스케치 예시(3) – Serial LCD Display : 변수를 LCD 표시 int age1=55; int age2=33; char prt[] = "$PRINT MY AGE = "; String bom1 = "$PRINT "; //만약 $가 빠지면 LCD에 표시 안됨 String bom2 = "your age = "; void setup() { Serial.begin(9600); } void loop() Serial.print("$CursorOff\n"); // 커서 깜박거리기 Serial.print("$CLEAR\n"); // \r(0x0D, CR), \n(0x0A, LF) Serial.print("$GO 1 2\n"); // 1번째 행에 표시 명령 // 직렬 데이터를 LCD에 표시하기 위해서는 $[cmd] 로 시작 Serial.print(prt); // $[cmd] 를 prt 문자열로 출력해도 됨 Serial.print(age1); // 변수값 age1을 표시 Serial.print(" \n"); // \n가 전달되면 LCD 표시 종료 Serial.print("$GO 2 1\n"); // 2번째 행에 표시 명령 // String 개체 활용 LCD에 표시 Serial.print(String(bom1 + bom2 + String(age2, DEC))); // 다음 명령으로 동일 결과 가능 // Serial.print(bom1); // Serial.print(bom2); // Serial.print(String(age2, DEC)); 혹은 Serial.print(ages2); Serial.print(" \n"); // 직렬 데이터 LCD 표시하는 현 상태 종료 Serial.print("$CURSOR 1 1\n"); // 커서 켜기 깜박임 delay(2000); }

72 감사합니다. Thank You !


Download ppt "컴퓨터정보공학과 권춘우 ARDUINO (센서활용프로그래밍/ICT융합실무) - 3 Digit 7 Segment LED - RGB LED(3 Color) - LCD 디스플레이."

Similar presentations


Ads by Google